From fc2f349eb6dd4cf3941d82f2003fa368b4578b46 Mon Sep 17 00:00:00 2001 From: "Phyks (Lucas Verney)" Date: Sun, 25 Nov 2018 12:52:51 +0100 Subject: [PATCH] Refactor handling of positions in OpenData works --- scripts/opendata/works.py | 27 +++++---------------------- 1 file changed, 5 insertions(+), 22 deletions(-) diff --git a/scripts/opendata/works.py b/scripts/opendata/works.py index a7916f1..ae44a63 100755 --- a/scripts/opendata/works.py +++ b/scripts/opendata/works.py @@ -600,33 +600,16 @@ def process_opendata(name, data, report_type=REPORT_TYPE): else: geo_shape = shape(item['geometry']) - if isinstance(geo_shape, Point): - # Single point for the item, add a report on it - positions = [geo_shape] - elif isinstance(geo_shape, LineString): - # LineString (e.g. along a way), add a report at each end - # TODO: More positions, put a report at each intersection? - positions = [ - Point(geo_shape.coords[0]), - Point(geo_shape.coords[-1]) - ] - elif isinstance(geo_shape, Polygon): - # TODO: Finer position, put a report at intersections? - positions = [ - geo_shape.centroid, - ] - elif isinstance(geo_shape, MultiPolygon): - # TODO: Finer position, put a report at intersections? + if isinstance(geo_shape, MultiPolygon): + # Split multipolygons into multiple polygons positions = [ p.centroid for p in geo_shape ] else: - logging.warning( - 'Unsupported geometry for record %s: %s.', - (item['recordid'], geo_shape) - ) - continue + positions = [ + geo_shape.centroid + ] for position in positions: # Check if this precise position is already in the database