Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add MEAN option to MERGE_ALG in papszOptions for GDALRasterizeGeometries #9601

Open
dluks opened this issue Apr 3, 2024 · 2 comments
Open

Comments

@dluks
Copy link

dluks commented Apr 3, 2024

Feature description

Add a MEAN (or AVERAGE) option to the papszOptions parameter in GDALRasterizeGeometries, which would compute the mean value of the geometries located within a grid cell.

In its current state, the only way to do this using GDAL (or one of its many downstream projects such as rasterio), is to circuitously rasterize using ADD and then divide by a second raster containing number of intersecting points.

Additional context

When rasterizing vector geometries, especially point observations, is a common operation in environmental geoscience. Often, when rasterizing points, the average value of the points contained within a grid cell is needed. In this instance, the currently available options for MERGE_ALG don't really suffice. For example, when rasterizing a set of land surface temperature observations, the ADD option doesn't make sense and the REPLACE option discards valuable information.

Admittedly my C knowledge is minimal, so I'm not comfortable submitting a PR. Is there a more fundamental reason why this seemingly commonplace operation was omitted in the first place?

@jratike80
Copy link
Collaborator

Rasterize does not only create a new raster but it can also update existing pixels. A pixel in an image does not know its history. GDAL can ADD a value to existing value 4+2=6, but GDAL cannot know why the original value was 4, and the image cannot tell it either. It can be the initial value, or average of 2 or 3 or whatever.

Your current method feels reasonable to me.

@skampus
Copy link

skampus commented Apr 29, 2024

Same as in #7480

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants