Skip to content
GitLab
Explore
Projects
Groups
Snippets
Projects
Groups
Snippets
/
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Sign in
Toggle navigation
Menu
Open sidebar
Eric Duminil
Get Baden-Württemberg CityGML Opendata
Commits
e2db986b
Commit
e2db986b
authored
1 month ago
by
Eric Duminil
Browse files
Options
Download
Email Patches
Plain Diff
formatting
parent
302428e1
master
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
download_files_from_LGL_BW.py
+11
-12
download_files_from_LGL_BW.py
with
11 additions
and
12 deletions
+11
-12
download_files_from_LGL_BW.py
+
11
-
12
View file @
e2db986b
...
...
@@ -69,7 +69,7 @@ def find_simstadt_folder():
"""Find SimStadt installation on desktop"""
try
:
simstadt_folder
=
next
(
x
for
x
in
Path
.
home
().
glob
(
'Desktop/SimStadt*_0.*/'
)
if
x
.
is_dir
())
logger
.
info
(
f
"RegionChooser has been found in
{
simstadt_folder
}
"
)
logger
.
info
(
"RegionChooser has been found in
%s"
,
simstadt_folder
)
return
simstadt_folder
except
StopIteration
:
return
None
...
...
@@ -98,8 +98,8 @@ def wkt_polygon_to_grid_coords(location_name: str, wkt_str: str) -> tuple[int, i
min_lon
,
max_lon
=
min
(
lons
),
max
(
lons
)
min_lat
,
max_lat
=
min
(
lats
),
max
(
lats
)
logger
.
info
(
"%s (%.3f°N %.3f°E -> %.3f°N %.3f°E)"
%
(
location_name
,
max_lat
,
min_lon
,
min_lat
,
max_lon
)
)
logger
.
info
(
"%s (%.3f°N %.3f°E -> %.3f°N %.3f°E)"
,
location_name
,
max_lat
,
min_lon
,
min_lat
,
max_lon
)
x1
,
y1
=
coordinates_to_grid
(
min_lon
,
min_lat
)
x2
,
y2
=
coordinates_to_grid
(
max_lon
,
max_lat
)
...
...
@@ -122,19 +122,19 @@ def download_whole_region(output_dir: Path, wkt_region: str, x1: int, x2: int, y
citygml_url
=
f
"
{
CITYGML_SERVER
}
/
{
citygml_zip
}
"
local_zip
=
output_dir
/
citygml_zip
if
local_zip
.
exists
():
logger
.
info
(
f
"
{
local_zip
.
name
}
already in
{
output_dir
.
name
}
/"
)
logger
.
info
(
"
%s already in %s/"
,
local_zip
.
name
,
output_dir
.
name
)
else
:
logger
.
info
(
f
" Download
{
citygml_zip
}
to
{
output_dir
.
name
}
/ "
)
logger
.
info
(
" Download
%s to %s/"
,
citygml_zip
,
output_dir
.
name
)
try
:
urllib
.
request
.
urlretrieve
(
citygml_url
,
local_zip
)
logger
.
info
(
"✅ Download successful"
)
except
urllib
.
error
.
HTTPError
as
e
:
logger
.
error
(
f
"❌
{
e
}
"
)
logger
.
error
(
"❌
%s"
,
e
)
continue
finally
:
time
.
sleep
(
WAIT_BETWEEN_DOWNLOADS
)
logger
.
info
(
f
" Extract
{
citygml_zip
}
to
{
output_dir
.
name
}
/ "
)
logger
.
info
(
" Extract
%s to %s/"
,
citygml_zip
,
output_dir
.
name
)
with
zipfile
.
ZipFile
(
local_zip
,
"r"
)
as
zip_ref
:
zip_ref
.
extractall
(
output_dir
)
logger
.
info
(
"✅ Extraction successful"
)
...
...
@@ -144,7 +144,7 @@ def extract_region(output_dir: Path, location_name: str, wkt_str: str, simstadt_
"""Uses RegionChooser to extract a given region from all the CityGML files found in subfolder."""
output_file
=
output_dir
/
(
location_name
+
'.gml'
)
if
output_file
.
exists
():
logger
.
info
(
f
"
{
output_file
}
already exists. Not extracting."
)
logger
.
info
(
"
%s
already exists. Not extracting."
,
output_file
)
return
region_chooser_libs
=
simstadt_folder
/
'lib/*'
...
...
@@ -159,7 +159,7 @@ def extract_region(output_dir: Path, location_name: str, wkt_str: str, simstadt_
local_wkt
=
convert_wkt_to_local
(
wkt_str
)
logger
.
info
(
f
" Extracting
{
output_file
}
."
)
logger
.
info
(
" Extracting
%s."
,
output_file
)
with
open
(
wkt_path
,
'w'
)
as
f
:
f
.
write
(
local_wkt
)
...
...
@@ -182,7 +182,7 @@ def extract_region(output_dir: Path, location_name: str, wkt_str: str, simstadt_
check
=
False
)
if
result
.
stderr
:
logger
.
error
(
result
.
stderr
)
logger
.
error
(
"%s"
,
result
.
stderr
)
if
result
.
returncode
!=
0
:
raise
ValueError
(
f
"RegionChooser failed with code
{
result
.
returncode
}
"
)
logger
.
info
(
" DONE!"
)
...
...
@@ -273,10 +273,9 @@ def main(location_name: str, wkt_or_zipcode: str, download_only: bool = False, s
else
:
logger
.
info
(
"Download-only mode: Skipping region extraction."
)
logger
.
info
(
f
"Processing of
{
location_name
}
complete!"
)
logger
.
info
(
"Processing of
%s complete!"
,
location_name
)
if
__name__
==
'__main__'
:
args
=
parse_arguments
()
main
(
args
.
name
,
args
.
region
,
args
.
download_only
,
args
.
simstadt_folder
)
This diff is collapsed.
Click to expand it.
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
Menu
Explore
Projects
Groups
Snippets