Skip to content
GitLab
Menu
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
a1776570
Commit
a1776570
authored
Jun 19, 2024
by
Eric Duminil
Browse files
Don't stop at first download error
parent
c500031c
Changes
1
Hide whitespace changes
Inline
Side-by-side
download_files_from_LGL_BW.py
View file @
a1776570
...
@@ -17,13 +17,13 @@ from pathlib import Path
...
@@ -17,13 +17,13 @@ from pathlib import Path
from
math
import
floor
from
math
import
floor
import
subprocess
import
subprocess
import
re
import
re
# pip install pyproj
from
pyproj
import
CRS
from
pyproj
import
Transformer
import
urllib.request
import
urllib.request
import
time
import
time
import
zipfile
import
zipfile
from
pyproj
import
CRS
from
pyproj
import
Transformer
###### User input ##########
###### User input ##########
POLYGONS
=
{
POLYGONS
=
{
"StuttgartCenter"
:
"POLYGON((9.175287 48.780916, 9.185501 48.777522, 9.181467 48.773704, 9.174429 48.768472, 9.168807 48.773902, 9.175287 48.780916))"
,
"StuttgartCenter"
:
"POLYGON((9.175287 48.780916, 9.185501 48.777522, 9.181467 48.773704, 9.174429 48.768472, 9.168807 48.773902, 9.175287 48.780916))"
,
...
@@ -101,12 +101,17 @@ def download_rectangle(output_dir: Path, x1: int, x2: int, y1: int, y2: int) ->
...
@@ -101,12 +101,17 @@ def download_rectangle(output_dir: Path, x1: int, x2: int, y1: int, y2: int) ->
print
(
f
"
{
local_zip
.
name
}
already in
{
output_dir
.
name
}
/"
)
print
(
f
"
{
local_zip
.
name
}
already in
{
output_dir
.
name
}
/"
)
else
:
else
:
print
(
f
" Download
{
citygml_zip
}
to
{
output_dir
.
name
}
/ "
,
end
=
''
)
print
(
f
" Download
{
citygml_zip
}
to
{
output_dir
.
name
}
/ "
,
end
=
''
)
urllib
.
request
.
urlretrieve
(
citygml_url
,
local_zip
)
try
:
time
.
sleep
(
WAIT_BETWEEN_DOWNLOADS
)
urllib
.
request
.
urlretrieve
(
citygml_url
,
local_zip
)
print
(
"✓"
)
except
urllib
.
error
.
HTTPError
as
e
:
print
(
f
"❌
{
e
}
"
)
continue
finally
:
time
.
sleep
(
WAIT_BETWEEN_DOWNLOADS
)
print
(
"✅"
)
print
(
f
" Extract
{
citygml_zip
}
to
{
output_dir
.
name
}
/ "
,
end
=
''
)
print
(
f
" Extract
{
citygml_zip
}
to
{
output_dir
.
name
}
/ "
,
end
=
''
)
print
(
"
✓
"
)
print
(
"
✅
"
)
print
(
""
)
print
(
""
)
with
zipfile
.
ZipFile
(
local_zip
,
"r"
)
as
zip_ref
:
with
zipfile
.
ZipFile
(
local_zip
,
"r"
)
as
zip_ref
:
zip_ref
.
extractall
(
output_dir
)
zip_ref
.
extractall
(
output_dir
)
...
@@ -118,9 +123,12 @@ def extract_region(output_dir: Path, location_name: str, wkt: str) -> None:
...
@@ -118,9 +123,12 @@ def extract_region(output_dir: Path, location_name: str, wkt: str) -> None:
if
output_file
.
exists
():
if
output_file
.
exists
():
print
(
f
"
{
output_file
}
already exists. Not extracting."
)
print
(
f
"
{
output_file
}
already exists. Not extracting."
)
return
return
print
(
f
" Extracting
{
output_file
}
."
)
region_chooser_libs
=
Path
(
SIMSTADT_FOLDER
).
expanduser
()
/
'lib/*'
region_chooser_libs
=
Path
(
SIMSTADT_FOLDER
).
expanduser
()
/
'lib/*'
gml_inputs
=
output_dir
.
glob
(
GML_GLOB
)
gml_inputs
=
list
(
output_dir
.
glob
(
GML_GLOB
))
if
len
(
gml_inputs
)
==
0
:
print
(
"Error: No CityGML found. At least part of the region should be in Baden-Württemberg!"
)
return
print
(
f
" Extracting
{
output_file
}
."
)
result
=
subprocess
.
run
([
'java'
,
'-classpath'
,
f
'
{
region_chooser_libs
}
'
,
result
=
subprocess
.
run
([
'java'
,
'-classpath'
,
f
'
{
region_chooser_libs
}
'
,
'eu.simstadt.regionchooser.RegionChooserCLI'
,
'eu.simstadt.regionchooser.RegionChooserCLI'
,
'--input'
,
','
.
join
(
str
(
gml
)
for
gml
in
gml_inputs
),
'--input'
,
','
.
join
(
str
(
gml
)
for
gml
in
gml_inputs
),
...
@@ -129,7 +137,8 @@ def extract_region(output_dir: Path, location_name: str, wkt: str) -> None:
...
@@ -129,7 +137,8 @@ def extract_region(output_dir: Path, location_name: str, wkt: str) -> None:
],
],
input
=
wkt
,
input
=
wkt
,
text
=
True
,
text
=
True
,
capture_output
=
True
capture_output
=
True
,
check
=
True
)
)
if
(
result
.
stderr
):
if
(
result
.
stderr
):
print
(
result
.
stderr
)
print
(
result
.
stderr
)
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a 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