-
Notifications
You must be signed in to change notification settings - Fork 473
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
Add additional modes for polygonToCells #775
Comments
One somewhat crude option (but effective and avoids some extra st_ calls) would be the following:
"Your mileage may vary" with this approach, but hopefully it helps |
This approach would work, but caveat emptor:
The alternative I generally use, which is computationally expensive but maybe cheaper than above, but not as memory intensive:
This catches a bunch of cases that buffering and other approaches might not (imagine for example a polygon with a long thin peninsula sticking out, which might miss cells even at R+2 if narrow enough). |
Actually, since the current polyfill algorithm starts by tracing outlines and then iteratively fills the shape toward the center it's possible to adapt the first step (outline calculation) to use another predicate (e.g. intersection vs centroid) and keep the second half of the algo (filling inward) unchanged. At least that's the approach I used in h3o, and so far the results are looking good (example), but I could have missed some corner cases. |
That's basically the plan for the multi-mode option, unless the alternative algorithm I've been considering turns out to be faster (I have a plan for |
Ha interesting! I also started to think about it when I was trying to optimize the polyfill, but didn't get very far. In the end I was able to mitigate the memory usage by streaming the cells as they are generated using iterators (now I can polyfill Russia at resolution 10 using ~100M of RAM only) so it was less of an issue. What was the approach/algorithm you had in mind? |
Taking this as a good excuse to document my thinking here 😁
Some notes here:
|
One advantage(?) of this approach is that we have to implement |
Improvement from @ajfriend - the candidate set can be a single cell! Simpler, and the memory requirement is down to almost nothing:
No need for a flag, if |
Really interesting, thanks for sharing 🙏 I'll try to implement this approach in h3o when I get the bandwidth to do so, curious to see how it perform in practice. One part I'm not sure to understand is this branch:
If a cell at R=1 intersect with the shape, we will explore its children at R=2 |
That's why we have the There's almost certainly a nicer way to write this, but that was the first version I thought of. |
Update on this (sorry, I've taken over this issue as a thread on the new polyfill algo):
On the plus side (relevant to the original ticket) I had to implement |
The additional modes have been implemented in #796 |
TLDR: Allow specification of 'contained', 'intersects', 'covers' for
polygonToCells
.Details:
For my project, I need to be able to convert arbitrary multipolygons to the set of hexes which completely cover the enclosed area.
The current implementation of
polygonToCells
only generates a list of cells whose centroids are located inside of the (multi)polygon.My current workaround is:
edge_length(res)
usingst_buffer
polygonToCells
to generate the list of cell idsst_overlaps
andst_contains
to flag all the cells that cover the original multipolygon.Unfortunately, this is somewhat slow, so I'm looking for a faster way to accomplish this.
(Note that the algorithm described at #608 (comment) won't work if any area of the original polygon is too small/narrow to contain a cell centroid.).
The text was updated successfully, but these errors were encountered: