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
608f73c0
Commit
608f73c0
authored
1 month ago
by
Eric Duminil
Browse files
Options
Download
Email Patches
Plain Diff
Ignore tiles if they are too far away from region
parent
a637a2ad
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
download_files_from_LGL_BW.py
+13
-5
download_files_from_LGL_BW.py
with
13 additions
and
5 deletions
+13
-5
download_files_from_LGL_BW.py
+
13
-
5
View file @
608f73c0
...
...
@@ -25,7 +25,9 @@ import zipfile
from
pyproj
import
CRS
from
pyproj
import
Transformer
import
shapely
from
shapely
import
wkt
from
shapely.ops
import
transform
from
shapely.geometry
import
Point
# TODO: Write tests
# TODO: Use logging
...
...
@@ -49,6 +51,7 @@ EXTRACT_REGIONS = True
CITYGML_SERVER
=
"https://opengeodata.lgl-bw.de/data/lod2"
RASTER
=
2
# [km]
KILOMETER
=
1000
# [m]
BUNDESLAND
=
'bw'
# UTM32N, used in BW. https://epsg.io/32632
...
...
@@ -77,8 +80,8 @@ if EXTRACT_REGIONS:
def
coordinates_to_grid
(
longitude
:
float
,
latitude
:
float
)
->
tuple
[
int
,
int
]:
"""Returns (x, y) of the tile on CITYGML_SERVER containing a given point."""
x
,
y
=
TO_LOCAL_CRS
.
transform
(
longitude
,
latitude
)
x
=
floor
(
x
/
1000
)
-
1
# Odd x
y
=
floor
(
y
/
1000
)
# Even y
x
=
floor
(
x
/
KILOMETER
)
-
1
# Odd x
y
=
floor
(
y
/
KILOMETER
)
# Even y
x
-=
x
%
RASTER
y
-=
y
%
RASTER
return
(
x
+
1
,
y
)
...
...
@@ -106,11 +109,16 @@ def wkt_polygon_to_grid_coords(location_name: str, wkt: str) -> tuple[int, int,
return
(
x1
,
x2
,
y1
,
y2
)
def
download_whole_region
(
output_dir
:
Path
,
wkt
:
str
,
x1
:
int
,
x2
:
int
,
y1
:
int
,
y2
:
int
)
->
None
:
def
download_whole_region
(
output_dir
:
Path
,
wkt
_region
:
str
,
x1
:
int
,
x2
:
int
,
y1
:
int
,
y2
:
int
)
->
None
:
"""Downloads every zip of a given region, to output_dir, and extracts CityGML files."""
# FIXME: Too many uninteresting tiles for complex shapes. Check if the tile is interesecting with the polygon!
wgs84_region
=
wkt
.
loads
(
wkt_region
)
local_region
=
transform
(
TO_LOCAL_CRS
.
transform
,
wgs84_region
)
for
x
in
range
(
x1
,
x2
+
1
,
RASTER
):
for
y
in
range
(
y1
,
y2
+
1
,
RASTER
):
tile_center
=
Point
((
x
+
1
)
*
KILOMETER
,
(
y
+
1
)
*
KILOMETER
)
if
local_region
.
distance
(
tile_center
)
>
RASTER
*
KILOMETER
:
continue
citygml_zip
=
f
"LoD2_
{
UTM
}
_
{
x
}
_
{
y
}
_
{
RASTER
}
_
{
BUNDESLAND
}
.zip"
citygml_url
=
f
"
{
CITYGML_SERVER
}
/
{
citygml_zip
}
"
local_zip
=
output_dir
/
citygml_zip
...
...
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