[R-sig-Geo] crop by pixel
Robert Hijmans
r.hijmans at gmail.com
Wed Jul 27 21:41:43 CEST 2011
>> I need to crop a raster by pixel value, from upper X,Y left.
>> I'm using this:
>> spot <- raster(.........)
>> x_shift <- 2
>> y_shift <- 2
>> crop(spot,extent(xmin(spot)+res(spot)[1]*x_shift,xmax(spot),ymin(spot),ymax(spot)-res(spot)[2]*y_shift))
>> It works, but is there another way?
>A little bit less verbose:
>x <- crop( spot, extent(spot, x_shift, nrow(spot), y_shift, ncol(spot)) )
>For smaller raster files, you could also consider (notice the drop=FALSE
argument):
>x <- spot[x_shift:nrow(spot), y_shift:ncol(spot), drop=FALSE]
In the above I made a mistake: I reversed x_shift and y_shift. It should be:
x <- crop( spot, extent(spot, y_shift, nrow(spot), x_shift, ncol(spot)) )
x <- spot[y_shift:nrow(spot), x_shift:ncol(spot), drop=FALSE]
Robert
--
View this message in context: http://r-sig-geo.2731867.n2.nabble.com/crop-by-pixel-tp6622234p6627457.html
Sent from the R-sig-geo mailing list archive at Nabble.com.
More information about the R-sig-Geo
mailing list