I have imported some rasters that is supposed to be continuously connected but instead they create some sort of bordered grid between them. I may assume that this is a matter of calibration between the individual rasters but I am not sure how to execute it in a datawise manner.

Have anyone experienced something like this before and perhaps know of a possible solution so that the overall of all the rasters will be more smooth.

All of these are supposed to be geographically connected. Hence the trouble of the 'borders' of the square.

I am using QGIS on windows.

enter image description here


2 Answers 2

  1. You could try merging the rasters into one:

    • From the toolbar:

      Raster > Miscellaneous> Merge

    • From the Processing Toolbox:

      GDAL/OGR > Miscellaneous > Merge

    • From the GDAL console:

      gdal_merge.py -o merged.tif input1.tif input2.tif

  1. Or build a virtual raster:

    • Raster > Miscellaneous> Build Virtual Raster
  • 1
    +1 for build Virtual Raster. This will create a very small file that will act like a single merged image. Jan 22, 2016 at 15:49
  • @AlexandreNeto - Thanks, I have noticed that the difference in file size compared to the separate rasters can be quite staggering =)
    – Joseph
    Jan 22, 2016 at 15:51
  • When choosing the merge or build virtual raster I get an error proclaiming that the process could not start. The porgram doesn't exist or i don't have the right rights. Therefore I succeeded doing a merge or build by loading all the rasters into the Layers-menu and choosing from there. Gdal_merge.bat command line can be too long, atleast inputx.tif can suspend the operation at 1000 x (different rasters)
    – MichaelR
    Jan 22, 2016 at 16:00
  • @Michael - Strange error but glad you found another way to get your results :)
    – Joseph
    Jan 22, 2016 at 16:02
  • 1
    @Michael At command line you can feed gdalbuildvrt with the filename of a file containing a list of files, rather then give many image files as arguments: gdalbuildvrt -input_file_list my_liste.txt doq_index.vrt
    – Detlev
    Jan 27, 2016 at 6:39

The reason for this mosaiked appearance is that each single image is drawn with gray scale stretched from image min to image max, and NOT across the global min/max. When you merge all images into one, well, there is only one min/max. Same is true for VRT, since VRT treats all images as one (when you have a look into the VRT file you will see the common statistics).

When both, merge and VRT, are not an option the following script might help.

In the first loop I iterate over all layers, picking the rasters and get an estimate of their min/max interval. This is the way like QGIS itself work. From these min/max values I calculate the global min/max

In the second loop the renderers for all raster layers are configured such that the gray scale is stretched across the interval global min/max.

gmin = 9999
gmax = -9999
layers = []
# loop over all layers, take rasters and estimate min, max values
for layer in iface.mapCanvas().layers():
    if isinstance(layer, QgsRasterLayer):
        # change percentages and sample size to increase or decrease accuracy
        min_max = layer.dataProvider().cumulativeCut(1, 0.02, 0.98, theSampleSize=250000)
        gmin = min(gmin, min_max[0])
        gmax = max(gmax, min_max[1])

# for all rasters create a single band gray scale renderer with 
# gray scale stretched across the interval [gmin..gmax]
for rasterlayer in layers:
    renderer = QgsSingleBandGrayRenderer(rasterlayer.dataProvider(), 1)
    # take the first band (0)
    ce = QgsContrastEnhancement(rasterlayer.dataProvider().dataType(0))


# refresh canvas to show changes

Your Answer

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

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