[neighborhoods] check polygon boundaries in OSM neighborhood points for a name match at the city level or below

This commit is contained in:
Al
2016-12-18 01:42:34 -05:00
parent a2cf1a35df
commit d357f0f37c

View File

@@ -324,30 +324,28 @@ class NeighborhoodReverseGeocoder(RTreePolygonIndex):
for name_key in OSM_NAME_TAGS:
osm_names.extend([v for k, v in six.iteritems(attrs) if k.startswith('{}:'.format(name_key))])
existing_osm_boundaries = None
existing_osm_boundaries = osm_admin_rtree.point_in_poly(lat, lon, return_all=True)
if component_name and component_name not in (AddressFormatter.SUBURB, AddressFormatter.CITY_DISTRICT):
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 != attrs.get('name'):
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 not in (AddressFormatter.SUBURB, AddressFormatter.CITY_DISTRICT):
skip_node = True
break
# Skip this element
if skip_node:
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
for idx in (cth, qs):
candidates = idx.get_candidate_polygons(lat, lon, return_all=True)