Skip to content

Commit 467386a

Browse files
authored
Merge pull request #19 from AnastKap:feature/dynamic-eubucco-links
Feat: Dynamically load country links from EUBUCCO
2 parents 4e2b525 + 9a22059 commit 467386a

1 file changed

Lines changed: 29 additions & 33 deletions

File tree

src/voxcity/downloader/eubucco.py

Lines changed: 29 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -41,39 +41,31 @@
4141

4242
from ..geoprocessor.utils import get_country_name
4343

44+
EUBUCCO_BASE_URL = "https://api.eubucco.com/v0.1"
45+
4446
# Dictionary mapping European countries to their EUBUCCO data download URLs
45-
country_links = {
46-
"Austria": "https://api.eubucco.com/v0.1/files/5e63fc15-b602-474b-a618-43080fa49db4/download",
47-
"Belgium": "https://api.eubucco.com/v0.1/files/08b81844-f46d-403b-bbd0-871fc5017b62/download",
48-
"Bulgaria": "https://api.eubucco.com/v0.1/files/4d0c2559-a3ec-4aea-bd56-e87d0261f5e5/download",
49-
"Croatia": "https://api.eubucco.com/v0.1/files/3638edd8-85af-4244-8208-128eedc85dcf/download",
50-
"Cyprus": "https://api.eubucco.com/v0.1/files/bee810d8-d4eb-4ddc-abf9-86d5247e05cf/download",
51-
"Czechia": "https://api.eubucco.com/v0.1/files/a130fd04-5d8c-4ea5-8383-62019cbec87f/download",
52-
"Czechia Other-license": "https://api.eubucco.com/v0.1/files/d044e347-7106-4516-811e-b340deac2041/download",
53-
"Denmark": "https://api.eubucco.com/v0.1/files/dc11a549-15db-4855-876d-ff3dfc401f76/download",
54-
"Estonia": "https://api.eubucco.com/v0.1/files/021d17ba-49a1-42e6-ae0b-fe73e8f02efb/download",
55-
"Finland": "https://api.eubucco.com/v0.1/files/c3131458-d835-4a22-8203-7d6367ae6f8f/download",
56-
"France": "https://api.eubucco.com/v0.1/files/0602abfe-d522-4683-a792-4dc4143a23fa/download",
57-
"Germany": "https://api.eubucco.com/v0.1/files/90148cbc-5bb1-4d1c-9935-8572a2a8c609/download",
58-
"Greece": "https://api.eubucco.com/v0.1/files/8d43e4c4-9e03-4ef1-b8c3-7bbb2ac23f4a/download",
59-
"Hungary": "https://api.eubucco.com/v0.1/files/bc0f8941-1b68-4c1c-9219-424c0d56d55a/download",
60-
"Ireland": "https://api.eubucco.com/v0.1/files/f580d806-9b32-4d1c-93ef-a4ff49889d56/download",
61-
"Italy": "https://api.eubucco.com/v0.1/files/e987077e-5c72-4903-a0d8-20ef8b9016de/download",
62-
"Italy Other-license": "https://api.eubucco.com/v0.1/files/d5a8e03f-0397-4f89-bcdd-a4bc61352ef6/download",
63-
"Latvia": "https://api.eubucco.com/v0.1/files/b7b3efdc-c9e1-4b70-bc81-2c4291cbdf8e/download",
64-
"Lithuania": "https://api.eubucco.com/v0.1/files/28862c49-25fe-4019-8c6b-cbad18d1c090/download",
65-
"Luxembourg": "https://api.eubucco.com/v0.1/files/0045dd6d-a2e0-4439-91c4-722856682cd6/download",
66-
"Malta": "https://api.eubucco.com/v0.1/files/2b4ecf81-365e-4a9b-91f6-70838c52487d/download",
67-
"Netherlands": "https://api.eubucco.com/v0.1/files/9f95ccbc-a095-4495-916c-6ea932f3ae10/download",
68-
"Poland": "https://api.eubucco.com/v0.1/files/6e8ea7fc-afcb-42b9-adbe-e12fa24048a7/download",
69-
"Portugal": "https://api.eubucco.com/v0.1/files/5d079772-5dd5-4dfc-95d2-393ca8edaa68/download",
70-
"Romania": "https://api.eubucco.com/v0.1/files/41cb29ed-e778-4b5b-807e-917ac93d48ca/download",
71-
"Slovakia": "https://api.eubucco.com/v0.1/files/17f71454-e4c4-41e8-b3ee-20b957abf546/download",
72-
"Slovenia": "https://api.eubucco.com/v0.1/files/e120065e-d6c2-42c6-b136-588072954e51/download",
73-
"Spain": "https://api.eubucco.com/v0.1/files/34dd019b-871f-443e-9b5d-61c29f8cb92c/download",
74-
"Sweden": "https://api.eubucco.com/v0.1/files/46fb09cc-38a9-46c0-bce2-d159e4b62963/download",
75-
"Switzerland": "https://api.eubucco.com/v0.1/files/1f4b7797-6e1e-44ab-a281-95d575360c9a/download",
76-
}
47+
country_links = {}
48+
49+
50+
def populate_country_links():
51+
global country_links
52+
53+
# Populate the coutry_links variable
54+
response = requests.get(f"{EUBUCCO_BASE_URL}/countries")
55+
if response.status_code != 200:
56+
msg = f"Failed get the country-url lookup. Status code: {response.status_code}"
57+
logging.error(msg)
58+
raise Exception(msg)
59+
60+
61+
data = response.json()
62+
country_links = {country_data["name"]: country_data["gpkg"]["download_link"]
63+
for country_data in data}
64+
65+
66+
# Get the country links when the current module is being imported
67+
populate_country_links()
68+
7769

7870
# ================================
7971
# Configuration
@@ -378,7 +370,11 @@ def load_gdf_from_eubucco(rectangle_vertices, output_dir):
378370
file_name = 'building.geojson'
379371
file_path = f"{output_dir}/{file_name}"
380372

373+
374+
# Refresh the coutry links
375+
populate_country_links()
376+
381377
# Download and save GeoJSON
382378
gdf = get_gdf_from_eubucco(rectangle_vertices, country_links, output_dir, file_name)
383379

384-
return gdf
380+
return gdf

0 commit comments

Comments
 (0)