Function allowing to crop an input vector object or shapefile on the extent of a different spatial object. in_vect must be an *sp, *sf object or vector file, while ext_obj should be a valid spatial object (sp, sf, vector file, raster or raster file name)

crop_vect(in_vect, ext_obj, out_file = NULL, verbose = TRUE)

Arguments

in_vect

Object of class sfc_POLYGON or sf_POLYGON, or coercible to it using (sprawl::cast_vect)

ext_obj

Object of class sprawl_ext, or from which an extent can be retrieved using spralw::get_extent (i.e., any R spatial object, or valid filenames of raster or vector files)

out_file

PARAM_DESCRIPTION, Default: NULL

verbose

PARAM_DESCRIPTION, Default: FALSE

Value

OUTPUT_DESCRIPTION

Details

DETAILS

See also

Examples

library(raster) library(sf) in_polys <- read_vect(system.file("extdata/shapes", "lc_polys.shp", package = "sprawl.data")) in_rast <- raster::raster(system.file("extdata/MODIS_test", "EVIts_test.tif", package = "sprawl.data")) in_polys_cropped <- crop_vect(in_polys, in_rast)
#> crop_vect --> cropping in_polys on extent of in_rast
#> although coordinates are longitude/latitude, st_intersection assumes that they are planar
# Retrieve a polygon representing in_rast extent and reproject it rast_extent <- as(get_extent(in_rast), "sfc_POLYGON") %>% sf::st_transform(get_proj4string(in_polys)) par(mfrow=c(1,2)) plot(in_polys[1])
plot(rast_extent, add = TRUE)
plot(in_polys_cropped[1])
plot(rast_extent, add = TRUE)
par(mfrow=c(1,2))