3

I would like to know how to change the values of raster cells which are within a polygon, leaving all cell values outside the polygon unchanged. I would like to subtract 1.5m from each raster cell value within the polygon, rather than make them all the same value.

I don't know how to use GRASS so I'm hoping there is a way to do it using the tools within the QGIS GUI, raster calculator, or processing toolbox. I'm using QGIS 2.0.

Thanks.

2

First, you need to convert your polygon to a raster. Create an integer field filled with "1" for the purpose of the conversion. (raster > conversion > rasterize)

Then, you can use the raster calculator to substract 1.5 where your polygon exists.

 yourdem@1 - ((poltoras@1 = 1) * 1.5 ) 
  • thanks. That method gives me an output raster which is the same extent as the polygon. I'm hoping to get an output raster the same size as the original DEM. In the output raster's metadata; the layer extent is the same as the original DEM, the max & min values are the original DEM's -1.5m (which is correct) for the area within the polygon, but there are no cells outside the polygon. I set output extent in the Raster Calculator to be the same extent as the original DEM's. Any ideas where I'm going wrong here please? – ffinnm Jan 29 '14 at 10:17
  • well, you could fix the extents according to gis.stackexchange.com/questions/62042/…, or buiding a virtual raster (Raster ‣ Miscellaneous ‣ Build Virtual Raster (Catalog).) with the required extent, but as you prefer not to go out of the GUI, the workaround is to make a background polygon with the extent of your DEM. – radouxju Jan 29 '14 at 10:33
  • thank you, I will go with the background polygon method. What should I do with this background polygon? – ffinnm Jan 29 '14 at 10:59
  • I worked how to use the background polygon. Thank so much for your help. – ffinnm Jan 29 '14 at 14:05
1
  1. make copy of raster (raster2)
  2. Use Raster / Conversion / Rasterize

    • select you polygon layer, make field with -9999 or some value which is not in your raster2
    • as target use your copy raster2 raster/grid
    • Keep existing size and resolution
  3. Use Raster / Raster Calculator...

    • expression should be like this: ("raster2" = -9999)*("raster1"-1.5) + ("raster2" != -9999)*"raster2"
0

Or using the new Qgis plugin designed for that: ThRasE

We're looking for long answers that provide some explanation and context. Don't just give a one-line answer; explain why your answer is right, ideally with citations. Answers that don't include explanations may be removed.

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.