Hi all,
          I have a raster r I want to cut  in two, then place the right side to the left, and the left side to the right, and finally merge these two rasters again with the orginal raster x.
I wrote the following piece of code to perform this task:


r=raster(r)
extent(r)<-extent(xmin,xmax,ymin, ymax)
e1=extent(xmin,xmax/2,ymin,ymax)
e2=extent(xmax/2,xmax,ymin,ymax)
r1=crop(r,e1)
r1=shift(r1,(-xmax/2))
r2=crop(r,e2)
r2=shift(r2,xmax)
newr=merge(r,r1)

When I try to merge these two rasters first I get the following message: 

"Error in compareRaster(x, extent = FALSE, rowcol = FALSE, orig = TRUE,  : 
  different origin"
Looking at the extent it seems that the crop function is cropping 45 more meters than xmax/2 and that causes the differences in the origin. Actually when I shift r1, the origin is at 45 m, confirming the differences in cropping.  Any idea of how to solve this?


Thanks!
	[[alternative HTML version deleted]]

