Function to subset and clip a GIS vector or raster layer by a bounding box or clip/subset layer (e.g. shapefile/KML)

subset_layer(
  file,
  coords = NULL,
  sub.layer = NULL,
  clip = FALSE,
  out.dir = NULL,
  out.name = NULL
)

Arguments

file

input file to be subset

coords

vector with xmin,ymin,xmax,ymax defing the bounding box for subset

sub.layer

Vector layer defining the subset region

clip

clip geometries to bounding box/subset layer? TRUE/FALSE

out.dir

output directory for subset layer. Defaults to location of input file. Can also set to 'pwd'

out.name

filename for subset layer. Defaults to original filename with the suffix *.sub

Author

Shawn P. Serbin

Examples

if (FALSE) { # \dontrun{
# Test dataset
file <- Sys.glob(file.path(R.home(), 'library', 'PEcAn.data.land','data','*.shp'))
out.dir <- path.expand('~/temp')
# with clipping enabled
subset_layer(file=file,coords=c(-95,42,-84,47),clip=TRUE,out.dir=out.dir)
# without clipping enables
subset_layer(file=file,coords=c(-95,42,-84,47),out.dir=out.dir)
system(paste('rm -r',out.dir,sep=''))
} # }