Search code examples
rrasterr-raster

Calculating a CHM with dtm and dsm with different resolutions


I have a DTM and DSM with different resolutions. Here are the summaries of each Raster layer.

> raster_dsm
class       : RasterLayer 
dimensions  : 2001, 2501, 5004501  (nrow, ncol, ncell)
resolution  : 0.5, 0.5  (x, y)
extent      : -112500.2, -111249.8, 388999.8, 390000.2  (xmin, xmax, ymin, ymax)
coord. ref. : +proj=tmerc +lat_0=0 +lon_0=16.33333333333333 +k=1 +x_0=0 +y_0=-5000000 +ellps=bessel +units=m +no_defs 
data source : D:/Test_Raster/DSM/dsm.asc 
names       : dsm 

>raster_dtm
class       : RasterLayer 
dimensions  : 1001, 1251, 1252251  (nrow, ncol, ncell)
resolution  : 1, 1  (x, y)
extent      : -112500.5, -111249.5, 388999.5, 390000.5  (xmin, xmax, ymin, ymax)
coord. ref. : +proj=tmerc +lat_0=0 +lon_0=16.33333333333333 +k=1 +x_0=0 +y_0=-5000000 +ellps=bessel +units=m +no_defs 
data source : D:/Test_Raster/DTM/dtm.asc 
names       : dtm

As you can see, the resolution of the dtm is 1 m and the resolution of the dsm is 0.5m.

I want to calculate a Crown Heigth Model (CHM). The easiest way is to CHM = dsm - dtm

But when I try in R the following error code appear:

Error in compareRaster(e1, e2, extent = FALSE, rowcol = FALSE, crs = TRUE,  : 
  different resolution

Is there a simple way to ignore the resolution? Or must I do a resampling of the data, before further calculation? In ArcGis you can do this kind of raster calculation easily, because you don't have to resample the data first.

Any suggestions will be appreciated!


Solution

  • Yes, Arc*** will do this for you, but what does it actually do? I think it is better to avoid that kind of ambiguity. In this case you cannot use dis/aggregate because the extents are different. So you need to use resample