-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
add script to add iso3166-2 codes to geofabrik index file
- Loading branch information
Showing
1 changed file
with
19 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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() |