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

Implemented the suggested schema for BuildingAsset and TileAsset

parent 0acbde6c
Pipeline #40837 passed with stage
in 1 minute and 24 seconds
......@@ -129,38 +129,43 @@ class ExposureDatabase(SpatialiteDatabase):
# Create table BuildingAsset
sql_statement = "CREATE TABLE BuildingAsset ("
sql_statement += "id TEXT, "
sql_statement += "id INTEGER PRIMARY KEY AUTOINCREMENT, "
sql_statement += "quadkey TEXT, "
sql_statement += "taxonomy_id INTEGER, "
sql_statement += "number REAL, "
sql_statement += "structural REAL, "
sql_statement += "night REAL, "
sql_statement += "occupancy TEXT, "
sql_statement += "district_id TEXT, "
sql_statement += "district_id INTEGER, "
sql_statement += "building_id INTEGER)"
self.connection.execute(sql_statement)
logger.debug("Table BuildingAsset created")
# Create table TileAsset
sql_statement = "CREATE TABLE TileAsset ("
sql_statement += "id TEXT, "
sql_statement += "id INTEGER PRIMARY KEY AUTOINCREMENT, "
sql_statement += "quadkey TEXT, "
sql_statement += "taxonomy_id INTEGER, "
sql_statement += "number REAL, "
sql_statement += "structural REAL, "
sql_statement += "night REAL, "
sql_statement += "occupancy TEXT, "
sql_statement += "district_id TEXT, "
sql_statement += "quadkey TEXT)"
sql_statement += "district_id INTEGER)"
self.connection.execute(sql_statement)
logger.debug("Table TileAsset created")
# Create table Building
sql_statement = "CREATE TABLE Building ("
sql_statement += "id INTEGER, "
sql_statement += "quadkey TEXT)"
sql_statement += "id INTEGER, "
sql_statement += "quadkey TEXT, "
sql_statement += "occupancy TEXT)"
self.connection.execute(sql_statement)
sql_statement = "SELECT AddGeometryColumn('Building', 'geom', 4326, "
sql_statement += "'MULTIPOLYGON', 'XY')"
self.connection.execute(sql_statement)
sql_statement = "SELECT AddGeometryColumn('Building', 'centroid', 4326, "
sql_statement += "'POINT', 'XY')"
self.connection.execute(sql_statement)
logger.debug("Table Building created")
# Create table Taxonomy
......@@ -180,7 +185,7 @@ class ExposureDatabase(SpatialiteDatabase):
def insert_building_asset(
self,
building_asset_id,
quadkey,
taxonomy_id,
number,
structural,
......@@ -193,8 +198,8 @@ class ExposureDatabase(SpatialiteDatabase):
Inserts a building-type asset to the BuildingAsset table.
Args:
building_asset_id (str):
ID of the building asset
quadkey (str):
Quadkey of the tile the building is located in
taxonomy_id (int):
ID of the taxonomy of the building asset (corresponds to Taxonomy.id)
number (float):
......@@ -212,10 +217,10 @@ class ExposureDatabase(SpatialiteDatabase):
"""
sql_statement = "INSERT INTO BuildingAsset "
sql_statement += "(id, taxonomy_id, number, structural, night, "
sql_statement += "(quadkey, taxonomy_id, number, structural, night, "
sql_statement += "occupancy, district_id, building_id) "
sql_statement += "VALUES ('%s', %d, %f, %f, %f, '%s', %d, %d)" % (
building_asset_id,
quadkey,
taxonomy_id,
number,
structural,
......@@ -228,21 +233,20 @@ class ExposureDatabase(SpatialiteDatabase):
def insert_tile_asset(
self,
tile_asset_id,
quadkey,
taxonomy_id,
number,
structural,
night,
occupancy,
district_id,
quadkey,
):
"""
Inserts a tile-type asset to the TileAsset table.
Args:
tile_asset_id (str):
ID of the tile asset
quadkey (str):
Quadkey of the tile asset is located in
taxonomy_id (int):
ID of the taxonomy of the tile asset (corresponds to Taxonomy.id)
number (float):
......@@ -255,41 +259,48 @@ class ExposureDatabase(SpatialiteDatabase):
Occupancy type of the tile asset
district_id (int):
ID of the district (corresponds to District.id)
quadkey (str):
ID (Quadkey) of the tile the tile asset is located in
"""
sql_statement = "INSERT INTO TileAsset "
sql_statement += "(id, taxonomy_id, number, structural, night, "
sql_statement += "occupancy, district_id, quadkey) "
sql_statement += "VALUES ('%s', %d, %f, %f, %f, '%s', %d, '%s')" % (
tile_asset_id,
sql_statement += "(quadkey, taxonomy_id, number, structural, night, "
sql_statement += "occupancy, district_id) "
sql_statement += "VALUES ('%s', %d, %f, %f, %f, '%s', %d)" % (
quadkey,
taxonomy_id,
number,
structural,
night,
occupancy,
district_id,
quadkey,
)
self.cursor.execute(sql_statement)
def insert_building(self, building_id, geom, quadkey):
def insert_building(self, building_id, quadkey, occupancy, geom, centroid):
"""
Inserts a building and its geometry to the Building table.
Args:
building_id (int):
ID of the building
geom (geom):
Geometry of the building (multi-polygon)
quadkey (str):
ID (Quadkey) of the tile the building centroid is located in
occupancy (str):
Occupancy type of the building
geom (geom):
Geometry of the building (multi-polygon)
centroid (geom):
Centroid of the building (point)
"""
sql_statement = "INSERT INTO Building "
sql_statement += "(id, geom, quadkey) "
sql_statement += "VALUES (%d, %s, '%s')" % (building_id, geom, quadkey)
sql_statement += "(id, quadkey, occupancy, geom, centroid) "
sql_statement += "VALUES (%d, %s, %s, '%s', '%s')" % (
building_id,
quadkey,
occupancy,
geom,
centroid,
)
self.cursor.execute(sql_statement)
def insert_taxonomy(self, taxonomy_id, taxonomy_string):
......
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