2

How can I modify an existing DEM using a polygon? I have a DEM raster with terrain varying between 355 and 365 meters. I have a polygon I've drawn over the area. Ideally, I would like to uniformly reduce the DEM by 1 meter from its current height within the polygon (so new values will range from 354 to 364 meters).

I found this previous question and answer, however the workflow seems to have changed as I'm having trouble following the answer in QGIS 3.4. Also, that answer addresses how to alter the DEM to have a new absolute height based on the elevation values of the polygon, but now how to create new height values relative to the old height values. The reason I want to do this is because the terrain in question is on a slope, so I cannot simply assign a single elevation value to the entire area bounded by the polygon.

2

Here is an alternative workflow that will work with your particular use-case (which is a little different to the one you link to):

  1. Create your polygon and ensure that the vector file has the same CRS as your DTM
  2. Go Raster->Conversion->Rasterize. Change the 'fixed value to burn' field to the relative height you want to add or subtract from your raster. Set the output raster size units to 'Georeferenced units' and the width and height to the same resolution as your DTM. Set the 'output extent' either to the same as your DTM, the canvas or select an area but bear in mind that the extent here will limit your output later. Set 'No Data value' to anything but zero (-9999 is good - or 'not set'). Keep 'pre-initialize output image' as the default zero. Set your file name and click run.
  3. You now have two rasters - your original DTM and a raster version of your polygon. Go Raster->Raster Calculator and double-click your DTM in the Raster Bands box. Click plus and then double click your newly created raster. You should now have a formula that looks something like this: "DTM@1" + "myPolygon@1" (for more info on the raster calculator see here). Select you DTM or the new raster and set 'Selected Extent' (depending on your preference and the setting you used in step 2). Set output Layer name and type and hit 'OK'.

If you have multiple polygons each with different values, you can set 'Field to use as burn-in' in step 2 instead of a single fixed value.

Caution - if you don't set an initialization value as Zero or leave NoData value as zero (step 2) you will end up with a load of NoData in the output outside the polygon. So just be sure of your settings in step 2 (measure twice - cut once!).

  • Thank you for the clear answer! Unfortunately when I run this, I'm getting an error regarding resolution (-tr flag), as my resolution is set to 0 by default. How do i determine what values to input here? – BogBody Nov 13 '18 at 17:32
  • 1
    In your DTM go to properties->Information. Near the bottom of the first section you will see 'Pixel size' (e.g. 50,-50). Note this and don't worry about the minus. use this value as the resolution in Step 2 above but remember to make sure you set the raster size units to 'Georeferenced Units' and not 'Pixels'. – MappaGnosis Nov 13 '18 at 17:37
  • I increased the resolution to smooth out the rasterized polygon, but this obviously has the downside of increasing the file size. Any suggestions for how to smooth the edges of the resulting raster without exponentially increasing filesize? – BogBody Nov 13 '18 at 18:59

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.