I have several DEM rasters in different projections and at different resolutions. The rasters are not rectangular, but they have appropriate NoData values. They overlap enough that I should be able to make a seamless dataset across the entire area, but is there a way I can use the GDAL tools to warp/mosaic them to get that seamless dataset?

I'm currently using the following command line to warp and mosaic the datasets:

gdalwarp -t_srs epsg:3857 -tr <calculated-x> <calculated-y> -r cubicspline output.tif input1.tif input2.tif ...

The problem is that the edges of the raster datasets don't always match each other, so I get effective cliffs at the edges. Is there a way to average them together for a few pixels near the edges of data for the dataset on top?

I'd really prefer to be able to do this in batch via command line or Python bindings.


Here's an (extreme) example of what I'm trying to avoid:

I'm not hugely fond of the ridges at the edge there.

I'm using the USGS NED 1/3 data as a seamless starting point, so I'm guaranteed to have something at every pixel (and the higher-resolution datasets that don't cover the entire area will always have something to be blended with).

  • Is the edge an artefact on the top raster that needs to be removed, or is it a mismatch between the two rasters? If you don't find a decent solution, I wrote a program in c++ (for learning purposes -- no representations as to quality!) that uses a sigmoid blend to mosaic a stack of rasters. If you're a programmer, you can try to get it working.
    – Rob Skelly
    Apr 3, 2016 at 18:14
  • For the most part, it's a mismatch between the rasters that I want to deal with. I suspect there's a genuine artifact on the right side there, but I figure any solution that will fix the mismatches should either let me manually cut out artifacts like that or just mitigate them a bit.
    – asciiphil
    Apr 3, 2016 at 22:00
  • If you want fine control, you can just use Gimp or Photoshop and add the georeference information back afterwards using GDAL.
    – Rob Skelly
    Apr 3, 2016 at 23:47
  • Yeah, that can take care of the artifacts I want to fix manually, but I don't see how it can help my root desire: blending each new dataset with the existing mosiac at the edges of the new dataset's data areas.
    – asciiphil
    Apr 4, 2016 at 19:09
  • 1
    If you use an alpha blend on the edges, the effect is a weighted mixture of the elevations of the top raster and the bottom one. So if a given pixel's alpha is 50%, and the top raster has 100m and the bottom 90m, the final pixel is 100 * 0.5 + 90 * 0.5 = 95m. Of course, this has the effect of "bending" each raster to meet the other but it will eliminate the seams. Naturally, if you don't have enough overlap between the rasters, it won't work.
    – Rob Skelly
    Apr 4, 2016 at 20:26

2 Answers 2


Fill raster regions by interpolation from edges.

gdal_fillnodata.py [-q] [-md max_distance] [-si smooth_iterations]
                [-o name=value] [-b band]
                srcfile [-nomask] [-mask filename] [-of format] [dstfile]
  • 2
    I don't think that will do what I want. The only NoData regions I have are outside the data collection areas of the individual datasets. I already have other data to put into those regions (either other datasets or just NED 1/3). I just want to blend them together so there aren't major discontinuities at the dataset edges. (I added an example to my question. Hopefully that better illustrates my problem.)
    – asciiphil
    Apr 3, 2016 at 12:25

It's likely, as mentioned by @RobSkelly, that the DEMs you are using have different elevation values where they overlap. If you merge an NED dataset with SRTM for example, the values can differ just based on the manner in which they were acquired, never mind which datum they use etc. This 'bias' should be corrected for prior to merging at the overlap region. Take the NED as the 'baseline' and adjust the other DEMs to have the same value as this for a given point (or same average over the dataset). This will reduce this effect although the problem will persist to some degree.

To eliminate completely would require that the data are merged using a relationship between the two (e.g., a spline) but it's best to start by eliminating the easier options such as correcting for bias. I understand that higher resolution data is preferable but resampling to the lowest resolution dataset will also alleviate this artifact.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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