Skip to content
GitLab
Projects
Groups
Snippets
/
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
Dynamic Exposure
Global Dynamic Exposure
exposure-coquimbo
Commits
54bf8633
Commit
54bf8633
authored
Mar 18, 2021
by
Danijel Schorlemmer
Browse files
Replaced the use of geopandas with Spatialite to read the buildings geopackage file
parent
45515949
Pipeline
#20838
passed with stage
in 1 minute and 19 seconds
Changes
1
Pipelines
2
Hide whitespace changes
Inline
Side-by-side
exposurecoquimbo/database.py
View file @
54bf8633
...
...
@@ -20,10 +20,10 @@
import
logging
import
sqlite3
import
csv
import
geopandas
import
numpy
from
collections
import
namedtuple
from
shapely
import
wkt
from
shapely.affinity
import
translate
from
pygeotile.tile
import
Tile
# Initialize log
...
...
@@ -397,38 +397,35 @@ class CoquimboDatabase(Database):
File path to a geopackage with OpenStreetMap buildings.
"""
buildings
=
geopandas
.
read_file
(
buildings_filepath
)
for
index
,
building
in
buildings
.
iterrows
():
building_db
=
Database
(
buildings_filepath
,
self
.
spatialite_filepath
)
building_db
.
create_connection_and_cursor
()
sql_statement
=
"SELECT AsWKT(CastAutomagic(geom)) FROM obm"
building_db
.
cursor
.
execute
(
sql_statement
)
for
building
in
building_db
.
cursor
:
footprint
=
wkt
.
loads
(
building
[
0
])
centroid
=
footprint
.
centroid
sql_statement
=
"SELECT location_id, geom FROM Voronoi WHERE "
sql_statement
+=
"within(GeomFromText('%s', 4326), "
%
building
.
geometry
.
centroid
sql_statement
+=
"within(GeomFromText('%s', 4326), "
%
centroid
.
wkt
sql_statement
+=
"voronoi.geom)"
self
.
cursor
.
execute
(
sql_statement
)
voronoi
=
self
.
cursor
.
fetchall
()
# TODO: fetchone()
try
:
location_id
=
voronoi
[
0
][
0
]
centroid
=
"POINT(%f %f)"
%
(
building
.
geometry
.
centroid
.
x
,
building
.
geometry
.
centroid
.
y
,
)
except
IndexError
:
location_id
=
self
.
cursor
.
fetchone
()[
0
]
except
TypeError
:
# If centroid lies on a boundary of the Voronoi cells, move the centroid
centroid
=
"POINT(%f %f)"
%
(
building
.
geometry
.
centroid
.
x
+
0.000001
,
building
.
geometry
.
centroid
.
y
+
0.000001
,
)
centroid
=
translate
(
centroid
,
xoff
=
0.000001
,
yoff
=
0.000001
)
sql_statement
=
"SELECT location_id, geom FROM Voronoi WHERE "
sql_statement
+=
"within(GeomFromText('%s', 4326), "
%
centroid
sql_statement
+=
"within(GeomFromText('%s', 4326), "
%
centroid
.
wkt
sql_statement
+=
"voronoi.geom)"
self
.
cursor
.
execute
(
sql_statement
)
voronoi
=
self
.
cursor
.
fetchall
()
# TODO: fetchone()
location_id
=
voronoi
[
0
][
0
]
location_id
=
self
.
cursor
.
fetchone
()[
0
]
quadkey
=
Tile
.
for_latitude_longitude
(
longitude
=
float
(
building
.
geometry
.
centroid
.
x
),
latitude
=
float
(
building
.
geometry
.
centroid
.
y
),
longitude
=
float
(
centroid
.
coords
[
0
][
0
]
),
latitude
=
float
(
centroid
.
coords
[
0
][
1
]
),
zoom
=
18
,
).
quad_tree
building_geometry
=
"GeomFromText('%s', 4326)"
%
building
.
geometry
building_geometry
=
"GeomFromText('%s', 4326)"
%
footprint
centroid_geometry
=
"GeomFromText('%s', 4326)"
%
centroid
building_id
=
self
.
insert_building
(
location_id
,
quadkey
,
building_geometry
,
centroid_geometry
...
...
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