aoi: Build area of interest (A.O.I.)

Description Usage Arguments Details Value See Also Examples

View source: R/aoi.R

Description

This function creates a spatial object (raster or vector) defining the area of interest, by taking a bounding box or a spatial object, or unioning the input spatial objects if more than one are provided. When msk is a list of rasters, extent is set equal to their combined extent (union) and resolution to the finest resolution among them.

Usage

1
aoi(msk, mskSub = NULL, xy = FALSE, bbox = NULL)

Arguments

msk

a character (path to raster or vector file), or a bounding box as numeric (xmin,xmax,ymin,ymax), or one or more (as list of) rasters of class "RasterLayer", or a single object of class "sf" or "SpatialPolygonsDataFrame". The reference data (raster or vector) to be used as mask. All model outputs will have the same extent (outline) as this object. All locations with no data (i.e. NA) cells in msk input will be ignored as well.

mskSub

vector of values, for raster data only. The subset values from msk which should be considered to build the area of interest. All other values will be ignored and masked out during modelling.

xy

logical. Should return a two column matrix of x and y coordinates of cells centre (raster data) or the IDs of features? Defaults to FALSE, returning an object of class RasterLayer or sf.

bbox

numeric of four elements, the coordinates defining a rectangle (bounding box) to limit the area of interest. Must be ordered as xmin, xmax, ymin, ymax. Coordinates must be in the same reference system as spatial data.

Details

If rasters are used, all model outputs will have the same resolution and same extent as inherited from msk. All locations with no data (i.e. NA) cells from msk will be ignored as well.

Value

An object of class RasterLayer or sf, or a matrix of coordinates of mask cells (raster only). In the former case, valid cells (i.e. the area of interest) will have value 1, NA otherwise.

See Also

extractByMask

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
## Make a mask from a group of input layers:
list2env(ConwyData, environment())

network <- LandUseChange
spatialData <- c(ConwyLU, ConwySlope, ConwyStatus)
m <- aoi(spatialData)
m

## Plot mask
library(raster)
m <- aoi(ConwyLU)
plot(m)

## Make mask from a subset of values and plot
m <- aoi(ConwyLU, mskSub=c(2,3))
plot(m)

## Return coordinates of valid mask locations
coord <- aoi(ConwyLU, xy=TRUE)
head(coord)

## Using a bounding box
aoi(ConwyLU, bbox=c(270000, 284950, 347000, 365000))

## For vectorial spatial data. Note xy=TRUE shall return the features IDs
Conwy = sf::st_read(system.file("extdata", "Conwy.shp", package = "bnspatial"))
aoi(Conwy, bbox=c(270000, 284950, 347000, 365000))

bnspatial documentation built on Jan. 17, 2020, 9:06 a.m.