Skip to content
GitLab
Projects
Groups
Snippets
/
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Sign in
Toggle navigation
Menu
Open sidebar
SimStadt
Germany Open-Data CityGML
Commits
bf1f67cd
Commit
bf1f67cd
authored
Oct 30, 2025
by
Eric Duminil
Browse files
Refactor
parent
0a926d4c
Changes
2
Hide whitespace changes
Inline
Side-by-side
02_bayern.py
View file @
bf1f67cd
...
...
@@ -13,13 +13,12 @@ import random
import
xml.etree.ElementTree
as
ET
from
pathlib
import
Path
from
citygml_download
import
CityGMLWithHash
,
download_all_files
,
download_file
from
citygml_download
import
CityGMLWithHash
,
download_all_files
,
download_file
,
SCRIPT_DIR
,
TMP_DIR
SCRIPT_DIR
=
Path
(
__file__
).
resolve
().
parent
BAYERN_METALINK
=
"https://geodaten.bayern.de/odd/a/lod2/citygml/meta/metalink/09.meta4"
def
download_metalink
(
metalink_url
:
str
,
tmp_path
:
Path
)
->
Path
:
def
download_metalink
(
metalink_url
:
str
,
tmp_path
:
Path
=
TMP_DIR
)
->
Path
:
"""Download metalink file to temporary directory."""
print
(
f
"Downloading
{
metalink_url
}
"
)
basename
=
metalink_url
.
split
(
"/"
)[
-
1
]
or
"metalink.xml"
...
...
@@ -65,14 +64,12 @@ def parse_metalink(metalink_path: Path, download_dir: Path) -> list[CityGMLWithH
if
__name__
==
"__main__"
:
# Download and parse metalink
tmp_dir
=
SCRIPT_DIR
/
"tmp"
download_dir
=
SCRIPT_DIR
/
"citygml"
/
"bayern"
tmp_dir
.
mkdir
(
parents
=
True
,
exist_ok
=
True
)
download_dir
.
mkdir
(
parents
=
True
,
exist_ok
=
True
)
metalink_path
=
download_metalink
(
BAYERN_METALINK
,
tmp_dir
)
file
s
=
parse_metalink
(
metalink_path
,
download_dir
)
metalink_path
=
download_metalink
(
BAYERN_METALINK
)
citygml
s
=
parse_metalink
(
metalink_path
,
download_dir
)
# Download all files
download_all_files
(
files
,
tmp_dir
,
sleep
=
5
,
retries
=
1
,
jobs
=
1
)
download_all_files
(
citygmls
)
citygml_download.py
View file @
bf1f67cd
...
...
@@ -17,14 +17,14 @@ from urllib.error import URLError
from
urllib.request
import
urlopen
SCRIPT_DIR
=
Path
(
__file__
).
resolve
().
parent
TMP_DIR
=
SCRIPT_DIR
/
"tmp"
TMP_DIR
.
mkdir
(
parents
=
True
,
exist_ok
=
True
)
def
download_all_files
(
files
:
Sequence
[
"CityGML"
],
tmp_dir
:
Path
=
SCRIPT_DIR
/
"tmp"
,
jobs
:
int
=
3
,
retries
:
int
=
2
,
sleep
:
int
=
5
files
:
Sequence
[
"CityGML"
],
tmp_dir
:
Path
=
TMP_DIR
,
jobs
:
int
=
3
,
retries
:
int
=
2
,
sleep
:
int
=
5
):
"""Download all CityGML files with parallel downloads."""
# Create directories
tmp_dir
.
mkdir
(
parents
=
True
,
exist_ok
=
True
)
print
(
f
"Found
{
len
(
files
)
}
files to download
\n
"
)
...
...
@@ -141,7 +141,7 @@ class CityGML(ABC):
return
self
.
verify
(
self
.
path
)
def
download
(
self
,
tmp_dir
:
Path
,
max_retries
:
int
=
3
,
sleep
:
int
=
0
)
->
bool
:
def
download
(
self
,
tmp_dir
:
Path
=
TMP_DIR
,
max_retries
:
int
=
3
,
sleep
:
int
=
0
)
->
bool
:
"""
Download and verify the file.
...
...
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment