Skip to content

Commit

Permalink
Merge pull request #257 from joshuacortez/chore/typo_fix
Browse files Browse the repository at this point in the history
Improved markdown describing off-boundary pixels
  • Loading branch information
joshuacortez authored Sep 12, 2024
2 parents fe05ce3 + 438034c commit d84a707
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 7 deletions.
12 changes: 7 additions & 5 deletions notebooks/15_polygon_fill.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -1065,17 +1065,19 @@
"\n",
"Off-boundary pixels are pixels that have at least one corner tangential to an AOI polygon's edge. They are useful for gridding error correction in [FastSquareGridGenerator](https://geowrangler.thinkingmachin.es/grids.html#fastsquaregridgenerator) and [FastBingTileGridGenerator](https://geowrangler.thinkingmachin.es/grids.html#fastbingtilegridgenerator). \n",
"\n",
"Since there are loss in precision errors from translating geographic coordinates to pixel coordinates, the polygon fill algorithm sometimes misses out on pixels tangential to the AOI polygon. To correct this error, we need to add some of the off-boundary pixels.\n",
"When we translate a polygon from geographic coordinates to pixel coordinates, we inevitably have to round the polygon vertex coordinates to the nearest higher or lower integer. For some pixels, this rounding results in one of the pixel corners to be just tangent to the translated polygon boundary. But if it were in the original geographic coordinates, the boundary would have had intersected a portion of the pixel's interior, not just exactly at a corner.\n",
"\n",
"### How is error correction implemented?\n",
"Thus, there will sometimes be pixels that when in geographic coordinates actually intersect the AOI, but when in pixel coordinates are only tangential to the AOI polygon. When we use the fast polygon fill algorithm, it doesn't consider these tangential pixels, also called off-boundary pixels, as part of the filled-in pixel set. So to correct this error, we need to first identify the off-boundary pixels and then select which ones to add to the filled-in pixel set.\n",
"\n",
"We determine which pixels to add to the main pixel set by intersecting the polygon boundary linestring with the off-boundary pixel polygon. Both the linestring and the off-boundary pixel polygon should be in geographic coordinates, not pixel coordinates. The pixels that intersect should be added to the main pixel set. You can find this implementation in the `generate_grid` method under [FastSquareGridGenerator](https://geowrangler.thinkingmachin.es/grids.html#fastsquaregridgenerator) and [FastBingTileGridGenerator](https://geowrangler.thinkingmachin.es/grids.html#fastbingtilegridgenerator)\n",
"### How do we implement error correction?\n",
"\n",
"We determine which pixels to add to the filled-in pixel set by intersecting the polygon boundary linestring with the off-boundary pixel polygon. Both the linestring and the off-boundary pixel polygon should be in geographic coordinates, not pixel coordinates. The pixels that intersect should be added to the filled-in pixel set. You can find this implementation in the `generate_grid` method under [FastSquareGridGenerator](https://geowrangler.thinkingmachin.es/grids.html#fastsquaregridgenerator) and [FastBingTileGridGenerator](https://geowrangler.thinkingmachin.es/grids.html#fastbingtilegridgenerator)\n",
"\n",
"- *Why can't we just add all of the off-boundary pixels?* We can't because not all of the off-boundary pixels actually intersect the polygon when in geographic coordinates. \n",
"\n",
"- *Won't there be a performance slowdown from using a geometric intersection operation?* Despite error correction relying on geometry intersection, the performance slowdown should be minimal since we're doing a linestring to polygon intersection (not a polygon to polygon intersection), and the off-boundary pixels should be a small fraction of the total pixels.\n",
"- *Won't there be an increased computational cost from using a geometry intersection operation?* Yes, this additional step will add compute time but the increase in computational cost should be minimal since we're doing a linestring to polygon intersection (not a polygon to polygon intersection), and the off-boundary pixels should be a small fraction of the total pixels.\n",
"\n",
"- *Why is error correction note implemented in this notebook?* In this particular notebook we're only working with pixel coordinates, so the loss of precision problem isn't a concern and we don't need error correction. It's a concern when you're starting off with geographic coordinates, as used in [FastSquareGridGenerator](https://geowrangler.thinkingmachin.es/grids.html#fastsquaregridgenerator) and [FastBingTileGridGenerator](https://geowrangler.thinkingmachin.es/grids.html#fastbingtilegridgenerator). \n"
"- *Why is error correction not implemented in this notebook?* In this particular notebook we're only working with pixel coordinates, so the translation problem isn't a concern and we don't need error correction. It's a concern when you're starting off with geographic coordinates, as shown in [FastSquareGridGenerator](https://geowrangler.thinkingmachin.es/grids.html#fastsquaregridgenerator) and [FastBingTileGridGenerator](https://geowrangler.thinkingmachin.es/grids.html#fastbingtilegridgenerator). \n"
]
},
{
Expand Down
4 changes: 2 additions & 2 deletions notebooks/tutorial.grids.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -1471,7 +1471,7 @@
"id": "06901bcb-487d-4632-829f-b96e71ba8f8d",
"metadata": {},
"source": [
"We check that `SquareGridGenerator` and `FastSquareGridGenerator` have an exact match in tiles. Since they use different underlying algorithms, it isn't a 100% guarantee that they will always have the exact same match in tiles due to floating point errors, but they should be extremely close most of the time."
"We check that `SquareGridGenerator` and `FastSquareGridGenerator` have an exact match in tiles. Since they use different underlying algorithms, it isn't a 100% guarantee that they will always have the exact same match in tiles due to floating point differences, but they should be extremely close most of the time."
]
},
{
Expand Down Expand Up @@ -2269,7 +2269,7 @@
"id": "550d2c31-881f-4305-99dc-2740cc930a62",
"metadata": {},
"source": [
"We check that `BingTileGridGenerator` and `FastBingTileGridGenerator` have an exact match in tiles. Since they use different underlying algorithms, it isn't a 100% guarantee that they will always have the exact same match in tiles due to floating point errors, but they should be extremely close most of the time."
"We check that `BingTileGridGenerator` and `FastBingTileGridGenerator` have an exact match in tiles. Since they use different underlying algorithms, it isn't a 100% guarantee that they will always have the exact same match in tiles due to floating point differences, but they should be extremely close most of the time."
]
},
{
Expand Down

0 comments on commit d84a707

Please sign in to comment.