More

Different origin problem while merging rasters

Different origin problem while merging rasters


I have two dem files downloaded via thegetDatafunction in the raster package. Here you can see the code:

I tried to make the example reproducible so there you have it.

library(raster) dem_n1<-getData("SRTM",lon=26,lat=43) dem_n2<-getData("SRTM",lon=31,lat=43) demALL<-merge(dem_n1,dem_n2)

While attempting to perform the merge, the following error appears:

Error in compareRaster(x, extent = FALSE, rowcol = FALSE, orig = TRUE, : different origin

This works as expected for me:

> demALL class : RasterLayer dimensions : 6000, 12000, 7.2e+07 (nrow, ncol, ncell) resolution : 0.0008333333, 0.0008333333 (x, y) extent : 25, 35, 40, 45 (xmin, xmax, ymin, ymax) coord. ref. : +proj=longlat +datum=WGS84 +ellps=WGS84 +towgs84=0,0,0 data source : c:TempR_raster_rhijmans
_tmp_2015-10-22_102651_340_06019.grd names : layer values : -37, 2573 (min, max)

However, there is a small difference in the origin due to floating-point imprecision

origin(dem_n1) #[1] 0 0 origin(dem_n2) #[1] -3.552714e-15 0.000000e+00

but that should not matter

So I wonder if you are using the current versions ofRandraster? If you are, you could probably get around this by setting

rasterOptions(tolerance = 0.1)

(That is actually the default value) or perhaps

.Machine$double.eps <- 0.000000001

or something like that


I faced a similar issue with other raster files even when using the most recent version ofRand therasterpackage. The above did not work for me. Instead, by trying

mergedraster <- raster::merge(raster1, raster2, tolerance = 0.1)

worked fine.


Watch the video: QGIS - Clipper - Clip Raster with shapefile boundary