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)
in_vect | Object of class |
---|---|
ext_obj | Object of class |
out_file | PARAM_DESCRIPTION, Default: NULL |
verbose | PARAM_DESCRIPTION, Default: FALSE |
OUTPUT_DESCRIPTION
DETAILS
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)#>#># 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])