You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
This repository has been archived by the owner on Sep 27, 2023. It is now read-only.
I had this problem where I needed to convert my list of cells back into a counterclockwise path to use in elasticsearch, so I cooked up a function to do exactly that. It definitely does not run the fastest because I only needed it for 6000 items at level 16 cells, which took roughly 3 minutes I think. Your mileage may vary. You will also need to add 1 and 2 to the Cell Union class in source. 3 is a correction to the cell union class "expand" method. 4 is the function that does it, takes as parameters a list of tokens representing your cell union, finds all the islands of the union, and creates a counter clockwise path for each island. I've only tested it for my case using standard lists of level 16 cell tokens. It should work for most other cases but take it with a grain of salt. Modify it as you need :). I went through too much pain for this, I hope this helps someone.
@classmethod
def reverse_flood_fill(cls, region, cell_union, start):
all_nbrs = set()
frontier = []
all_nbrs.add(start)
frontier.append(start)
while len(frontier) != 0:
cell_id = frontier.pop()
if not region.may_intersect(Cell(cell_id)):
continue
yield cell_id
neighbors = cell_id.get_edge_neighbors()
for nbr in neighbors:
if (not cell_union.contains(nbr)) and (nbr not in all_nbrs):
all_nbrs.add(nbr)
frontier.append(nbr)
I had this problem where I needed to convert my list of cells back into a counterclockwise path to use in elasticsearch, so I cooked up a function to do exactly that. It definitely does not run the fastest because I only needed it for 6000 items at level 16 cells, which took roughly 3 minutes I think. Your mileage may vary. You will also need to add 1 and 2 to the Cell Union class in source. 3 is a correction to the cell union class "expand" method. 4 is the function that does it, takes as parameters a list of tokens representing your cell union, finds all the islands of the union, and creates a counter clockwise path for each island. I've only tested it for my case using standard lists of level 16 cell tokens. It should work for most other cases but take it with a grain of salt. Modify it as you need :). I went through too much pain for this, I hope this helps someone.
The text was updated successfully, but these errors were encountered: