Skip to content

Add grid subdivision / rasterization algorithms - #1232

Merged
dbaston merged 23 commits into
libgeos:mainfrom
dbaston:grid-intersection
Nov 27, 2025
Merged

dbaston merged 23 commits into
libgeos:mainfrom
dbaston:grid-intersection

Conversation

@dbaston

@dbaston dbaston commented Feb 4, 2025

Copy link
Copy Markdown
Member

As discussed in #967, adds functions for:
(1) subdividing a geometry by a rectangular grid
(2) computing the fraction of each cell in a grid that is covered by a polygon

Performance in the included benchmark is 1-3 orders of magnitude faster than repeated calls to Geometry::intersection

image

Code was adapted and pared down from https://github.com/isciences/exactextract

@dbaston dbaston added the Enhancement New feature or feature improvement. label Feb 4, 2025
@dbaston
dbaston marked this pull request as draft February 4, 2025 17:07
@dbaston
dbaston force-pushed the grid-intersection branch from 96f73a4 to 843eb01 Compare July 9, 2025 12:52
@dbaston
dbaston marked this pull request as ready for review July 10, 2025 18:05
@pramsey

pramsey commented Jul 11, 2025

Copy link
Copy Markdown
Member

This looks very exciting, I'm fine w/ the CAPI and not qualified to judge the implementation. The tests look good, maybe see if any of the codecov suggestions for complete coverage are easy to knock off.

@dbaston
dbaston force-pushed the grid-intersection branch 7 times, most recently from c2d9c93 to 26b08ae Compare July 13, 2025 15:25
@dbaston

dbaston commented Jul 16, 2025

Copy link
Copy Markdown
Member Author

Still working through a couple of minor issues with this. I think it could go in the beta, I'm not seeing anything I can't resolve before release.

@dbaston
dbaston force-pushed the grid-intersection branch 2 times, most recently from a19511a to 15a7a71 Compare August 10, 2025 20:06
@dbaston
dbaston force-pushed the grid-intersection branch from 43bcd9b to 37fec59 Compare August 27, 2025 12:59
@dbaston

dbaston commented Aug 27, 2025

Copy link
Copy Markdown
Member Author

Current status: this produces valid polygons in all cases that I've tested, but the polygons do not necessarily form a valid coverage if polygon boundaries follow grid cell boundaries. Here is an example:

image

Subdivided to produce:

image

In this case, some of the fully interior polygons are generated as squares without redundant nodes along their edges. As a result, the polygons do not form a valid coverage. Because the missing nodes may only be on a horizontal or vertical edge, they do not cause an overlap or gap.

@dbaston
dbaston force-pushed the grid-intersection branch from 37fec59 to d48797a Compare August 27, 2025 13:07
@theroggy

Copy link
Copy Markdown
Contributor

In this case, some of the fully interior polygons are generated as squares without redundant nodes along their edges. As a result, the polygons do not form a valid coverage.

Because the missing nodes may only be on a horizontal or vertical edge, they do not cause an overlap or gap.

It isn't really clear to me where the missing nodes are, but this last sentence is an important nuance indeed... because of this overlay operations should not cause slivers,... so at least for my use cases, it not being a valid coverage is not a problem.

@dbaston

dbaston commented Nov 23, 2025

Copy link
Copy Markdown
Member Author

It isn't really clear to me where the missing nodes are,

I mean that polygon "A" should have a node at the location pointed to by the arrow. If it does not have a node at this location there will be no gaps or overlaps between adjacent polygons, but the polygons will still not be considered to form a valid coverage.

image

Either way, I believe all issues in this category have now been addressed.

@dbaston
dbaston merged commit c0b00fc into libgeos:main Nov 27, 2025
26 of 27 checks passed
@dbaston dbaston added this to the 3.15.0 milestone Mar 9, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Enhancement New feature or feature improvement.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants