From 82608fbfddbd084ede855eccb3fa2b4dbacabe6a Mon Sep 17 00:00:00 2001 From: User <8444617+pnoll1@users.noreply.github.com> Date: Sat, 7 Sep 2024 23:42:43 +0000 Subject: [PATCH] add script to add iso3166-2 codes to geofabrik index file --- osmand_osm/osm/geofabrik_fix.py | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) create mode 100644 osmand_osm/osm/geofabrik_fix.py diff --git a/osmand_osm/osm/geofabrik_fix.py b/osmand_osm/osm/geofabrik_fix.py new file mode 100644 index 0000000..ec74e4f --- /dev/null +++ b/osmand_osm/osm/geofabrik_fix.py @@ -0,0 +1,19 @@ +import json + +# dict area name to iso +iso_translation = {'baden-wuerttemberg':'de-bw', 'bayern':'de-by', 'berlin':'de-be', 'brandenburg':'de-bb', \ + 'hamburg':'de-hh', 'hessen':'de-he', 'mecklenburg-vorpommern':'de-mv', 'niedersachsen':'de-ni', \ + 'nordrhein-westfalen':'de-nw', 'rheinland-pfalz':'de-rp', 'saarland':'de-sl', 'sachsen':'de-sn', \ + 'sachsen-anhalt':'de-st', 'schleswig-holstein':'de-sh', 'thueringen':'de-th'} +# find area +with open('geofabrik_index-v1.json', 'r+') as index_file: + geofabrik_index = json.load(index_file) + area_list = geofabrik_index['features'] + for area in area_list: + area_name = area['properties']['id'] + for full_name in iso_translation: + if area_name == full_name: + area['properties']['iso3166-2'] = [iso_translation[area_name].upper()] + index_file.seek(0) + index_file.write(json.dumps(geofabrik_index)) + index_file.truncate()