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

Improve AggregateRaster for small source geometries #104

Closed
wants to merge 2 commits into from

Conversation

byrman
Copy link

@byrman byrman commented Mar 24, 2023

This pull request solves https://github.com/nens/lizard-nxt/issues/5814 by using a different strategy in AggregateRaster.

An alternative solution is to enable the ALL_TOUCHED rasterization option in GDAL (affecting other calculations too): https://gdal.org/programs/gdal_rasterize.html#cmdoption-gdal_rasterize-at.

Copy link
Collaborator

@caspervdw caspervdw left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I recall making the # snap the extent to (0, 0) to prevent subpixel shift part to make label computations deterministic.

There was problem that the outcome of an aggregation value depended on other geometries being present. This is because the extent is computed based on all geometries in the request.

I think that effect is back now as x2, y1 are not snapped anymore to (0,0).

@byrman
Copy link
Author

byrman commented Mar 27, 2023

@byrman
Copy link
Author

byrman commented Mar 27, 2023

I think that effect is back now as x2, y1 are not snapped anymore to (0,0)

"think"?

@caspervdw
Copy link
Collaborator

Have you seen these results: https://github.com/nens/lizard-nxt/issues/5814#issuecomment-1479321495?

I think that effect is back now as x2, y1 are not snapped anymore to (0,0)

"think"?

Yes I read the issue. I am afraid I don't understand what is happening.
Also I can't oversee the effects of this change completely.

Does this test fail now?

I just want to be sure that this solution doesn't break other use cases.

@arjanverkerk
Copy link
Contributor

I recall making the # snap the extent to (0, 0) to prevent subpixel shift part to make label computations deterministic.

There was problem that the outcome of an aggregation value depended on other geometries being present. This is because the extent is computed based on all geometries in the request.

I think that effect is back now as x2, y1 are not snapped anymore to (0,0).

Ah, the clash of use cases... What is the subpixel shift we try to avoid? I'd guess that what is meant is that the rasterization of a particular feature does not depend on the envelope of the group of features that are rasterized together. But by anchoring anchoring to (0, 0), the tiniest change in pixel_size may result in a big shift of the bounding box requested to the raster source in the current situation which may have big effects on the rasterization.

So should we add an option here to choose between snapping methods? We also may need an option to enable the ALL_TOUCHED gdal option.

@caspervdw
Copy link
Collaborator

I'd guess that what is meant is that the rasterization of a particular feature does not depend on the envelope of the group of features that are rasterized together.

Exactly. Well put!

the tiniest change in pixel_size may result in a big shift of the bounding box requested to the raster source in the current situation which may have big effects on the rasterization.

I don't get that part. The "big shift" is at maximum 1 cell, right? From what perspective is that big? And in any case, the geometry will be enclosed by the raster.

What happens in rasterization to a geometry much smaller than 1 cell?

@byrman
Copy link
Author

byrman commented Mar 27, 2023

Does this test fail now?

All pull requests fail, not just mine. I don't know what's wrong with the test setup. I would be happy the run the tests locally in a container (but no Docker files are present).

@caspervdw
Copy link
Collaborator

Does this test fail now?

All pull requests fail, not just mine. I don't know what's wrong with the test setup. I would be happy the run the tests locally in a container (but no Docker files are present).

Just make a virtualenv, any python version will do.

@byrman
Copy link
Author

byrman commented Mar 27, 2023

Just make a virtualenv, any python version will do.

Doesn't the project require more than that (e.g. gdal libraries)? I prefer to keep my (macOS) host clean, because I work on many different projects.

@caspervdw
Copy link
Collaborator

Just make a virtualenv, any python version will do.

Doesn't the project require more than that (e.g. gdal libraries)? I prefer to keep my (macOS) host clean, because I work on many different projects.

Yes you do need to have the GDAL binaries, on Ubuntu that would be apt install libgdal-dev.

@arjanverkerk
Copy link
Contributor

I don't get that part. The "big shift" is at maximum 1 cell, right? From what perspective is that big? And in any case, the geometry will be enclosed by the raster.

From the perspective of the cells near the edge of a feature it means everything, it means to be included or not. We're talking about the rain raster here, which has 1000 m cells. Of course, one should pick a much smaller pixel_size (supersampling) when the geometry's area is in the same order as the pixel area, and that is what I suggested and @byrman tried. But then he noticed how small pixel_size changes affected the result very much.

What happens in rasterization to a geometry much smaller than 1 cell?

Good one. In this use case it is not clearly defined. We have a small diamond shaped geometry. When near or at the center of a cell, it gets rasterized. But when it is over the intersection between 4 cells and away from centers, it is not rasterized (Bresenhams line algorithm, not exactly meant for this use case I guess) unless 'ALL_TOUCHED=TRUE'.

@byrman byrman closed this Mar 27, 2023
@byrman byrman deleted the byrman_aggregate branch March 27, 2023 11:02
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

Successfully merging this pull request may close these issues.

None yet

3 participants