Commit ea175fb2 authored by Danijel Schorlemmer's avatar Danijel Schorlemmer
Browse files

Added the OSM ID of the buildings to the Building table to be included in the exposure data

parent b9bb84e6
Pipeline #21487 passed with stage
in 1 minute and 29 seconds
......@@ -149,7 +149,7 @@ class CoquimboDatabase(Database):
# Create table Building
sql_statement = "CREATE TABLE Building ("
sql_statement += "id INTEGER PRIMARY KEY AUTOINCREMENT, "
sql_statement += "id INTEGER PRIMARY KEY, "
sql_statement += "location_id INTEGER, "
sql_statement += "quadkey TEXT)"
self.connection.execute(sql_statement)
......@@ -247,11 +247,13 @@ class CoquimboDatabase(Database):
)
self.cursor.execute(sql_statement)
def insert_building(self, location_id, quadkey, geom, centroid):
def insert_building(self, osm_id, location_id, quadkey, geom, centroid):
"""
Inserts a dataset to the Building table.
Args:
osm_id (int):
OSM ID of the building
location_id (int):
ID of the location of SARA data this building belongs to
(corresponds to Location.id)
......@@ -267,8 +269,14 @@ class CoquimboDatabase(Database):
"""
sql_statement = "INSERT INTO Building "
sql_statement += "(location_id, quadkey, geom, centroid) "
sql_statement += "VALUES (%d, %s, %s, %s)" % (location_id, quadkey, geom, centroid)
sql_statement += "(id, location_id, quadkey, geom, centroid) "
sql_statement += "VALUES (%d, %d, %s, %s, %s)" % (
osm_id,
location_id,
quadkey,
geom,
centroid,
)
self.cursor.execute(sql_statement)
return self.cursor.lastrowid
......@@ -416,11 +424,17 @@ class CoquimboDatabase(Database):
building_db = Database(buildings_filepath, self.spatialite_filepath)
building_db.create_connection_and_cursor()
sql_statement = "SELECT AsWKT(CastAutomagic(geom)) FROM obm"
sql_statement = "SELECT AsWKT(CastAutomagic(geom)), osm_id, osm_way_id FROM obm"
building_db.cursor.execute(sql_statement)
for building in building_db.cursor:
footprint = wkt.loads(building[0])
centroid = footprint.centroid
if building[1] is not None: # Building has an OSM-relation ID
osm_id = -1 * int(building[1])
elif building[2] is not None:
osm_id = int(building[2]) # Building has an OSM-way ID
else:
osm_id = 0 # Building has no ID, something must be wrong
sql_statement = "SELECT location_id, geom FROM Voronoi WHERE "
sql_statement += "within(GeomFromText('%s', 4326), " % centroid.wkt
sql_statement += "voronoi.geom)"
......@@ -444,7 +458,7 @@ class CoquimboDatabase(Database):
building_geometry = "GeomFromText('%s', 4326)" % footprint
centroid_geometry = "GeomFromText('%s', 4326)" % centroid
building_id = self.insert_building(
location_id, quadkey, building_geometry, centroid_geometry
osm_id, location_id, quadkey, building_geometry, centroid_geometry
)
self.cursor.execute(sql_statement)
logger.debug("Building %d added to location %d" % (building_id, location_id))
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment