forked from QGEP/datamodel
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
improve labelling as per QGEP/QGEP#524
- Loading branch information
1 parent
82e2b76
commit 9d146ec
Showing
4 changed files
with
129 additions
and
24 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,87 @@ | ||
|
||
-- TABLE wastewater_structure | ||
|
||
ALTER TABLE qgep_od.wastewater_structure ADD COLUMN _cover_label text; | ||
COMMENT ON COLUMN qgep_od.wastewater_structure._cover_label IS 'not part of the VSA-DSS data model | ||
added solely for QGEP'; | ||
ALTER TABLE qgep_od.wastewater_structure ADD COLUMN _input_label text; | ||
COMMENT ON COLUMN qgep_od.wastewater_structure._input_label IS 'not part of the VSA-DSS data model | ||
added solely for QGEP'; | ||
ALTER TABLE qgep_od.wastewater_structure ADD COLUMN _output_label text; | ||
COMMENT ON COLUMN qgep_od.wastewater_structure._output_label IS 'not part of the VSA-DSS data model | ||
added solely for QGEP'; | ||
ALTER TABLE qgep_od.wastewater_structure ADD COLUMN _bottom_label text; | ||
COMMENT ON COLUMN qgep_od.wastewater_structure._bottom_label IS 'not part of the VSA-DSS data model | ||
added solely for QGEP'; | ||
|
||
|
||
-------------------------------------------------------- | ||
-- UPDATE wastewater structure label | ||
-- Argument: | ||
-- * obj_id of wastewater structure or NULL to update all | ||
-------------------------------------------------------- | ||
|
||
CREATE OR REPLACE FUNCTION qgep_od.update_wastewater_structure_label(_obj_id text, _all boolean default false) | ||
RETURNS VOID AS | ||
$BODY$ | ||
DECLARE | ||
myrec record; | ||
|
||
BEGIN | ||
UPDATE qgep_od.wastewater_structure ws | ||
SET _label = label, | ||
_cover_label = cover_label, | ||
_bottom_label = bottom_label, | ||
_input_label = input_label, | ||
_output_label = output_label | ||
FROM ( | ||
SELECT ws_obj_id, | ||
COALESCE(ws_identifier, '') as label, | ||
array_to_string(array_agg(E'\nC' || '=' || co_level::text ORDER BY co_level DESC), '', '') as cover_label, | ||
array_to_string(array_agg(E'\nB' || '=' || bottom_level::text), '', '') as bottom_label, | ||
array_to_string(array_agg(E'\nI' || idx || '=' || rpi_level::text ORDER BY idx), '', '') as input_label, | ||
array_to_string(array_agg(E'\nO' || idx || '=' || rpo_level::text ORDER BY idx), '', '') as output_label | ||
FROM ( | ||
SELECT ws.obj_id AS ws_obj_id, ws.identifier AS ws_identifier, round(parts.co_level, 2) AS co_level, round(parts.rpi_level, 2) AS rpi_level, round(parts.rpo_level, 2) AS rpo_level, parts.obj_id, idx, round(bottom_level, 2) AS bottom_level | ||
FROM qgep_od.wastewater_structure WS | ||
|
||
LEFT JOIN ( | ||
-- Cover | ||
SELECT CO.level AS co_level, NULL::numeric(5,3) AS rpi_level, NULL::numeric(5,3) AS rpo_level, SP.fk_wastewater_structure ws, SP.obj_id, row_number() OVER(PARTITION BY SP.fk_wastewater_structure) AS idx, NULL::numeric(5,3) AS bottom_level | ||
FROM qgep_od.structure_part SP | ||
RIGHT JOIN qgep_od.cover CO ON CO.obj_id = SP.obj_id | ||
WHERE _all OR SP.fk_wastewater_structure = _obj_id | ||
-- Inputs | ||
UNION | ||
SELECT NULL AS co_level, RP.level AS rpi_level, NULL::numeric(5,3) AS rpo_level, NE.fk_wastewater_structure ws, RP.obj_id, row_number() OVER(PARTITION BY RP.fk_wastewater_networkelement ORDER BY ST_Azimuth(RP.situation_geometry,ST_LineInterpolatePoint(ST_CurveToLine(RE_to.progression_geometry),0.99))/pi()*180 ASC), NULL::numeric(5,3) AS bottom_level | ||
FROM qgep_od.reach_point RP | ||
LEFT JOIN qgep_od.wastewater_networkelement NE ON RP.fk_wastewater_networkelement = NE.obj_id | ||
INNER JOIN qgep_od.reach RE_to ON RP.obj_id = RE_to.fk_reach_point_to | ||
LEFT JOIN qgep_od.wastewater_networkelement NE_to ON NE_to.obj_id = RE_to.obj_id | ||
LEFT JOIN qgep_od.channel CH_to ON NE_to.fk_wastewater_structure = CH_to.obj_id | ||
WHERE (_all OR NE.fk_wastewater_structure = _obj_id) and CH_to.function_hierarchic in (5062,5064,5066,5068,5069,5070,5071,5072,5074) ----label only reaches with function_hierarchic=pwwf.* | ||
-- Outputs | ||
UNION | ||
SELECT NULL AS co_level, NULL::numeric(5,3) AS rpi_level, RP.level AS rpo_level, NE.fk_wastewater_structure ws, RP.obj_id, row_number() OVER(PARTITION BY RP.fk_wastewater_networkelement ORDER BY ST_Azimuth(RP.situation_geometry,ST_LineInterpolatePoint(ST_CurveToLine(RE_from.progression_geometry),0.99))/pi()*180 ASC), NULL::numeric(5,3) AS bottom_level | ||
FROM qgep_od.reach_point RP | ||
LEFT JOIN qgep_od.wastewater_networkelement NE ON RP.fk_wastewater_networkelement = NE.obj_id | ||
INNER JOIN qgep_od.reach RE_from ON RP.obj_id = RE_from.fk_reach_point_from | ||
WHERE CASE WHEN _obj_id IS NULL THEN TRUE ELSE NE.fk_wastewater_structure = _obj_id END | ||
-- Bottom | ||
UNION | ||
SELECT NULL AS co_level, NULL::numeric(5,3) AS rpi_level, NULL::numeric(5,3) AS rpo_level, ws1.obj_id ws, NULL, NULL, wn.bottom_level AS wn_bottom_level | ||
FROM qgep_od.wastewater_structure ws1 | ||
LEFT JOIN qgep_od.wastewater_node wn ON wn.obj_id = ws1.fk_main_wastewater_node | ||
WHERE _all OR ws1.obj_id = _obj_id | ||
) AS parts ON ws = ws.obj_id | ||
WHERE _all OR ws.obj_id = _obj_id | ||
) parts | ||
GROUP BY ws_obj_id, COALESCE(ws_identifier, '') | ||
) labeled_ws | ||
WHERE ws.obj_id = labeled_ws.ws_obj_id; | ||
|
||
END | ||
|
||
$BODY$ | ||
LANGUAGE plpgsql | ||
VOLATILE; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters