From 19a5541a85c38422ac63c176f715b81b83d6a838 Mon Sep 17 00:00:00 2001 From: Al Date: Sat, 16 Jan 2016 21:20:49 -0500 Subject: [PATCH] [polygons/osm] append polygon nodes by vertices that connect to each other --- scripts/geodata/osm/osm_admin_boundaries.py | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/scripts/geodata/osm/osm_admin_boundaries.py b/scripts/geodata/osm/osm_admin_boundaries.py index 6556e013..df74251d 100644 --- a/scripts/geodata/osm/osm_admin_boundaries.py +++ b/scripts/geodata/osm/osm_admin_boundaries.py @@ -132,9 +132,16 @@ class OSMAdminPolygonReader(object): for component in strongly_connected_components(way_graph): poly_nodes = [] - for way_id in component: + seen = set() + + q = component[:1] + while q: + way_id = q.pop() way_index = way_indices[way_id] poly_nodes.extend(self.node_coordinates(self.way_coords, self.way_indptr, way_index)[:-1]) + neighbors = way_graph[way_id] + q.extend([w for w in neighbors if w not in seen]) + seen.add(way_id) polys.append(poly_nodes)