Message-ID: <1338576563.61385.YahooMailNeo@web161404.mail.bf1.yahoo.com>
Date: 2012-06-01T18:49:23Z
From: Thiago V. dos Santos
Subject: Crop a raster using a shapefile
? 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.