Skip to content

Commit

Permalink
feat: returns building_outlines modified in msg box
Browse files Browse the repository at this point in the history
  • Loading branch information
YingtingChen committed Oct 17, 2024
1 parent 43a5697 commit 3923874
Show file tree
Hide file tree
Showing 5 changed files with 26 additions and 22 deletions.
19 changes: 12 additions & 7 deletions buildings/gui/reference_data.py
Original file line number Diff line number Diff line change
Expand Up @@ -265,22 +265,27 @@ def topo_layer_processing(self, dataset):
else:
status = topo50.update_topo50(api_key, dataset, self.db)
self.update_message(status, dataset)
if status != "error":
if status == "updated":
self.updates.append(dataset)

def admin_bdy_layer_processing(self, dataset):
"""Processes to run for admin bdy layers"""
api_key = self.check_api_key(dataset)
if api_key is None:
return
status = admin_bdys.update_admin_bdys(api_key, dataset, self.db)
self.update_message(status, dataset)
if status != "error":
status, ids_bo = admin_bdys.update_admin_bdys(api_key, dataset, self.db)
if status == "updated":
self.update_message(
status,
f"{dataset} ({len(ids_bo)} building outlines modified)",
)
self.updates.append(dataset)
if dataset == "territorial_authority":
self.db.execute_no_commit(reference_select.refresh_ta_grid_view)
self.update_message("updated", "territorial_authority_grid")
self.updates.append("territorial_authority_grid")
else:
self.update_message(status, dataset)

def check_api_key(self, layer):
# check for API key
Expand All @@ -301,9 +306,9 @@ def check_api_key(self, layer):
def update_message(self, status, name):
"""add to message for display at end of processing"""
if status == "current":
self.message += "The {} table was up to date\n".format(name)
self.message += "The table {} was up to date\n".format(name)
if status == "updated":
self.message += "The {} table has been updated\n".format(name)
self.message += "The table {} has been updated\n".format(name)
if status == "error":
self.message += "The request errored on the {} table\n".format(name)
self.message += "The request errored on the table {}\n".format(name)
self.request_error()
19 changes: 9 additions & 10 deletions buildings/reference_data/admin_bdys.py
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,6 @@ def current_date():
# todo: add kx_api_key in config
# todo: combine suburb_locality- and town city
def update_admin_bdys(kx_api_key, dataset, dbconn: db):

# get last update of layer date from log
from_var = last_update(dataset)

Expand All @@ -76,10 +75,10 @@ def update_admin_bdys(kx_api_key, dataset, dbconn: db):

if not layer.isValid():
# something went wrong
return "error"
return "error", []

if layer.featureCount() == 0:
return "current"
return "current", []

external_id = LAYERS[dataset]["primary_id"]

Expand Down Expand Up @@ -201,21 +200,21 @@ def update_admin_bdys(kx_api_key, dataset, dbconn: db):
feature.geometry().asWkt(),
),
)
print("updated_attrs: {}".format(ids_attr_updates))
print("updated_geom: {}".format(len(geoms_diff)))
geom_union = QgsGeometry.unaryUnion(geoms_diff).asWkt()
print(geom_union)
sql = "SELECT buildings_reference.{}_attribute_update_building_outlines(%s)".format(
dataset
)
dbconn.execute_no_commit(sql, (ids_attr_updates,))
result = dbconn.execute_no_commit(sql, (ids_attr_updates,))
ids_bo = [r[0] for r in result.fetchall() if r[0] is not None]

sql = "SELECT buildings_reference.{}_geometry_update_building_outlines(%s)".format(
dataset
)
dbconn.execute_no_commit(sql, (geom_union,))

return "updated"
result = dbconn.execute_no_commit(sql, (geom_union,))
ids_bo.extend(
[r[0] for r in result.fetchall() if r[0] not in ids_bo and r[0] is not None]
)
return "updated", ids_bo


def correct_name_format(name):
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ RETURNS integer AS
$$

INSERT INTO buildings_reference.reference_update_log (river, lake, pond, swamp, lagoon, canal, coastlines_and_islands, capture_source_area, territorial_authority, territorial_authority_grid, suburb_locality, hut, shelter, bivouac, protected_areas)
VALUES(CASE WHEN ('river_polygon' = ANY(p_list)) THEN True ELSE False END,
VALUES(CASE WHEN ('river_polygons' = ANY(p_list)) THEN True ELSE False END,
CASE WHEN ('lake_polygons' = ANY(p_list)) THEN True ELSE False END,
CASE WHEN ('pond_polygons' = ANY(p_list)) THEN True ELSE False END,
CASE WHEN ('swamp_polygons' = ANY(p_list)) THEN True ELSE False END,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,7 @@ COMMENT ON FUNCTION buildings_reference.suburb_locality_update_by_external_id(in
-- params: integer[] suburb_locality_id
-- return: integer building_outline_id
CREATE OR REPLACE FUNCTION buildings_reference.suburb_locality_attribute_update_building_outlines(integer[])
RETURNS integer AS
RETURNS SETOF integer AS
$$
UPDATE buildings.building_outlines
SET last_modified = NOW()
Expand All @@ -138,7 +138,7 @@ COMMENT ON FUNCTION buildings_reference.suburb_locality_attribute_update_buildin
-- params: varchar shape
-- return: integer building_outline_id
CREATE OR REPLACE FUNCTION buildings_reference.suburb_locality_geometry_update_building_outlines(varchar)
RETURNS integer AS
RETURNS SETOF integer AS
$$
WITH sub_tas AS (
SELECT ST_Subdivide(ST_SetSRID(ST_GeometryFromText($1), 2193)) AS shape
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -152,7 +152,7 @@ COMMENT ON FUNCTION buildings_reference.territorial_authority_update_by_external
-- params: integer[] territorial_authority_id
-- return: integer building_outline_id
CREATE OR REPLACE FUNCTION buildings_reference.territorial_authority_attribute_update_building_outlines(integer[])
RETURNS integer AS
RETURNS SETOF integer AS
$$
UPDATE buildings.building_outlines
SET last_modified = NOW()
Expand All @@ -169,7 +169,7 @@ COMMENT ON FUNCTION buildings_reference.territorial_authority_attribute_update_b
-- params: varchar shape
-- return: integer building_outline_id
CREATE OR REPLACE FUNCTION buildings_reference.territorial_authority_geometry_update_building_outlines(varchar)
RETURNS integer AS
RETURNS SETOF integer AS
$$
WITH sub_tas AS (
SELECT ST_Subdivide(ST_SetSRID(ST_GeometryFromText($1), 2193)) AS shape
Expand Down

0 comments on commit 3923874

Please sign in to comment.