2

I have a shapefile (ShapeY) of European extend and want to rasterize each time only a certain area of the shape (ShapeX) (i have the shapes indicating the prevailing extend) with python and QGis.

However so far i have not found a way to write the code in a manner that it already uses Shape X as mask.

My code reads as following:

err = gdal.RasterizeLayer(target_raster, (3,2,1), source_layer1, options=["ATTRIBUTE=%s" % RASTERIZE_COLOR_FIELD1])

The only solution i found was clipping the resulting layer afterwards with Shape X, but this takes significantly much time. I assume there is a smarter way of initially setting the mask while rasterizing?

  • With gdal_rasterize gdal.org/gdal_rasterize.html you could use -te option for defining target extents. Since GDAL 2.1 you can use gdal_rasterize. I don't know how to do the same with Python from QGIS but I believe that it is possible. Perhaps you can take the envelope of the shape X and use that as an extent when the GeoTIFF is created. – user30184 May 15 '16 at 15:54
  • But as i understand it there the target extend is a rectangle defined by x/y min/max. I dont see how it is possible to set the outline of a certain layer as extend. – Philipp Dahlem May 16 '16 at 14:35

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.