Refactor handling of positions in OpenData works

This commit is contained in:
Lucas Verney 2018-11-25 12:52:51 +01:00
parent 85031a5462
commit fc2f349eb6
1 changed files with 5 additions and 22 deletions

View File

@ -600,33 +600,16 @@ def process_opendata(name, data, report_type=REPORT_TYPE):
else: else:
geo_shape = shape(item['geometry']) geo_shape = shape(item['geometry'])
if isinstance(geo_shape, Point): if isinstance(geo_shape, MultiPolygon):
# Single point for the item, add a report on it # Split multipolygons into multiple polygons
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?
positions = [ positions = [
p.centroid p.centroid
for p in geo_shape for p in geo_shape
] ]
else: else:
logging.warning( positions = [
'Unsupported geometry for record %s: %s.', geo_shape.centroid
(item['recordid'], geo_shape) ]
)
continue
for position in positions: for position in positions:
# Check if this precise position is already in the database # Check if this precise position is already in the database