2

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.

  • How do you expect or require multiple values in a single cell to be aggregated? Sum, mean, first ,last, etc...In the end, multiple points will have to be converted to a single value, as you are seeing. – Evil Genius Oct 26 '15 at 10:49
  • Raster value should be the sum of the attributes of the points falling inside the raster cell. – Erkka Rinne Oct 26 '15 at 11:01
  • Oh you did specify that, I read that sentence a few times and still didn't see it...sorry! – Evil Genius Oct 26 '15 at 11:02
  • 1
    Try setting the rasterize option MERGE_ALG=ADD. – user10353 Oct 27 '15 at 15:28
3

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.

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.