[R-sig-Geo] merge rasters with different origins

john polo jpolo at mail.usf.edu
Mon Aug 24 23:25:03 CEST 2015


List,
I have 3 elevation rasters that I want to merge into one raster. Ras1 is 
north-most, ras2 is in center, and ras3 is south-most.

 > ras1
class       : RasterLayer
dimensions  : 1488, 1227, 1825776  (nrow, ncol, ncell)
resolution  : 9.495279, 9.495279  (x, y)
extent      : 295923.3, 307574, 3930569, 3944698  (xmin, xmax, ymin, ymax)
coord. ref. : +proj=utm +zone=15 +datum=NAD83 +units=m +no_defs 
+ellps=GRS80 +towgs84=0,0,0
data source : elevation\ned10m35095e2.tif
names       : ned10m35095e2
values      : 139.683, 271.0386  (min, max)

 > ras2
class       : RasterLayer
dimensions  : 1490, 1226, 1826740  (nrow, ncol, ncell)
resolution  : 9.488669, 9.488669  (x, y)
extent      : 296240.2, 307873.3, 3944427, 3958565  (xmin, xmax, ymin, ymax)
coord. ref. : +proj=utm +zone=15 +datum=NAD83 +units=m +no_defs 
+ellps=GRS80 +towgs84=0,0,0
data source : elevation\ned10m35095f2.tif
names       : ned10m35095f2
values      : 146.5723, 287.688  (min, max)

 > ras3
class       : RasterLayer
dimensions  : 1491, 1225, 1826475  (nrow, ncol, ncell)
resolution  : 9.482029, 9.482029  (x, y)
extent      : 296558, 308173.5, 3958295, 3972432  (xmin, xmax, ymin, ymax)
coord. ref. : +proj=utm +zone=15 +datum=NAD83 +units=m +no_defs 
+ellps=GRS80 +towgs84=0,0,0
data source : elevation\ned10m35095g2.tif
names       : ned10m35095g2
values      : 145.3133, 330.6396  (min, max)

I tried merging the files in steps, while not knowing what a reasonable 
value for tolerance should be, such as:
rasb <- merge(ras2, ras3, tolerance = .5)
Warning message:
In vv[is.na(vv)] <- getValues(x[[i]])[is.na(vv)] :
   number of items to replace is not a multiple of replacement length
 > rasc <- merge(ras1, rasb, tolerance = .5)
Warning message:
In vv[is.na(vv)] <- getValues(x[[i]])[is.na(vv)] :
   number of items to replace is not a multiple of replacement length

And when I plot the rasc, the two files merged in the 1st step look 
fine, but the 3rd raster looks seriously warped. I tried using the 
original files in different combinations, but the 3rd raster remains 
warped in the plot. I've also tried merging all three at the same time 
with same result for the plot.

I understand that this probably has something to do with a different 
origin for each file. I tried setting tolerance as high as 15, but that 
didn't seem to change the result.

 > origin(ras1)
[1]  2.920684 -1.739802
 > origin(ras2)
[1]  3.936303 -2.994262
 > origin(ras3)
[1] -1.914666  2.977150

What steps are necessary for this merge to work?

As a related question, those origin values are not what I would expect; 
I would expect the values to be something relevant to UTM values in 
south central U.S., thousands (of meters). Are those values "canvas" 
values?

Here is my session info:

R version 3.2.1 (2015-06-18)
Platform: x86_64-w64-mingw32/x64 (64-bit)
Running under: Windows 7 x64 (build 7601) Service Pack 1

cheers,
john polo



More information about the R-sig-Geo mailing list