Skip to content
Snippets Groups Projects
Commit e1856c42 authored by Laurens Oostwegel's avatar Laurens Oostwegel
Browse files

Delete a building from the building database if it doesn't exist in the source database

parent c0677929
1 merge request!8Resolve "Delete building from the obm_buildings table if the building ID does not exist in the osm_replication table"
Pipeline #65310 passed
......@@ -50,6 +50,11 @@ class ObmBuildingsInformation:
"""
database.cursor.execute(sql_statement)
result = database.cursor.fetchone()
# If the OSM ID does not exist, it should be deleted.
if result is None:
return {"osm_id": key, "deleted": True}
building_information.update(
{k.name: v for k, v in zip(database.cursor.description, result)}
)
......
......@@ -2,13 +2,14 @@ class ObmBuildingsUpsert:
def __call__(
self,
database,
geometry,
osm_id,
geometry=None,
floorspace=None,
occupancy=None,
stories=None,
relation_id=None,
quadkey=None,
deleted=False,
*args,
**kwargs,
):
......@@ -35,6 +36,16 @@ class ObmBuildingsUpsert:
Quadkey of the tile that the building is located in.
"""
# If the `deleted` flag is True, delete the building from the database
if deleted:
sql_statement = f"""
DELETE FROM obm_buildings
WHERE osm_id = {osm_id}
"""
database.cursor.execute(sql_statement)
database.connection.commit()
return
sql_statement = f"""
INSERT INTO obm_buildings
(osm_id, geometry, floorspace, occupancy, storeys, relation_id, quadkey,
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment