-
Notifications
You must be signed in to change notification settings - Fork 468
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
Is there a method to validate that a list of hexagon IDs are one contiguous bloc? #718
Comments
It looks to me like this would require something like BFS/DFS or a flood fill algorithm. If you only need contiguity yes/no there are some optimizations that can be made, I think using the localIj algorithms in H3 and iterating through in order. This type of algorithm is not available in the H3 library today. |
Copying my answer from uber/h3-py#291: My suggestion would be:
This is a |
Would this return true (undesirably) if the cells make up two separate blocs? |
... yes 🤦 I guess the easy way to determine this, though it feels a bit computationally expensive for the purpose, would be to use This also allows for holes, so you could disallow any contiguous set with holes if you choose. |
This is how I currently do this, and it is unfortunately a pretty expensive operation :/ I use it because I disallow holes in my use case, and this makes finding them dead simple, but calls to |
This is a graph theory problem. Making sure a set of hexagons are all contiguous should be doable relatively cheaply. Also confirming there are no holes is more complex, though. Without that constraint, we just need to confirm that all hexagons can "reach" some arbitrarily chosen hexagon. I remember reading some biology-inspired algorithm with bacterial culture growth (or something like that) but I can't seem to find it.
I need to think a bit more on how you'd detect holes, but this could at least be a much faster first-pass filter for now for sets that are disconnected that you absolutely should ignore. |
Oh, and that The do-while with the queue makes sure that only cells that have a known path to prior checked cells are the ones that are checked, which is how the contiguous nature is kept. The k-ring of 1 calculation makes more work, but it can be considered a higher constant-time for each tested cell, which is why this should still be an |
I'm looking for a way to validate if a list of cell id's (all same resolution) is a contiguous bloc (single island of hexagons).
My use case is a map-picker where the user selects multiple hexagons but the selection must constitute one contiguous bloc.
My initial thought was to use
h3.are_neighbor_cells
(https://uber.github.io/h3-py/api_reference.html#h3.are_neighbor_cells but then I realised that not every cell has to be neighbours with every other cell to satisfy this contiguous bloc requirement.Is there a method to perform such a check?
The text was updated successfully, but these errors were encountered: