From 1fe3c9b79b6e35c24fcce426db8e87c68d437b17 Mon Sep 17 00:00:00 2001 From: Al Date: Wed, 15 Jul 2015 14:33:49 -0400 Subject: [PATCH] [polygons] Adding a return_all version of point_in_poly e.g. for regions like Navarra where we want to add a non-default Basque dictionary but still retain Spanish as the default from the national polygon --- scripts/geodata/polygons/index.py | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/scripts/geodata/polygons/index.py b/scripts/geodata/polygons/index.py index 52602193..9dd85cb4 100644 --- a/scripts/geodata/polygons/index.py +++ b/scripts/geodata/polygons/index.py @@ -128,11 +128,17 @@ class RTreePolygonIndex(object): def get_candidate_polygons(self, lat, lon): return OrderedDict.fromkeys(self.index.intersection((lon, lat, lon, lat))).keys() - def point_in_poly(self, lat, lon): + def point_in_poly(self, lat, lon, return_all=False): polys = self.get_candidate_polygons(lat, lon) pt = Point(lon, lat) + containing = None + if return_all: + containing = [] for i in polys: props, poly = self.polygons[i] - if poly.contains(pt): + contains = poly.contains(pt) + if contains and not return_all: return props - return None \ No newline at end of file + elif contains: + containing.append(props) + return containing