3

I've got a shapefile with many polygons, each of which exactly overlays a contiguous region of raster cells; an example in yellow:

enter image description here

For some of these, I want to use the polygon as a sort of analysis mask, so that I can reclassify only those cells that are overlaid by the polygon according to one of the polygon's attributes. I have to do this thousands of times to the same raster, so I'm looking for a Python-automated way to do it, using (hopefully) any of GDAL/OGR, SAGA, QGIS, or numpy arrays.

nmtoken
13.6k5 gold badges39 silver badges91 bronze badges
asked Nov 5, 2015 at 23:03
0

1 Answer 1

1

Figured this out myself, posting for posterity.

The command line utility gdal_rasterize is able to "burn-in" values into a raster, given a polygon as the area over which to do so. It accepts SQL queries, which can be used to specify certain polygons in a whole layer. From the GDAL documentation (http://www.gdal.org/gdal_rasterize.html), one can call something like

gdal_rasterize -a ROOF_H -where 'class="A"' -l footprints footprints.shp city_dem.tif

That burns the attribute value in the field ROOF_H from footprints.shp into city_dem.tif, wherever there are polygons satisfying 'class="A"'.

answered Nov 21, 2015 at 3:14

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.