3

I have two elevation rasters that I want to combine into an output like the one shown in the image - Expected result.

I tried that using Gdal: Merge, but it doesn't take into account my NoData cells as seen in Merge - Result.

From what I understand from this question, it is possible to do that using GRASS's tool r.mapcalculator. I tried the solution listed there, but it outputs only a few pixels where the two rasters overlap.

How can I adapt the code below to match my needs?

r.mapcalc "output = not(if(a))*b"

I am open to other suggestions as well.

I am using QGIS 2.14 with GRASS 7.0.4.

  • 2
    This doesn't answer your question, but gdal_merge can take into account NoData values with the -n option for the input and -a_nodata for the output (official doc). – ArMoraer Sep 6 '16 at 9:12
  • 1
    You're right, thank you. Actually I was using gdal: Merge from the QGIS GUI and it didn't have the option for NoData. But I've used gdal_merge and it worked perfectly. Now I don't know if I should leave the question here or just delete it. – Ralu Bur Sep 6 '16 at 9:29
  • 1
    I would suggest leaving the question open and @ArMoraer posting an answer :) – Joseph Sep 6 '16 at 10:30
  • A solution using r.mapcalculator is still welcome, because gdal_merge stops my automated script with a "Python.exe has stopped working" error, as seen here, here and here. – Ralu Bur Sep 7 '16 at 12:30
1

One option to achieve this is using gdal_merge.py. But unfortunately, this tool stops my automated script with a "Python.exe has stopped working" error, as others complained here, here and here.

Another option, which actually works for me, is using SAGA's tool Mosaic raster layers, which doesn't generate any errors:

#prepare QGIS environment
import sys
from qgis.core import *
from PyQt4.QtGui import *
app = QApplication([])
QgsApplication.setPrefixPath("E:\\QGIS\\apps\\qgis", True)
QgsApplication.initQgis()

#prepare processing framework 
sys.path.append('E:\\QGIS\\apps\\qgis\\python\\plugins')
from processing.core.Processing import Processing
Processing.initialize()
import processing
from processing.tools import *

#set variables
algorithm = "saga:mosaickrasterlayers"
inputMain = path + "Flood_main.tif;"
input2D = path + "Flood_cvasi2D.tif"
addInput = None
dataType = 7
interpolation = 0
overlapAreas = 1
blendDistance = 10
match = 0
fit = 0
extent = "612550.33,660022.33,679329.28,703773.28"
result = path + "Flood.tif"

#run algorithm
processing.runalg(algorithm,inputMain + input2D, addInput, dataType, interpolation,
                  overlapAreas, blendDistance, match, fit, extent, result)

#exit QGIS
QgsApplication.exitQgis()
QApplication.exit()

QGIS version: 2.14.3-Essen

  • saga mosaickrasterlayers als oworks well! – brentiemapper Jan 15 at 6:06

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.