From e5657c56125681e1209e02fea92500e19809f0ad Mon Sep 17 00:00:00 2001 From: Al Date: Sun, 18 Dec 2016 03:00:40 -0500 Subject: [PATCH] [fix] putting the neighborhoods check after the dupe threshold check, as it's not really needed until then anyway --- .../geodata/neighborhoods/reverse_geocode.py | 47 +++++++++---------- 1 file changed, 22 insertions(+), 25 deletions(-) diff --git a/scripts/geodata/neighborhoods/reverse_geocode.py b/scripts/geodata/neighborhoods/reverse_geocode.py index c6092e4f..ee3a5d0b 100644 --- a/scripts/geodata/neighborhoods/reverse_geocode.py +++ b/scripts/geodata/neighborhoods/reverse_geocode.py @@ -366,35 +366,32 @@ class NeighborhoodReverseGeocoder(RTreePolygonIndex): if arg_max: ranks.append(arg_max) - if not ranks: - continue - - existing_osm_boundaries = osm_admin_rtree.point_in_poly(lat, lon, return_all=True) - - skip_node = False - for i, props in enumerate(existing_osm_boundaries): - containing_component = None - name = props.get('name') - # Only exact name matches here since we're comparins OSM to OSM - if name and name.lower() != attrs.get('name', ''.lower()): - continue - - containing_ids = [(boundary['type'], boundary['id']) for boundary in existing_osm_boundaries[i + 1:]] - - containing_component = osm_address_components.component_from_properties(country, props, containing=containing_ids) - - if containing_component and containing_component != component_name and AddressFormatter.component_order[containing_component] <= AddressFormatter.component_order[AddressFormatter.CITY]: - skip_node = True - break - - # Skip this element - if skip_node: - continue - ranks.sort(key=operator.itemgetter(0), reverse=True) if ranks and ranks[0][0] >= cls.DUPE_THRESHOLD: score, props, poly, idx, i = ranks[0] + existing_osm_boundaries = osm_admin_rtree.point_in_poly(lat, lon, return_all=True) + + skip_node = False + for i, props in enumerate(existing_osm_boundaries): + containing_component = None + name = props.get('name') + # Only exact name matches here since we're comparins OSM to OSM + if name and name.lower() != attrs.get('name', ''.lower()): + continue + + containing_ids = [(boundary['type'], boundary['id']) for boundary in existing_osm_boundaries[i + 1:]] + + containing_component = osm_address_components.component_from_properties(country, props, containing=containing_ids) + + if containing_component and containing_component != component_name and AddressFormatter.component_order[containing_component] <= AddressFormatter.component_order[AddressFormatter.CITY]: + skip_node = True + break + + # Skip this element + if skip_node: + continue + containing_ids = [(boundary['type'], boundary['id']) for boundary in existing_osm_boundaries] component = osm_address_components.component_from_properties(country, props, containing=containing_ids) attrs['component'] = component