From 21a2a7419a1815b500c7ff41361ba828c6e778df Mon Sep 17 00:00:00 2001 From: Al Date: Thu, 29 Dec 2016 13:41:05 -0500 Subject: [PATCH] [addresses] only add village as city component if no city can be found in the area --- scripts/geodata/addresses/components.py | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/scripts/geodata/addresses/components.py b/scripts/geodata/addresses/components.py index 7fcbff83..3a77ae1e 100644 --- a/scripts/geodata/addresses/components.py +++ b/scripts/geodata/addresses/components.py @@ -912,6 +912,8 @@ class AddressComponents(object): is_japan = country == JAPAN checked_first_suburb = False + first_village = None + for props, lat, lon, dist in self.places_index.nearest_points(latitude, longitude): component = self.categorize_osm_component(country, props, containing_components) @@ -919,9 +921,14 @@ class AddressComponents(object): have_city = AddressFormatter.CITY in grouped_components - if (component == AddressFormatter.CITY or (component in city_replacements and not have_city)) and component not in grouped_components and (not have_sub_city or not self.osm_component_is_village(props)): + is_village = self.osm_component_is_village(props) + + if (component == AddressFormatter.CITY or (component in city_replacements and not have_city)) and component not in grouped_components and not is_village: grouped_components[component].append(props) + if is_village: + first_village = props + if is_japan and component == AddressFormatter.SUBURB and not checked_first_suburb: existing = grouped_components[component] for p in existing: @@ -935,6 +942,11 @@ class AddressComponents(object): grouped_components[component].append(props) checked_first_suburb = True + have_city = AddressFormatter.CITY in grouped_components + if not have_city and first_village: + grouped_components[AddressFormatter.CITY].append(first_village) + + def add_admin_boundaries(self, address_components, osm_components, country, language,