diff --git a/resources/boundaries/osm/co.yaml b/resources/boundaries/osm/co.yaml index 81603eae..f5d34be7 100644 --- a/resources/boundaries/osm/co.yaml +++ b/resources/boundaries/osm/co.yaml @@ -1,17 +1,21 @@ --- - admin_level: - "2": "country" - "3": "country_region" - "4": "state" - "5": "state_district" - "6": "city" - "7": "city_district" - "8": "city_district" - "9": "suburb" - - + admin_level: + "2": "country" + "3": "country_region" + "4": "state" + "5": "state_district" + "6": "city" + "7": "city_district" + "8": "city_district" + "9": "suburb" overrides: id: relation: # Bogotá "1387968": "city" + + use_admin_center: + - id: 1387968 # Bogotá + type: relation + # Occasionally use properties/names from the state boundary + probability: 0.8 \ No newline at end of file diff --git a/resources/boundaries/osm/lu.yaml b/resources/boundaries/osm/lu.yaml index 106e88fd..691fa34b 100644 --- a/resources/boundaries/osm/lu.yaml +++ b/resources/boundaries/osm/lu.yaml @@ -1,15 +1,21 @@ --- - admin_level: - "2": "country" - "4": "state" - "5": "state_district" - "6": "state_district" - "8": "city" - "9": "suburb" + admin_level: + "2": "country" + "4": "state" + "5": "state_district" + "6": "state_district" + "8": "city" + "9": "suburb" overrides: contained_by: - relation: - "407489": - admin_level: - "9": "city_district" \ No newline at end of file + relation: + # Luxembourg City + "407489": + admin_level: + "9": "city_district" + + use_admin_center: + - id: 407489 # Luxembourg City + type: relation + probability: 0.6 \ No newline at end of file diff --git a/resources/boundaries/osm/mx.yaml b/resources/boundaries/osm/mx.yaml index eb91c793..786ebbc2 100644 --- a/resources/boundaries/osm/mx.yaml +++ b/resources/boundaries/osm/mx.yaml @@ -1,20 +1,25 @@ --- - admin_level: - "2": "country" - "4": "state" - "6": "state_district" - "8": "city" - "9": "city_district" - "10": "city_district" - + admin_level: + "2": "country" + "4": "state" + "6": "state_district" + "8": "city" + "9": "city_district" + "10": "city_district" overrides: id: relation: + # Mexico City "1376330": "city" contained_by: relation: "1376330": admin_level: - "6": "city_district" \ No newline at end of file + "6": "city_district" + + use_admin_center: + - id: 1376330 # Mexico City + type: relation + probability: 0.6 \ No newline at end of file diff --git a/resources/boundaries/osm/ne.yaml b/resources/boundaries/osm/ne.yaml index 407d233e..aa091539 100644 --- a/resources/boundaries/osm/ne.yaml +++ b/resources/boundaries/osm/ne.yaml @@ -8,4 +8,4 @@ id: relation: # Niamey - "3218804": "city" \ No newline at end of file + "3218804": "city" diff --git a/resources/boundaries/osm/nz.yaml b/resources/boundaries/osm/nz.yaml index 4a99c31e..ef4ba4e1 100644 --- a/resources/boundaries/osm/nz.yaml +++ b/resources/boundaries/osm/nz.yaml @@ -1,8 +1,76 @@ --- - admin_level: - "2": "country" - "4": "state" - "6": "state_district" - "7": "city_district" - "8": "city_district" + admin_level: + "2": "country" + "4": "state" + "6": "state_district" + "8": "city_district" + + overrides: + id: + relation: + # Auckland + "2094141": "city" + # Wellington + "4266321": "city" + # Christchurch + "1640161": "city" + # Hamilton + "2595124": "city" + # Dunedin + "4426790": "city" + # Tauranga + "4266815": "city" + # Lower Hutt + "4266371": "city" + # Palmerston North + "3440209": "city" + # Napier + "2731991": "city" + # Porirua + "4266370": "city" + # Invercargill + "1656388": "city" + # Nelson + "4266962": "city" + # Upper Hutt + "4266375": "city" + + use_admin_center: + - id: 2094141 # Auckland + type: relation + - id: 4266321 # Wellington + type: relation + probability: 0.7 + - id: 1640161 # Christchurch + type: relation + probability: 0.7 + - id: 2595124 # Hamilton + type: relation + probability: 0.7 + - id: 4426790 # Dunedin + type: relation + probability: 0.7 + - id: 4266815 # Tauranga + type: relation + probability: 0.7 + - id: 4266371 # Lower Hutt + type: relation + probability: 0.7 + - id: 3440209 # Palmerston North + type: relation + probability: 0.7 + - id: 2731991 # Napier + type: relation + probability: 0.7 + - id: 4266370 # Porirua + type: relation + probability: 0.7 + - id: 1656388 # Invercargill + type: relation + probability: 0.7 + - id: 4266962 # Nelson + type: relation + - id: 4266375 # Upper Hutt + type: relation + probability: 0.7 diff --git a/resources/boundaries/osm/th.yaml b/resources/boundaries/osm/th.yaml index 8883d9be..c5df9b00 100644 --- a/resources/boundaries/osm/th.yaml +++ b/resources/boundaries/osm/th.yaml @@ -9,10 +9,16 @@ overrides: id: relation: + # Bangkok "92277": "city" contained_by: relation: "92277": admin_level: "6": "city_district" - "8": "suburb" \ No newline at end of file + "8": "suburb" + + use_admin_center: + - id: 92277 # Bangkok + type: relation + probability: 0.85 \ No newline at end of file diff --git a/resources/parser/default.yaml b/resources/parser/default.yaml index 88a6b153..88377717 100644 --- a/resources/parser/default.yaml +++ b/resources/parser/default.yaml @@ -109,12 +109,6 @@ category: boundaries: abbreviate_toponym_probability: 0.35 - # OSM relations should inherit properties from their admin_center - override_with_admin_center: - - id: 92277 # Bangkok, Thailand - type: relation - - id: 1387968 # Bogotá, Colombia - type: relation neighborhood: # Usually in Germany, may have e.g. name:prefix=Ortsteil diff --git a/scripts/geodata/osm/components.py b/scripts/geodata/osm/components.py index b09aaa79..086db0f8 100644 --- a/scripts/geodata/osm/components.py +++ b/scripts/geodata/osm/components.py @@ -8,6 +8,8 @@ from copy import deepcopy from geodata.address_formatting.formatter import AddressFormatter from geodata.configs.utils import recursive_merge +from geodata.encoding import safe_encode + this_dir = os.path.realpath(os.path.dirname(__file__)) OSM_BOUNDARIES_DIR = os.path.join(this_dir, os.pardir, os.pardir, os.pardir, @@ -61,18 +63,23 @@ class OSMAddressComponents(object): def __init__(self, boundaries_dir=OSM_BOUNDARIES_DIR): self.config = {} + self.use_admin_center = {} + for filename in os.listdir(boundaries_dir): if not filename.endswith('.yaml'): continue country_code = filename.rsplit('.yaml', 1)[0] data = yaml.load(open(os.path.join(boundaries_dir, filename))) + for prop, values in six.iteritems(data): for k, v in values.iteritems(): if isinstance(v, six.string_types) and v not in AddressFormatter.address_formatter_fields: raise ValueError(u'Invalid value in {} for prop={}, key={}: {}'.format(filename, prop, k, v)) if prop == 'overrides': + self.use_admin_center.update({(r['type'], safe_encode(r['id'])): r.get('probability', 1.0) for r in values.get('use_admin_center', [])}) + containing_overrides = values.get('contained_by', {}) if not containing_overrides: