Fix missing tiles in corners for fast gridding by using off-boundary pixels#255
Merged
joshuacortez merged 18 commits intothinkingmachines:masterfrom Sep 10, 2024
Merged
Conversation
…gTileGridGenerator
…in voxel_traversal_scanline_fill
|
Check out this pull request on See visual diffs & provide feedback on Jupyter Notebooks. Powered by ReviewNB |
tm-jc-nacpil
approved these changes
Sep 10, 2024
Contributor
tm-jc-nacpil
left a comment
There was a problem hiding this comment.
lgtm! keen to merge it so we can test it out in other repos
Merged
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
This PR fixes the missing corner tiles when using FastSquareGridGenerator and FastBingTileGridGenerator
Results
Describing the issue
In the gridding tutorial there is a discrepancy between the regular and the fast version of both square and Bing tile gridding.
The image below shows the mismatch: there is 1 tile available in BingTileGridGenerator but not in FastBingTileGridGenerator (see green tile)

While a 1 tile mismatch might seem innocuous and coincidental, this points to a deeper issue in general. Usage using other AOIs by @tm-jc-nacpil show that FastBingTileGridGenerator can miss even tiles with a large AOI intersection (see bottom left arrow)

Diagnosis
Upon further inspection, I saw this issue is due to 2 things:
The image below is the same AOI and 1 missing tile (shown in green) in terms of pixel coordinates instead of geographic coordinates. Note that the vertical orientation is flipped in pixel coordinates.

Notice how the 1 missing tile in green has a corner that is tangent to the blue line segment. This points to the underlying issue of
off-boundary pixels. These are pixels whose corners are tangential to an AOI polygon edge. Most importantly, these pixels are candidates for adding back to the main tile set for error correction.You can read more about
off-boundary pixelsin the15_polygon_fill.ipynbnotebook in this PR. Examples ofoff-boundary pixelsin the image below:Resolution
Here are the general steps for the fix:
off-boundary pixels. Several functions in15_polygon_fillare updated to return these.off-boundary pixelsthat intersect linestring of the AOI boundary. The intersections should be done in terms of geographic coordinates, not pixel coordinates. This is implemented in thegenerate_gridmethod in FastSquareGridGenerator and FastBingTileGridGeneratora. Despite this step relying on geometry intersection, the performance hit should be relatively small since we're doing a linestring to polygon intersection (not a polygon to polygon intersection), and the
off-boundary pixelsshould be a small fraction of the total tiles.off-boundary pixelsto the main tile setNote that even after this fix, there still isn't a 100% guarantee of a perfect match between the regular and fast versions of gridding, which I suspect can still happen due to floating point precision errors. But the percent match should have nonetheless improved.