Thursday, 10 October 2019

python - Rasterizing point layer with multiple features falling inside raster cell using GDAL?


How to make a raster with values that are the sum of all points inside each raster cell?



The burn value is a specific attribute.


Using gdal_rasterize or gdal.RasterizeLayer(), the resulting raster only has the value of a random (or probably the first or last) point inside a raster cell. I’ve already tried gdal_rasterize option ALL_TOUCHED, but it does not change the behaviour.



Answer



Adding 'MERGE_ALG=ADD' to the list of options to gdal.RasterizeLayer() did the trick, thanks to kyle. An example:


gdal.RasterizeLayer(target_ds, [1], src_layer, options = ['MERGE_ALG=ADD'])

This is documented in http://www.gdal.org/gdal__alg_8h.html.


No comments:

Post a Comment

arcpy - Changing output name when exporting data driven pages to JPG?

Is there a way to save the output JPG, changing the output file name to the page name, instead of page number? I mean changing the script fo...