[R-sig-Geo] Crop a raster using a shapefile

rafael.wueest at wsl.ch rafael.wueest at wsl.ch
Fri Jun 1 21:17:49 CEST 2012


Check out ?mask

Rafi

--
Rafael Wüest
Swiss Federal Research Institute WSL
Zuercherstrasse 111
8903 Birmensdorf

Am 01.06.2012 um 20:51 schrieb "Thiago Veloso" <thi_veloso at yahoo.com.br>:

>   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.
>
> _______________________________________________
> R-sig-Geo mailing list
> R-sig-Geo at r-project.org
> https://stat.ethz.ch/mailman/listinfo/r-sig-geo


More information about the R-sig-Geo mailing list