Skip to content

Commit

Permalink
Add H3_Line error handling for bad input geometries (#3)
Browse files Browse the repository at this point in the history
  • Loading branch information
deankieserman authored Feb 24, 2022
1 parent 3df0087 commit 626c71b
Showing 1 changed file with 8 additions and 2 deletions.
10 changes: 8 additions & 2 deletions src/h3_pyspark/indexing.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,10 @@ def _index_line_object(line: LineString, resolution: int):
endpoint_hexes = [h3.geo_to_h3(t[1], t[0], resolution) for t in list(line.coords)]
# Hexes for line (inclusive of endpoints)
for i in range(len(endpoint_hexes) - 1):
result_set.update(h3.h3_line(endpoint_hexes[i], endpoint_hexes[i + 1]))
try:
result_set.update(h3.h3_line(endpoint_hexes[i], endpoint_hexes[i + 1]))
except h3.H3ValueError:
pass
return result_set


Expand All @@ -52,7 +55,10 @@ def _index_polygon_object(polygon: Polygon, resolution: int):
vertex_hexes = [h3.geo_to_h3(t[1], t[0], resolution) for t in list(polygon.exterior.coords)]
# Hexes for edges (inclusive of vertices)
for i in range(len(vertex_hexes) - 1):
result_set.update(h3.h3_line(vertex_hexes[i], vertex_hexes[i + 1]))
try:
result_set.update(h3.h3_line(vertex_hexes[i], vertex_hexes[i + 1]))
except h3.H3ValueError:
pass
# Hexes for internal area
result_set.update(list(h3.polyfill(geometry.mapping(polygon), resolution, geo_json_conformant=True)))
return result_set
Expand Down

0 comments on commit 626c71b

Please sign in to comment.