From c1d4b03bb49a2b1bc251b5334eac762f5ef7e7e2 Mon Sep 17 00:00:00 2001 From: Al Date: Wed, 16 Nov 2016 23:25:48 -0500 Subject: [PATCH] [polygons] moving polygon fixes to the to_polygon method so they get applied both at ingestion and on cache load --- scripts/geodata/polygons/index.py | 5 +++++ scripts/geodata/polygons/reverse_geocode.py | 5 ----- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/scripts/geodata/polygons/index.py b/scripts/geodata/polygons/index.py index 702643d1..d28e2a03 100644 --- a/scripts/geodata/polygons/index.py +++ b/scripts/geodata/polygons/index.py @@ -167,6 +167,11 @@ class PolygonIndex(object): holes = [(lon + 360.0 if lon < 0 else lon, lat) for lon, lat in holes] poly = Polygon(coords, holes) + if not poly.is_valid and not poly.contains(poly.centroid): + poly_fix = cls.fix_polygon(poly) + if poly_fix is not None and poly_fix.bounds and len(poly_fix.bounds) == 4 and poly_fix.is_valid and (poly_fix.contains(poly.centroid) or poly_fix.contains(poly_fix.representative_point())): + poly = poly_fix + return poly def add_geojson_like_record(self, rec, include_only_properties=None): diff --git a/scripts/geodata/polygons/reverse_geocode.py b/scripts/geodata/polygons/reverse_geocode.py index a85daafa..6599bd59 100644 --- a/scripts/geodata/polygons/reverse_geocode.py +++ b/scripts/geodata/polygons/reverse_geocode.py @@ -379,11 +379,6 @@ class OSMReverseGeocoder(RTreePolygonIndex): if poly is None or not poly.bounds or len(poly.bounds) != 4: continue - if not poly.is_valid and not poly.contains(poly.centroid): - poly_fix = cls.fix_polygon(poly) - if poly_fix is not None and poly_fix.bounds and len(poly_fix.bounds) == 4 and poly_fix.is_valid and (poly_fix.contains(poly.centroid) or poly_fix.contains(poly_fix.representative_point())): - poly = poly_fix - interior = [] try: # Figure out which outer polygon contains each inner polygon