 you need to describe what you want to do.  rasters are grids.  crop  works
to select a specified subgrid.
 It is rectangular by definition.

 Looking at what you have below  it appears that  you
 have a  tif file  " lai2011361.Lai_1km.tif "    that has an extent larger
than brazil.
And you want to use a polygon  that represents the border of brazil to
eliminate
all the pixel ( or set them to NA ) outside of brazil.

If that is correct,  then I can tell you how to proceed, or how I have
proceeded in the past
to do exactly that.

as others suggested you have to use the mask function.
Create a blank raster the same size as " lai2011361.Lai_1km.tif "
use the function  'rasterize()'  and your polygon to turn this into a
"mask"
 then its just raster algebra.  There might be a more elegant way,  but
this worked for me.



On Fri, Jun 1, 2012 at 11:49 AM, Thiago Veloso <thi_veloso@yahoo.com.br>wrote:

>   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@r-project.org
> https://stat.ethz.ch/mailman/listinfo/r-sig-geo
>

	[[alternative HTML version deleted]]

