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

Subpixel overlap in AggregateRaster #64

Closed
caspervdw opened this issue Aug 26, 2020 · 3 comments
Closed

Subpixel overlap in AggregateRaster #64

caspervdw opened this issue Aug 26, 2020 · 3 comments

Comments

@caspervdw
Copy link
Collaborator

caspervdw commented Aug 26, 2020

Possibly related to #43

@wietzesuijker Raised this issue originally. If a polygon is smaller (or comparable) to the size of a single raster cell (pixel), then in some cases the polygon gets NaN for the aggregation result. A test confirming this behaviour is in #63

The issue here is that GDAL's Rasterize only takes into account pixels whose center are inside the polygon. In other words, if a polygon does not contain any pixel centers, there is nothing to aggregate.

What do we want to do in dask-geomodeling? One way to tackle this is adding ALLTOUCHED=TRUE to the options, but that might not be good in all cases. (see https://gdal.org/python/osgeo.gdal-module.html#RasterizeOptions)

Also, I have the feeling that we might be introducing a half-pixel shift here? @arjanverkerk

Note that this also has consequences for the bucketize algorithm.

@arjanverkerk
Copy link
Contributor

Note that all pixels with center inside polygon or those on the line render path are taken into account. The test in #63 also fails because the polygon stays within a single pixel (so no line algorithm). The line algorithm makes the rasterization less accurate even for larger polygons, because it causes more pixels to be taken into account then without it. Nevertheless, the this issue stands.

https://pythonhosted.org/rasterstats/ seems to follow (or use) the same two options that GDAL offers. I understand that QGIS has/had a hybrid method switching to and exact calculation when the amount of pixels aggregated falls below some threshold.
That maybe a possibility for us, too. We could also refine the raster in that case, which would be less accurate but probably also less work.

Or use all_touched=true (to get rid of the line algorithm) and do multiple runs with different shifts (is that what you mean with the half-pixel shift, @caspervdw ? I've thought in that direction, too, but couldn't get my head around it yet. I think it makes things too complicated anyway.

@caspervdw
Copy link
Collaborator Author

This discussion is BTW related to #43, there a reference is made to https://github.com/isciences/exactextract.

I think that taking into account partial pixels is overkill for us. "just" doing all_touched=true might be enough. This would overestimate sum and count in some cases.

@caspervdw
Copy link
Collaborator Author

Closing as it is a duplicate of nens/lizard-nxt#5262

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

No branches or pull requests

2 participants