I have two different DEM grids (basically single-band GeoTIFFs) and I want to merge them.

The grids overlap and have different values, and I want to create a new DEM grid that takes the average or maybe maximum value in the overlapping regions. The DEM grids already have a nodata flag in them.

Currently I have this script through OsGeo4W:

set pathin=F:\mergebox_DEM\IN
set pathout=F:\mergebox_DEM\OUT
set filename=Merge_result

gdalbuildvrt -tr 0.3 0.3 -r bilinear index.vrt %pathin%\*.tif
gdal_translate index.vrt %pathout%\%filename%.tif -tr 0.3 0.3 -co COMPRESS=PACKBITS -co BIGTIFF=YES

Currently, my merged result looks like this (pseudocolor scale added for emphasis): improper_merge

This is not very good - you can clearly see that the files are simply overlapped. I think I see why that happens - the bilinear resampling is applied after the two files are overlapped?

Am I missing something very basic?

I don't want to use a raster calculator, because in the future I might have to merge a large number of files and I would like to be able to do it directory-wise.

  • I’m afraid you won’t get around using something like a raster calculator, since you want to combine the values (compute their average). Actually, it might prove even more complex than a simple raster calculator function: you might have to resort to a custom script – which in turn allows you to optimise the processing. gdal-python or rasterio are your friends – christoph Jun 20 '17 at 13:20
  • That might be so - my problem is that with most raster calculators you have to give the attributes (-a raster1.tif -b raster2tif.etc) and I will have a large group of them for such syntax. Ideally I would want one that takes all raster grids I give it and just spits out the average, instead of simply choosing the last pixel value it encounters. Thanks for the tip with rasterio, looking into it now. – miln40 Jun 20 '17 at 16:26

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.