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
fe513353
Commit
fe513353
authored
6 months ago
by
Eric Duminil
Browse files
Options
Download
Email Patches
Plain Diff
Allow to specify ZipCodes too
parent
b2b2b958
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
download_files_from_LGL_BW.py
+21
-4
download_files_from_LGL_BW.py
with
21 additions
and
4 deletions
+21
-4
download_files_from_LGL_BW.py
+
21
-
4
View file @
fe513353
...
@@ -25,10 +25,13 @@ import zipfile
...
@@ -25,10 +25,13 @@ import zipfile
from
pyproj
import
CRS
from
pyproj
import
CRS
from
pyproj
import
Transformer
from
pyproj
import
Transformer
from
get_coordinates_by_zipcode
import
get_coordinates_by_zipcode
COORDINATES_REGEX
=
re
.
compile
(
r
"(\-?\d+\.\d*) (\-?\d+\.\d*)"
)
COORDINATES_REGEX
=
re
.
compile
(
r
"(\-?\d+\.\d*) (\-?\d+\.\d*)"
)
###### User input ##########
###### User input ##########
POLYGONS
=
{
# Values can be either a WKT POLYGON or MULTIPOLYGON, a Zipcode, or Zipcodes separated by a comma.
REGIONS
=
{
"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))"
,
# "AnotherRegion": "Another WKT Polygon...",
# "AnotherRegion": "Another WKT Polygon...",
}
}
...
@@ -168,13 +171,27 @@ def extract_region(output_dir: Path, location_name: str, wkt: str) -> None:
...
@@ -168,13 +171,27 @@ def extract_region(output_dir: Path, location_name: str, wkt: str) -> None:
print
(
" DONE!"
)
print
(
" DONE!"
)
def
main
(
polygons
:
dict
[
str
,
str
])
->
None
:
def
get_wkt
(
wkt_or_zipcode
:
str
)
->
str
:
"""Returns WKT string for a given region, either specified as a POLYGON, or Zipcode(s).
"POLYGON((...))"
"MULTIPOLYGON(((...)))"
"70567"
"70567,70569"
"""
if
'POLYGON'
in
wkt_or_zipcode
:
return
wkt_or_zipcode
else
:
return
get_coordinates_by_zipcode
(
wkt_or_zipcode
.
split
(
','
))
# raise ValueError(f"Unknown region format: {wkt_or_zipcode}")
def
main
(
regions
:
dict
[
str
,
str
])
->
None
:
"""Downloads ZIP files, extracts CityGML files, and selects desired region."""
"""Downloads ZIP files, extracts CityGML files, and selects desired region."""
for
location_name
,
wkt
in
polyg
ons
.
items
():
for
location_name
,
wkt
_or_zipcode
in
regi
ons
.
items
():
if
' '
in
location_name
:
if
' '
in
location_name
:
raise
ValueError
(
"Location name should not contain spaces: 'Some City' -> 'SomeCity'"
)
raise
ValueError
(
"Location name should not contain spaces: 'Some City' -> 'SomeCity'"
)
output_dir
=
SCRIPT_DIR
/
(
location_name
+
'.proj'
)
output_dir
=
SCRIPT_DIR
/
(
location_name
+
'.proj'
)
output_dir
.
mkdir
(
parents
=
True
,
exist_ok
=
True
)
output_dir
.
mkdir
(
parents
=
True
,
exist_ok
=
True
)
wkt
=
get_wkt
(
wkt_or_zipcode
)
x1
,
x2
,
y1
,
y2
=
wkt_polygon_to_grid_coords
(
location_name
,
wkt
)
x1
,
x2
,
y1
,
y2
=
wkt_polygon_to_grid_coords
(
location_name
,
wkt
)
download_rectangle
(
output_dir
,
x1
,
x2
,
y1
,
y2
)
download_rectangle
(
output_dir
,
x1
,
x2
,
y1
,
y2
)
if
EXTRACT_REGIONS
:
if
EXTRACT_REGIONS
:
...
@@ -193,4 +210,4 @@ def convert_wkt_to_local(wkt):
...
@@ -193,4 +210,4 @@ def convert_wkt_to_local(wkt):
if
__name__
==
'__main__'
:
if
__name__
==
'__main__'
:
main
(
POLYG
ONS
)
main
(
REGI
ONS
)
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