From a25ae7f9ef1112bbf26e524fc8738d6b050e9bef Mon Sep 17 00:00:00 2001 From: Al Date: Wed, 16 Nov 2016 17:38:01 -0500 Subject: [PATCH] [osm/polygons] adding fixed version of a polygon if polygon is invalid and doesn't contain its centroid --- scripts/geodata/polygons/reverse_geocode.py | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/scripts/geodata/polygons/reverse_geocode.py b/scripts/geodata/polygons/reverse_geocode.py index 6599bd59..a85daafa 100644 --- a/scripts/geodata/polygons/reverse_geocode.py +++ b/scripts/geodata/polygons/reverse_geocode.py @@ -379,6 +379,11 @@ 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