From a67efcffe40c4b89f39c4c0ff8722552692c5717 Mon Sep 17 00:00:00 2001 From: Al Date: Wed, 5 Oct 2016 18:16:08 -0400 Subject: [PATCH] [addresses] add new option to use city population to determine whether components should be dropped out --- scripts/geodata/addresses/components.py | 19 ++++++++++++++++++- scripts/geodata/osm/formatter.py | 3 ++- 2 files changed, 20 insertions(+), 2 deletions(-) diff --git a/scripts/geodata/addresses/components.py b/scripts/geodata/addresses/components.py index 2a43f06a..e3019dc8 100644 --- a/scripts/geodata/addresses/components.py +++ b/scripts/geodata/addresses/components.py @@ -1320,7 +1320,8 @@ class AddressComponents(object): return False def expanded(self, address_components, latitude, longitude, language=None, - dropout_places=True, population=None, add_sub_building_components=True, + dropout_places=True, population=None, population_from_city=False, + add_sub_building_components=True, num_floors=None, num_basements=None, zone=None): ''' Expanded components @@ -1377,6 +1378,8 @@ class AddressComponents(object): if city: address_components[AddressFormatter.CITY] = city + + self.add_neighborhoods(address_components, neighborhoods, language_suffix=language_suffix) @@ -1405,6 +1408,20 @@ class AddressComponents(object): num_floors=num_floors, num_basements=num_basements, zone=zone) if dropout_places: + # Population of the city helps us determine if the city can be used + # on its own like "Seattle" or "New York" vs. smaller cities like + # have to be qualified with a state, country, etc. + if population is None and population_from_city: + tagged = self.categorized_osm_components(osm_components) + for props, component in (tagged or []): + if component == AddressFormatter.CITY and 'population' in props: + try: + population = int(props['population']) + except (ValueError, TypeError): + continue + + population = 0 + # Perform dropout on places address_components = place_config.dropout_components(address_components, all_osm_components, country=country, population=population) diff --git a/scripts/geodata/osm/formatter.py b/scripts/geodata/osm/formatter.py index 45c65115..825d4eae 100644 --- a/scripts/geodata/osm/formatter.py +++ b/scripts/geodata/osm/formatter.py @@ -815,7 +815,8 @@ class OSMAddressFormatter(object): address_components, country, language = self.components.expanded(revised_tags, latitude, longitude, language=language or namespaced_language, num_floors=num_floors, num_basements=num_basements, - zone=zone, add_sub_building_components=add_sub_building_components) + zone=zone, add_sub_building_components=add_sub_building_components, + population_from_city=True) if not address_components: return None, None, None