I'm trying to use vector lines to change the height of the areas of my DEM that they overlay. They trace rivers, and i'm hoping to assign arbitrarily high values to the rivers so that my least-cost path analyses using r.walk don't constantly try to follow the riverbeds.

What's the best way to do this?

  • 1
    GDAL_Rasterize will create a raster from your lines.. are they 3d lines? If not how is your arbitrarily high value stored? – Michael Stimson Dec 10 '18 at 7:50
  • They aren't 3d lines. I just added an attribute to the table named "elevation" and set it to 9999. <br> I rasterized the line vectors, but now can't seem to merge it with the existing DEM successfully. What should I be doing to make this happen? – BogBody Dec 10 '18 at 7:55
  • You could try GDAL_Merge but it's not immediately clear which raster takes precedence where two or more overlap or use the raster calculator docs.qgis.org/2.8/en/docs/user_manual/working_with_raster/… with an expression that selects where your rivers is nodata docs.qgis.org/2.8/en/docs/training_manual/processing/… then use the DEM otherwise use the rivers. – Michael Stimson Dec 10 '18 at 8:09

First of all, it is quite logic that r.walk guide you along the riverbed. This is usually the path to walk along. If you change the rivers values to 9999, you will create artificial cliff that will be difficult to cross, and if you climb on it you will try to stay on it. Otherwise, you will just follow the riverbed with one pixel shift. I would instead suggest to use the rasterized river as a friction layer or to play with some parameters of r.walk

EDIT: after rasterizing, use

gdal_edit.py -unsetnodata your_rasterized_polygons.tif

to remove the nodata values of your raster

That being said, you can achieve what you want to do by combining the two comments to your question.

1) use gdal_rasterize to convert your lines to raster based on your attribute field that contains the 9999 values.

2) use the raster calculator to update your DEM with the new raster value

("yourrivers@1" != 9999) * "yourdem@1" + ("yourrivers@1" = 9999) * 9999
  • Thank you, however your suggestion for what to plug into the raster calculator is not producing a usable output. It's giving me a blank raster. – BogBody Dec 10 '18 at 14:42
  • Sorry, not a blank raster, but a raster that looks like my initial "yourrivers@1" raster. – BogBody Dec 10 '18 at 14:49
  • sorry, I forgot to manage the nodata. The easiest way is to simply remove them – radouxju Dec 12 '18 at 8:37

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.