Hi all,

I'm currently having some problems getting the crop() function in the raster
package to work properly, and cannot for the life of me figure out what's
going on.

Essentially, I'm trying to crop a larger raster (raster1) to match one with
a smaller extent (raster2), which is entirely contained in the first raster.
The projections seem to match and the resolution is the same.

> e <- extent(raster2)
> raster3 <- crop(raster1,e,progress="text")
> extent(raster2)
class       : Extent
xmin        : 281*885*
xmax        : 523*415*
ymin        : 5515*285 *
ymax        : 5731*615 *
> extent(raster3)
class       : Extent
xmin        : 281*900*
xmax        : 523*400*
ymin        : 5515*271 *
ymax        : 5731*601 *


This is the part I don't understand. Does it have something to do with the
pixel definitions (i.e., 30m distance starts at left for one file vs. center
for another)? If so, how can I adjust this and can I do so in an automated
fashion? Note that the x difference is 15 and y difference in 14. I also
can't seem to replicate this with dummy rasters created from scratch
(sorry).

Here are the file details:

> projection(raster1) == projection(raster2)
[1] TRUE

> raster1
class       : RasterLayer
dimensions  : 11737, 17827, 209235499  (nrow, ncol, ncell)
resolution  : 30, 30  (x, y)
extent      : 102050, 636860, 5470571, 5822681  (xmin, xmax, ymin, ymax)
coord. ref. : +proj=utm +zone=15 +ellps=WGS84 +datum=WGS84 +units=m +no_defs
+towgs84=0,0,0
values      : /raster1.tif
min value   : 0
max value   : 255

> raster2
class       : RasterLayer
dimensions  : 7211, 8051, 58055761  (nrow, ncol, ncell)
resolution  : 30, 30  (x, y)
extent      : 281885, 523415, 5515285, 5731615  (xmin, xmax, ymin, ymax)
coord. ref. : +proj=utm +zone=15 +ellps=WGS84 +datum=WGS84 +units=m +no_defs
+towgs84=0,0,0
values      : /raster2.TIF
min value   : 0
max value   : 255



Unfortunately, the documentation doesn't seem to indicate that there are any
special cases where such an error would occur. Any help would be much
appreciated.

Thanks,
Nick

	[[alternative HTML version deleted]]

