Skip to content

Commit

Permalink
Merge pull request #11 from kevinschaich/rwaldman-patch-1
Browse files Browse the repository at this point in the history
Add edge cases for lines
  • Loading branch information
rwaldman authored Mar 9, 2022
2 parents f8c0407 + b70cd1f commit 1b78172
Showing 1 changed file with 7 additions and 1 deletion.
8 changes: 7 additions & 1 deletion src/h3_pyspark/indexing.py
Original file line number Diff line number Diff line change
Expand Up @@ -47,10 +47,16 @@ def _index_line_object(line: LineString, resolution: int):
)
step = math.degrees(min([h3.exact_edge_length(e, unit="rads") for e in endpoint_hex_edges]))

densified_line = densify(line, step - step * 0.1) # 10% buffer to guarantee we don't miss any hexes
densified_line = densify(line, step)
line_hexes = [h3.geo_to_h3(t[1], t[0], resolution) for t in list(densified_line.coords)]
result_set.update(line_hexes)

neighboring_hexes = set(flatten([h3.k_ring(h, 1) for h in result_set])) - result_set
intersecting_neighboring_hexes = filter(
lambda h: Polygon(h3.h3_set_to_multi_polygon([h], True)[0][0]).distance(line) == 0, neighboring_hexes
)
result_set.update(intersecting_neighboring_hexes)

return result_set


Expand Down

0 comments on commit 1b78172

Please sign in to comment.