Skip to content
Prev 7832 / 29559 Next

how to calculate with grids?

Bastian,

These rasters have a different extent and origin. So you cannot just
subtract them. This often some unfortunate processing choices earlier
on. But if that is not the case, I think you need to resample (and
hence distort) your data. You can use the raster package for this. Had
the origin been the same you could have used the 'crop' function only,
and not 'resample'.

install.packages("raster", repos="http://R-Forge.R-project.org")
library(raster)

dem1 <- raster("grid1.asc")
dem2 <- raster("dem2.asc")
intersect <- crop(dem2, dem1)
dem1r <- resample(dem1, intersect, method='bilinear', progress='text')
dem3 <- intersect - dem1r
plot(dem3)

#or vice versa, resample to dem2 rather than to dem1
intersect2 <- crop(dem1, dem2)
dem2r <- resample(dem2, intersect2, method='bilinear', progress='text')
dem4 <- dem2r - intersect2
plot(dem4)

Good luck,
Robert
On Tue, Mar 16, 2010 at 12:49 PM, Bastian P?schl <rotate at gmx.li> wrote: