From 072a838fde562ac12d69b7e6fc9cdf42ef5899b3 Mon Sep 17 00:00:00 2001 From: Al Date: Tue, 14 Feb 2017 02:04:07 -0500 Subject: [PATCH] [neighborhoods] components are now pre-calculated by CTH index --- .../geodata/neighborhoods/reverse_geocode.py | 40 ++++++++++++------- 1 file changed, 25 insertions(+), 15 deletions(-) diff --git a/scripts/geodata/neighborhoods/reverse_geocode.py b/scripts/geodata/neighborhoods/reverse_geocode.py index 01c15c36..fcc7a75e 100644 --- a/scripts/geodata/neighborhoods/reverse_geocode.py +++ b/scripts/geodata/neighborhoods/reverse_geocode.py @@ -430,12 +430,11 @@ class NeighborhoodReverseGeocoder(RTreePolygonIndex): if skip_node: continue - containing_ids = [(boundary['type'], boundary['id']) for boundary in existing_osm_boundaries] - component = osm_address_components.component_from_properties(country, attrs, containing=containing_ids) - attrs['component'] = component - if idx is cth: - attrs['polygon_type'] = 'neighborhood' + if attrs['component'] == AddressFormatter.SUBURB: + attrs['polygon_type'] = 'neighborhood' + else: + attrs['polygon_type'] = 'local_admin' source = 'osm_cth' else: level = props.get(QuattroshapesReverseGeocoder.LEVEL, None) @@ -446,6 +445,10 @@ class NeighborhoodReverseGeocoder(RTreePolygonIndex): else: attrs['polygon_type'] = 'local_admin' + containing_ids = [(boundary['type'], boundary['id']) for boundary in existing_osm_boundaries] + component = osm_address_components.component_from_properties(country, attrs, containing=containing_ids) + attrs['component'] = component + attrs['source'] = source index.index_polygon(poly) index.add_polygon(poly, attrs) @@ -462,19 +465,26 @@ class NeighborhoodReverseGeocoder(RTreePolygonIndex): if idx.matched[i]: continue props['source'] = source - if idx is cth or props.get(QuattroshapesReverseGeocoder.LEVEL, None) == 'neighborhood': + if idx is cth: + component = props['component'] + if component == AddressFormatter.SUBURB: + props['polygon_type'] = 'neighborhood' + elif component == AddressFormatter.CITY_DISTRICT: + props['polygon_type'] = 'local_admin' + else: + continue + elif props.get(QuattroshapesReverseGeocoder.LEVEL, None) == 'neighborhood': component = AddressFormatter.SUBURB - if source == 'quattroshapes': - name = props.get('name') - if not name: - continue - for pattern, repl in cls.regex_replacements: - name = pattern.sub(repl, name) + name = props.get('name') + if not name: + continue + for pattern, repl in cls.regex_replacements: + name = pattern.sub(repl, name) - props['name'] = name + props['name'] = name - if cls.quattroshapes_city_district_regex.match(name): - component = AddressFormatter.CITY_DISTRICT + if cls.quattroshapes_city_district_regex.match(name): + component = AddressFormatter.CITY_DISTRICT props['component'] = component props['polygon_type'] = 'neighborhood'