Skip to content

Commit b7bce84

Browse files
authored
ensure linestrings have enough points (#4)
1 parent b041b19 commit b7bce84

File tree

1 file changed

+11
-1
lines changed

1 file changed

+11
-1
lines changed

changegen/generator.py

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -284,6 +284,12 @@ def _modify_existing_way(way_geom, way_id, nodes, tags, intersection_db):
284284
]
285285

286286
for n in add_nodes:
287+
288+
# ensure at least 2 nodes in linestring
289+
if len(way_geom_pts) < 2:
290+
logging.warning("Malformed linestring found.")
291+
continue
292+
287293
_g = sg.LineString(way_geom_pts)
288294
idx = _get_point_insertion_index(_g, sg.Point(n.lon, n.lat))
289295
ip_x, ip_y = way_geom_pts[idx]
@@ -374,7 +380,11 @@ def _generate_ways_and_nodes(
374380
]
375381

376382
for n in add_nodes:
377-
_tmp_ls = sg.LineString([(_n.lon, _n.lat) for _n in nodes])
383+
ls_points = [(_n.lon, _n.lat) for _n in nodes]
384+
if len(ls_points) < 2:
385+
logging.warning("Malformed linestring found.")
386+
continue # skip linestrings that are not linestrings
387+
_tmp_ls = sg.LineString(ls_points)
378388
idx = _get_point_insertion_index(_tmp_ls, sg.Point(n.lon, n.lat))
379389
ip_x, ip_y = list(_tmp_ls.coords)[idx]
380390
# there's a special case here where the intersection point already exists

0 commit comments

Comments
 (0)