Skip to content

Commit

Permalink
[FIX] handle USA json country names via conversion of _ to - (#137)
Browse files Browse the repository at this point in the history
* get correct geofabrik URL via conversion of `_` to `-`

another way as initially done via #135 (changes in json files)

* review changes

- remove dublicate key
- save .osm.pbf file with geofabrik name
- move two functions into one
- commonwealth_of_the_northern_mariana_islands still downloads two similar .osm.pbf files
  • Loading branch information
treee111 authored Jun 27, 2022
1 parent 26968e5 commit f235b8c
Show file tree
Hide file tree
Showing 3 changed files with 52 additions and 16 deletions.
30 changes: 30 additions & 0 deletions .vscode/launch.json
Original file line number Diff line number Diff line change
Expand Up @@ -217,6 +217,36 @@
"100",
"-om"
]
},
{
"name": "american_samoa #135",
"type": "python",
"request": "launch",
"module": "wahoomc",
"console": "integratedTerminal",
"args": [
"cli",
"-co",
"american_samoa",
"-c",
"-md",
"100",
]
},
{
"name": "commonwealth_of_the_northern_mariana_islands #135",
"type": "python",
"request": "launch",
"module": "wahoomc",
"console": "integratedTerminal",
"args": [
"cli",
"-co",
"commonwealth_of_the_northern_mariana_islands",
"-c",
"-md",
"100",
]
}
]
}
17 changes: 15 additions & 2 deletions wahoomc/constants.py
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,20 @@
'western_sahara': 'morocco',
'qatar': 'gcc-states',
'åland': 'finland',
'new_mexico': 'new-mexico'
'new_mexico': 'new-mexico',
'american_samoa': 'samoa',
'commonwealth_of_the_northern_mariana_islands': 'american-oceania',
'northern_mariana_islands': 'american-oceania',
'new_york': 'new-york',
'new_hampshire': 'new-hampshire',
'new_jersey': 'new-jersey',
'rhode_island': 'rhode-island',
'district_of_columbia': 'district-of-columbia',
'north_carolina': 'north-carolina',
'south_carolina': 'south-carolina',
'north_dakota': 'north-dakota',
'south_dakota': 'south-dakota',
'west_virginia': 'west-virginia'
}

continents = ['europe', 'unitedstates', 'north-america', 'south-america', 'asia', 'oceania',
Expand Down Expand Up @@ -166,7 +179,7 @@
'pakistan', 'philippines', 'russian federation', 'south-korea', 'sri-lanka', 'syria',
'taiwan', 'tajikistan', 'thailand', 'turkmenistan', 'uzbekistan', 'vietnam', 'yemen']

australiaoceania_geofabrik = ['american oceania', 'australia', 'cook islands', 'fiji',
australiaoceania_geofabrik = ['american-oceania', 'australia', 'cook islands', 'fiji',
'île de clipperton', 'kiribati', 'marshall islands', 'micronesia', 'nauru',
'new caledonia', 'new zealand', 'niue', 'palau', 'papua new guinea',
'pitcairn islands', 'polynesie-francaise', 'samoa', 'solomon islands', 'tokelau',
Expand Down
21 changes: 7 additions & 14 deletions wahoomc/downloader.py
Original file line number Diff line number Diff line change
Expand Up @@ -64,29 +64,22 @@ def download_file(target_filepath, url, is_zip):

def get_osm_pbf_filepath_url(country):
"""
evaluate a countries' OSM file URL and download filepath
build the geofabrik download url to a countries' OSM file and download filepath
"""

# get .osm.pbf region of country
url = build_url_for_country_osm_pbf_download(country)
map_file_path = os.path.join(
USER_MAPS_DIR, f'{country}' + '-latest.osm.pbf')
# return URL and download filepath
return map_file_path, url


def build_url_for_country_osm_pbf_download(country):
"""
build the geofabrik download url to a countries' OSM file
"""
transl_c = const_fct.translate_country_input_to_geofabrik(country)
region = const_fct.get_geofabrik_region_of_country(country)
if region != 'no':
url = 'https://download.geofabrik.de/' + region + \
'/' + transl_c + '-latest.osm.pbf'
else:
url = 'https://download.geofabrik.de/' + transl_c + '-latest.osm.pbf'
return url

map_file_path = os.path.join(
USER_MAPS_DIR, f'{transl_c}' + '-latest.osm.pbf')

# return URL and download filepath
return map_file_path, url


class Downloader:
Expand Down

0 comments on commit f235b8c

Please sign in to comment.