I am preparing tiff elevation files. For one particular country I have a 10 meter elevation model, but the data is present only for the specific country - so when the image is sliced into smaller parts - for example 0.1 x 0.1 degree - there are null (no data) values outside the country's border. I have figured out that I can use gdalwarp -r bilinear 10M_tiff.tiff 30M_tiff.tiff out.tiff file to merge 10M and 30M tiff. But this command merges files fully. Is it possible to add additional parameters to the gdalwarp command so it will add values from 30M tiff only in the case that data in the 10M tiff is missing? (I would like to preserve original 10m elevation data where possible)


I think a way to achieve what you're trying to do is gdal_merge.py (i.e., a Python command line tool, see http://www.gdal.org/gdal_merge.html). In case of overlap, that tool will take the cells of the last named raster rather than those of any previous rasters, so listing the 10m raster last will ensure it's values are used when there's overlap. In that case you need to specify the output cell resolution, since the tool takes that of the first raster as default. Syntax would be something like:

python gdal_merge.py -ps 10 10 -o out.tif 30M_tiff.tif 10M_tiff.tif

Unfortunately, I don't see a way to specify the resampling method used this way, and I don't know what the tool uses by default.

Another approach might be to use gdalwarp, as you suggest, merging the 10m Tiff into a pre-existing copy of the 30m raster, and using the overwrite option (GDAL >= 1.8.0, see http://www.gdal.org/gdalwarp.html). I think that would replace the 30m elevation values with the new 10m ones. Something like:

gdalwarp -tr 10 10 -r bilinear -overwrite 10M_Tiff.tif 30M_Copy_Tiff.tif
| improve this answer | |

I have 10 meter DEM model with holes on the borders. I also have full 30m DEM model. The DEMs are in different coordinate system.

  • transform 10m coordinate system to the same coordinate system as 30m meter
  • slice a 0.1 x 0.1 degree tiff with gdal_translate - gdal_translate -projwin 5 48.10 5.10 48 -ot Int16 -r bilinear bigTiff.tiff slice.tiff
  • slice a 0.1 x 0.1 degree tiff from the 30m model
  • now you have two tiffs 10m with holes and 30m without holes. Keep original tiff and create merged tiff by issuing following gdalwarp -r bilinear 10m_slice.tiff 30m_slice.tiff 10m_30m_slice.tiff
  • now we want the best 10m model possible - so we wish to preserve 10m values where possible. Open 10m slice tiff and read values from it. If the values is equal to no_data value copy the value from the merged model. You can read raster tiff in python very simply - with numpy arrays
| improve this answer | |

Your Answer

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

Not the answer you're looking for? Browse other questions tagged or ask your own question.