[polygons] Separating out simplify polygon into a method in RTree index

This commit is contained in:
Al
2015-08-13 18:43:32 -04:00
parent 46f2c68a69
commit 9125f07af0
2 changed files with 8 additions and 4 deletions

View File

@@ -105,6 +105,7 @@ class LanguagePolygonIndex(RTreePolygonIndex):
if poly_type == 'Polygon':
poly = Polygon(rec['geometry']['coordinates'][0])
index.index_polygon(i, poly)
poly = self.simplify_polygon(poly)
index.add_polygon(poly, dict(rec['properties']))
elif poly_type == 'MultiPolygon':
polys = []
@@ -113,7 +114,8 @@ class LanguagePolygonIndex(RTreePolygonIndex):
polys.append(poly)
index.index_polygon(i, poly)
index.add_polygon(MultiPolygon(polys), dict(rec['properties']))
multi_poly = self.simplify_polygon(MultiPolygon(polys))
index.add_polygon(multi_poly, dict(rec['properties']))
else:
continue
@@ -127,3 +129,4 @@ class LanguagePolygonIndex(RTreePolygonIndex):
def get_candidate_polygons(self, lat, lon):
candidates = OrderedDict.fromkeys(self.index.intersection((lon, lat, lon, lat))).keys()
return sorted(candidates, key=self.admin_level, reverse=True)