[R-sig-Geo] Crop a raster using a shapefile
Thiago Veloso
thi_veloso at yahoo.com.br
Fri Jun 1 20:49:23 CEST 2012
Dear all,
When cropping a raster using a shapefile, through 'crop' function from "raster" package, only the extent is taken into account:
> r<-raster("lai2011361.Lai_1km.tif")
> extent(r)
class : Extent
xmin : -104.4326
xmax : -29.99736
ymin : -40.00064
ymax : 10
> br<-readShapePoly("/mnt/disco3/MODIS/shapes/brazil.shp")
> extent(br)
class : Extent
xmin : -73.83943
xmax : -34.8581
ymin : -33.77086
ymax : 5.38289
> c<-crop(r,br)
> extent(c)
class : Extent
xmin : -73.83772
xmax : -34.85554
ymin : -33.76852
ymax : 5.38428
However, the cropped raster is rectangular. Is there any way to keep also the "shape" of a shapefile (and not only its extent) when performing this kind of crop operation?
Thanks in advance,
Thiago.
More information about the R-sig-Geo
mailing list