Skip to content

Commit

Permalink
add update_fk_main_cover and fk_main_node to symbology functions
Browse files Browse the repository at this point in the history
Create delta for it also
  • Loading branch information
sjib committed May 13, 2024
1 parent e58d627 commit 1c90791
Show file tree
Hide file tree
Showing 2 changed files with 126 additions and 0 deletions.
63 changes: 63 additions & 0 deletions 06_symbology_functions.sql
Original file line number Diff line number Diff line change
Expand Up @@ -263,6 +263,69 @@ BEGIN
END; $BODY$
LANGUAGE plpgsql VOLATILE;

--------------------------------------------------------
-- UPDATE wastewater structure fk_main_cover
-- Argument:
-- * obj_id of wastewater structure
-- * all True to update all
-- * omit both arguments to update all where fk_main_cover is null
--------------------------------------------------------
CREATE OR REPLACE FUNCTION qgep_od.wastewater_structure_update_fk_main_cover(_obj_id text default NULL, _all boolean default false)
RETURNS VOID AS
$BODY$
DECLARE
myrec record;

BEGIN
UPDATE qgep_od.wastewater_structure ws
SET fk_main_cover = ws_covers.co_obj_id
FROM (
SELECT ws.obj_id, min(co.obj_id) OVER (PARTITION BY ws.obj_id) AS co_obj_id
FROM qgep_od.wastewater_structure ws
LEFT JOIN qgep_od.structure_part sp ON sp.fk_wastewater_structure = ws.obj_id
LEFT JOIN qgep_od.cover co ON sp.obj_id = co.obj_id
LEFT JOIN qgep_od.channel ch ON ch.obj_id = ws.obj_id
WHERE ch.obj_id IS NULL AND (_all OR ws.obj_id = _obj_id OR ( NOT _all AND _obj_id is NULL AND ws.fk_main_cover IS NULL))
) ws_covers
WHERE ws.obj_id = ws_covers.obj_id;
END

$BODY$
LANGUAGE plpgsql
VOLATILE;

--------------------------------------------------------
-- UPDATE wastewater structure fk_main_wastewater_node
-- Argument:
-- * obj_id of wastewater structure
-- * all True to update all
-- * omit both arguments to update all where fk_main_wastewater_node is null
--------------------------------------------------------

CREATE OR REPLACE FUNCTION qgep_od.wastewater_structure_update_fk_main_wastewater_node(_obj_id text default NULL, _all boolean default false)
RETURNS VOID AS
$BODY$
DECLARE
myrec record;

BEGIN
UPDATE qgep_od.wastewater_structure ws
SET fk_main_wastewater_node = ws_nodes.wn_obj_id
FROM (
SELECT ws.obj_id, min(wn.obj_id) OVER (PARTITION BY ws.obj_id) AS wn_obj_id
FROM qgep_od.wastewater_structure ws
LEFT JOIN qgep_od.wastewater_networkelement ne ON ne.fk_wastewater_structure = ws.obj_id
LEFT JOIN qgep_od.wastewater_node wn ON ne.obj_id = wn.obj_id
LEFT JOIN qgep_od.channel ch ON ch.obj_id = ws.obj_id
WHERE ch.obj_id IS NULL AND (_all OR ws.obj_id = _obj_id OR ( NOT _all AND _obj_id is NULL AND ws.fk_main_wastewater_node IS NULL))
) ws_nodes
WHERE ws.obj_id = ws_nodes.obj_id;
END

$BODY$
LANGUAGE plpgsql
VOLATILE;

--------------------------------------------------------
-- UPDATE wastewater structure depth
-- Argument:
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@

--------------------------------------------------------
-- UPDATE wastewater structure fk_main_cover
-- Argument:
-- * obj_id of wastewater structure
-- * all True to update all
-- * omit both arguments to update all where fk_main_cover is null
--------------------------------------------------------
CREATE OR REPLACE FUNCTION qgep_od.wastewater_structure_update_fk_main_cover(_obj_id text default NULL, _all boolean default false)
RETURNS VOID AS
$BODY$
DECLARE
myrec record;

BEGIN
UPDATE qgep_od.wastewater_structure ws
SET fk_main_cover = ws_covers.co_obj_id
FROM (
SELECT ws.obj_id, min(co.obj_id) OVER (PARTITION BY ws.obj_id) AS co_obj_id
FROM qgep_od.wastewater_structure ws
LEFT JOIN qgep_od.structure_part sp ON sp.fk_wastewater_structure = ws.obj_id
LEFT JOIN qgep_od.cover co ON sp.obj_id = co.obj_id
LEFT JOIN qgep_od.channel ch ON ch.obj_id = ws.obj_id
WHERE ch.obj_id IS NULL AND (_all OR ws.obj_id = _obj_id OR ( NOT _all AND _obj_id is NULL AND ws.fk_main_cover IS NULL))
) ws_covers
WHERE ws.obj_id = ws_covers.obj_id;
END

$BODY$
LANGUAGE plpgsql
VOLATILE;

--------------------------------------------------------
-- UPDATE wastewater structure fk_main_wastewater_node
-- Argument:
-- * obj_id of wastewater structure
-- * all True to update all
-- * omit both arguments to update all where fk_main_wastewater_node is null
--------------------------------------------------------

CREATE OR REPLACE FUNCTION qgep_od.wastewater_structure_update_fk_main_wastewater_node(_obj_id text default NULL, _all boolean default false)
RETURNS VOID AS
$BODY$
DECLARE
myrec record;

BEGIN
UPDATE qgep_od.wastewater_structure ws
SET fk_main_wastewater_node = ws_nodes.wn_obj_id
FROM (
SELECT ws.obj_id, min(wn.obj_id) OVER (PARTITION BY ws.obj_id) AS wn_obj_id
FROM qgep_od.wastewater_structure ws
LEFT JOIN qgep_od.wastewater_networkelement ne ON ne.fk_wastewater_structure = ws.obj_id
LEFT JOIN qgep_od.wastewater_node wn ON ne.obj_id = wn.obj_id
LEFT JOIN qgep_od.channel ch ON ch.obj_id = ws.obj_id
WHERE ch.obj_id IS NULL AND (_all OR ws.obj_id = _obj_id OR ( NOT _all AND _obj_id is NULL AND ws.fk_main_wastewater_node IS NULL))
) ws_nodes
WHERE ws.obj_id = ws_nodes.obj_id;
END

$BODY$
LANGUAGE plpgsql
VOLATILE;

0 comments on commit 1c90791

Please sign in to comment.