3

First things first, I am completely new to this so please bare with me if this is a bit unclear as I lack the vocabulary.

I have two raster layers (a DEM and a DSM). The DEM layer covers a large rectangular region while the DSM only covers a part of the same region (the Urban part) and the shape of the area is a complicated polygon.

I want to produce a single raster which will have all the information from both DEM and DSM. When I try to merge those two, I get a valid result (everything aligns nicely) however, it looks like the DSM is being projected on the DEM and this results in gaps.

I have high hopes that the attached image will make the situation clear. Below you can see the result of merging the DEM and DSM rasters in 3D View (top) and 2D view (bottom).

PS: I tried to use GRASS r.patch but unfortunately its UI doesn't allow to chose the order of the layers in QGIS 3.10.

enter image description here

  • 1
    Looks like your dsm has a lot of nodata areas which are not defined as nodata. You could try redefining those using r.null before merging. – MrXsquared Sep 17 at 19:04
  • @MrXsquared I think you are right. r.null worked when I configured it to remove 0 values. I am wondering how can I detect this issue in the future. Is there a way to look into the data and see if there are Nulls, Zeros or -9999s? I foten work on regions which are quite close to sea level and I am wondering how to opt these values out...Removing zeros might not be the case there... – Dimitris Sep 18 at 15:55
  • There is no masterrule, I think the best thing is to take a look at histograms and inspecting pixelvalues for suspicious areas – MrXsquared Sep 18 at 17:34
2

I think that as @MrXsquared tells you, you must first solve the problem of non data or null. This is very common, it depends on the type of data and how the raster was generated.

You can search on this website to find out how to solve it.

If your null value is recognized by QGis, for example -9999 (used by SAGA). You could perform the procedure with the Raster Calculator with a simple sum of both rasters. Something like that:

(@dsm > 0 ) * (@dem + @dsm)

Explanation of the operation:

Read it from left to right, the first thing is a conditional that excludes null values, then, the multiplication operator makes an assignment, to the pixels that fulfill the condition assigns the result of the sum of both rasters.

To cover what does not meet the condition you can concatenate another operation with the sum sign, it would look like this:

(@dsm > 0) * (@dem + @dsm) + (@dsm < 0) * @dem

In the Raster calculator, you assign the extension of the DEM. Depending on the value of the no data you can vary this operation.

But if the value of the no data does not allow you to perform the operation, you should first change it with the Translate process or another option as I told you at the beginning.

| improve this answer | |
  • I am afraid this didn't work. The result looks exactly the same, however your explanation is quite helpful. I followed @MrXsquared method with r.null, removed all 0 values from the DSM and merged with DEM. It looks perfect now. – Dimitris Sep 18 at 16:06
1

Solution 1:

r.patch solved the problem if DSM and DEM files are inputted correctly into the algorithm. Unfortunately, changing the order of the files in the UI is not clear. You need to drag them in order in the selection window before clicking OK.

Solution 2:

As @MrXsquared described in a comment in the initial post, this problem occurs when "nodata areas" are described as data (in my case with zeros). In that case r.null also solves the problem, however it requires prior knowledge of the value of the data you want to remove. I had to figure this out by trial and error (-9999, NULL, 0 etc)

With my limited knowledge of GIS data, the r.null solution seems better since it actually fixes the data while r.patch is only resolving the problem. However, if you are working at sea level this might pose some issues!

Result of r.null enter image description here

Result of final merge enter image description here

Thank you all!

| 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.