Skip to content

Commit

Permalink
Swmm states (#163)
Browse files Browse the repository at this point in the history
* add states

* update status list

* update outlet fk_wastewater_networkelement

* check with gruner data

* preserve topology

* preserve topology

* updates dones with Stefan

* add wastewater nodes without structure

* add the functions in the descriptions

* identifiers in description, function in tag

* raingages bug and conversion area unit

* merge with master

* update test counted values

* Update 09_vw_swmm_subcatchments.sql

remove comment
  • Loading branch information
tproduit authored Dec 16, 2020
1 parent b194ff6 commit f32001d
Show file tree
Hide file tree
Showing 10 changed files with 325 additions and 89 deletions.
97 changes: 85 additions & 12 deletions swmm_views/02_vw_swmm_junctions.sql
Original file line number Diff line number Diff line change
Expand Up @@ -12,19 +12,24 @@ SELECT
NULL::float as InitDepth,
NULL::float as SurchargeDepth,
NULL::float as PondedArea,
ws.identifier::text as description,
ma.obj_id as tag,
wn.situation_geometry as geom
ws.identifier::text as description,
CONCAT_WS(',', 'manhole', mf.value_en) as tag,
wn.situation_geometry as geom,
CASE
WHEN status IN (7959, 6529, 6526) THEN 'planned'
ELSE 'current'
END as state
FROM qgep_od.manhole ma
LEFT JOIN qgep_od.wastewater_structure ws ON ws.obj_id::text = ma.obj_id::text
LEFT JOIN qgep_od.wastewater_networkelement we ON we.fk_wastewater_structure::text = ws.obj_id::text
LEFT JOIN qgep_od.wastewater_node wn on wn.obj_id = we.obj_id
LEFT JOIN qgep_od.cover co on ws.fk_main_cover = co.obj_id
LEFT JOIN qgep_vl.manhole_function mf on ma.function = mf.code
WHERE wn.obj_id IS NOT NULL
AND ws._function_hierarchic in (5066, 5068, 5069, 5070, 5064, 5071, 5062, 5072, 5074)
--AND function != 4798 -- separating_structure -> used in swmm dividers
AND status IN (6530, 6533, 8493, 6529, 6526, 7959)

UNION ALL
UNION

-- special structures
SELECT
Expand All @@ -34,17 +39,22 @@ SELECT
NULL::float as InitDepth,
NULL::float as SurchargeDepth,
NULL::float as PondedArea,
ws.identifier::text as description,
ss.obj_id as tag,
wn.situation_geometry as geom
ws.identifier::text as description,
CONCAT_WS(',','special_structure', ssf.value_en) as tag,
wn.situation_geometry as geom,
CASE
WHEN status IN (7959, 6529, 6526) THEN 'planned'
ELSE 'current'
END as state
FROM qgep_od.special_structure ss
LEFT JOIN qgep_od.wastewater_structure ws ON ws.obj_id::text = ss.obj_id::text
LEFT JOIN qgep_od.wastewater_networkelement we ON we.fk_wastewater_structure::text = ws.obj_id::text
LEFT JOIN qgep_od.wastewater_node wn on wn.obj_id = we.obj_id
LEFT JOIN qgep_od.cover co on ws.fk_main_cover = co.obj_id
LEFT JOIN qgep_vl.special_structure_function ssf on ss.function = ssf.code
WHERE wn.obj_id IS NOT NULL
AND ws._function_hierarchic in (5066, 5068, 5069, 5070, 5064, 5071, 5062, 5072, 5074)
--AND function != 4799 -- separating_structure -> used in swmm dividers
AND status IN (6530, 6533, 8493, 6529, 6526, 7959)
AND function NOT IN ( -- must be the same list in vw_swmm_storages
6397, --"pit_without_drain"
-- 245, --"drop_structure"
Expand All @@ -68,12 +78,75 @@ AND function NOT IN ( -- must be the same list in vw_swmm_storages
3676, --"stormwater_retention_tank"
5575, --"stormwater_retention_channel"
5576, --"stormwater_storage_channel"
3677, --"stormwater_composite_tank"
5372 --"stormwater_overflow"
3677 --"stormwater_composite_tank"
-- 5372 -- "stormwater_overflow"
-- 5373, --"floating_material_separator"
-- 383 , --"side_access"
-- 227, --"jetting_manhole"
-- 4799, --"separating_structure"
-- 3008, --"unknown"
-- 2745, --"vortex_manhole"
);
)

UNION

-- wastewater_node not linked to wastewater structures
SELECT
from_wn.obj_id as Name,
coalesce(from_wn.bottom_level,0) as InvertElev,
0 as MaxDepth,
NULL::float as InitDepth,
NULL::float as SurchargeDepth,
NULL::float as PondedArea,
from_wn.obj_id as description,
'junction without structure' as tag,
from_wn.situation_geometry as geom,
CASE
WHEN ws.status IN (7959, 6529, 6526) THEN 'planned'
ELSE 'current'
END as state
FROM qgep_od.reach as re
LEFT JOIN qgep_od.wastewater_networkelement ne ON ne.obj_id::text = re.obj_id::text
LEFT JOIN qgep_od.wastewater_structure ws ON ws.obj_id = ne.fk_wastewater_structure
LEFT JOIN qgep_od.reach_point rp_from ON rp_from.obj_id::text = re.fk_reach_point_from::text
LEFT JOIN qgep_od.wastewater_node from_wn on from_wn.obj_id = rp_from.fk_wastewater_networkelement
LEFT JOIN qgep_od.channel ch on ch.obj_id::text = ws.obj_id::text
-- Get wastewater structure linked to the from node
LEFT JOIN qgep_od.wastewater_networkelement we ON from_wn.obj_id = we.obj_id
LEFT JOIN qgep_od.wastewater_structure ws_node ON we.fk_wastewater_structure::text = ws_node.obj_id::text
-- select only the primary channels pwwf.*
WHERE ch.function_hierarchic in (5066, 5068, 5069, 5070, 5064, 5071, 5062, 5072, 5074)
-- select only operationals and "planned"
AND ws.status IN (6530, 6533, 8493, 6529, 6526, 7959)
and ws_node is null

UNION

SELECT
to_wn.obj_id as Name,
coalesce(to_wn.bottom_level,0) as InvertElev,
0 as MaxDepth,
NULL::float as InitDepth,
NULL::float as SurchargeDepth,
NULL::float as PondedArea,
to_wn.obj_id as description,
'junction without structure' as tag,
to_wn.situation_geometry as geom,
CASE
WHEN ws.status IN (7959, 6529, 6526) THEN 'planned'
ELSE 'current'
END as state
FROM qgep_od.reach as re
LEFT JOIN qgep_od.wastewater_networkelement ne ON ne.obj_id::text = re.obj_id::text
LEFT JOIN qgep_od.wastewater_structure ws ON ws.obj_id = ne.fk_wastewater_structure
LEFT JOIN qgep_od.reach_point rp_to ON rp_to.obj_id::text = re.fk_reach_point_from::text
LEFT JOIN qgep_od.wastewater_node to_wn on to_wn.obj_id = rp_to.fk_wastewater_networkelement
LEFT JOIN qgep_od.channel ch on ch.obj_id::text = ws.obj_id::text
-- Get wastewater structure linked to the from node
LEFT JOIN qgep_od.wastewater_networkelement we ON to_wn.obj_id = we.obj_id
LEFT JOIN qgep_od.wastewater_structure ws_node ON we.fk_wastewater_structure::text = ws_node.obj_id::text
-- select only the primary channels pwwf.*
WHERE ch.function_hierarchic in (5066, 5068, 5069, 5070, 5064, 5071, 5062, 5072, 5074)
-- select only operationals and "planned"
AND ws.status IN (6530, 6533, 8493, 6529, 6526, 7959)
and ws_node is null;
31 changes: 24 additions & 7 deletions swmm_views/04_vw_swmm_conduits.sql
Original file line number Diff line number Diff line change
Expand Up @@ -21,18 +21,35 @@ SELECT
coalesce((rp_to.level-to_wn.bottom_level),0) as OutletOffset,
0 as InitFlow,
0 as MaxFlow,
ne.identifier::text as description,
ne.fk_wastewater_structure as tag,
ST_Simplify(ST_CurveToLine(progression_geometry), 20, TRUE)::geometry(LineStringZ, %(SRID)s) as geom
ws.identifier::text as description,
cfh.value_en as tag,
ST_SimplifyPreserveTopology(ST_CurveToLine(progression_geometry), 0.5)::geometry(LineStringZ, %(SRID)s) as geom,
CASE
WHEN status IN (7959, 6529, 6526) THEN 'planned'
ELSE 'current'
END as state
FROM qgep_od.reach as re
LEFT JOIN qgep_od.wastewater_networkelement ne ON ne.obj_id::text = re.obj_id::text

LEFT JOIN qgep_od.wastewater_structure ws ON ws.obj_id = ne.fk_wastewater_structure

LEFT JOIN qgep_od.reach_point rp_from ON rp_from.obj_id::text = re.fk_reach_point_from::text
LEFT JOIN qgep_od.reach_point rp_to ON rp_to.obj_id::text = re.fk_reach_point_to::text

LEFT JOIN qgep_od.wastewater_node from_wn on from_wn.obj_id = rp_from.fk_wastewater_networkelement
LEFT JOIN qgep_od.wastewater_node to_wn on to_wn.obj_id = rp_to.fk_wastewater_networkelement
LEFT JOIN qgep_od.channel ch on ch.obj_id::text = ws.obj_id::text
WHERE ch.function_hierarchic in (5066, 5068, 5069, 5070, 5064, 5071, 5062, 5072, 5074);
LEFT JOIN qgep_vl.channel_function_hydraulic cfh on cfh.code = ch.function_hydraulic
-- select only the primary channels pwwf.*
WHERE ch.function_hierarchic in (5066, 5068, 5069, 5070, 5064, 5071, 5062, 5072, 5074)
-- select only operationals and "planned"
AND status IN (6530, 6533, 8493, 6529, 6526, 7959);
-- 6526 "other.calculation_alternative"
-- 6529 "other.project"
-- 7959 "other.planned"
-- 6530 "operational.tentative"
-- 6533 "operational.will_be_suspended"
-- 8493 "operational"

-- 6532 "abanndoned.filled"
-- 3027 "unknown"
-- 3633 "inoperative"
-- 6523 "abanndoned.suspended_not_filled"
-- 6524 "abanndoned.suspended_unknown"
22 changes: 17 additions & 5 deletions swmm_views/05_vw_swmm_dividers.sql
Original file line number Diff line number Diff line change
Expand Up @@ -9,17 +9,23 @@ SELECT
st_x(wn.situation_geometry) as X_coordinate,
st_y(wn.situation_geometry) as Y_coordinate,
ws.identifier as description,
'manhole' as tag,
CONCAT_WS(',', 'manhole', mf.value_en) as tag,
wn.bottom_level as invert_elev,
(co.level-wn.bottom_level) as max_depth,
'???' as diverted_link
'???' as diverted_link,
CASE
WHEN status IN (7959, 6529, 6526) THEN 'planned'
ELSE 'current'
END as state
FROM qgep_od.manhole ma
LEFT JOIN qgep_od.wastewater_structure ws ON ws.obj_id::text = ma.obj_id::text
LEFT JOIN qgep_od.wastewater_networkelement we ON we.fk_wastewater_structure::text = ws.obj_id::text
LEFT JOIN qgep_od.wastewater_node wn on wn.obj_id = we.obj_id
LEFT JOIN qgep_od.cover co on ws.fk_main_cover = co.obj_id
LEFT JOIN qgep_vl.manhole_function mf on ma.function = mf.code
WHERE function = 4798 -- separating_structure
AND ws._function_hierarchic in (5066, 5068, 5069, 5070, 5064, 5071, 5062, 5072, 5074)
AND status IN (6530, 6533, 8493, 6529, 6526, 7959)

UNION ALL

Expand All @@ -28,14 +34,20 @@ SELECT
st_x(wn.situation_geometry) as X_coordinate,
st_y(wn.situation_geometry) as Y_coordinate,
ws.identifier as description,
'special_stucture' as tag,
CONCAT_WS(',','special_structure', ssf.value_en) as tag,
wn.bottom_level as invert_elev,
(co.level-wn.bottom_level) as max_depth,
'???' as diverted_link
'???' as diverted_link,
CASE
WHEN status IN (7959, 6529, 6526) THEN 'planned'
ELSE 'current'
END as state
FROM qgep_od.special_structure ss
LEFT JOIN qgep_od.wastewater_structure ws ON ws.obj_id::text = ss.obj_id::text
LEFT JOIN qgep_od.wastewater_networkelement we ON we.fk_wastewater_structure::text = ws.obj_id::text
LEFT JOIN qgep_od.wastewater_node wn on wn.obj_id = we.obj_id
LEFT JOIN qgep_od.cover co on ws.fk_main_cover = co.obj_id
LEFT JOIN qgep_vl.special_structure_function ssf on ss.function = ssf.code
WHERE function = 4799 -- separating_structure
AND ws._function_hierarchic in (5066, 5068, 5069, 5070, 5064, 5071, 5062, 5072, 5074);
AND ws._function_hierarchic in (5066, 5068, 5069, 5070, 5064, 5071, 5062, 5072, 5074)
AND status IN (6530, 6533, 8493, 6529, 6526, 7959);
7 changes: 6 additions & 1 deletion swmm_views/07_vw_swmm_losses.sql
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,11 @@ SELECT DISTINCT
WHEN ts.obj_id IS NOT NULL THEN 'YES'
ELSE 'NO'
END as flap_gate,
0::float as Seepage
0::float as Seepage,
CASE
WHEN status IN (7959, 6529, 6526) THEN 'planned'
ELSE 'current'
END as state
FROM qgep_od.reach re
LEFT JOIN qgep_od.wastewater_networkelement ne ON ne.obj_id::text = re.obj_id::text
LEFT JOIN qgep_od.pipe_profile pp on pp.obj_id = re.fk_pipe_profile
Expand All @@ -22,4 +26,5 @@ LEFT JOIN qgep_od.wastewater_node from_wn on from_wn.obj_id = rp_from.fk_wastewa
LEFT JOIN qgep_od.throttle_shut_off_unit ts ON ts.fk_wastewater_node = from_wn.obj_id
LEFT JOIN qgep_od.wastewater_structure ws ON ws.obj_id = ne.fk_wastewater_structure
WHERE ws._function_hierarchic in (5066, 5068, 5069, 5070, 5064, 5071, 5062, 5072, 5074)
AND status IN (6530, 6533, 8493, 6529, 6526, 7959)
; -- wastewater node of the downstream wastewater node
10 changes: 8 additions & 2 deletions swmm_views/08_vw_swmm_outfalls.sql
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,16 @@ SELECT
NULL::varchar as RouteTo,
CONCAT(ws.identifier, ', ', ws.remark) as description,
dp.obj_id::varchar as tag,
wn.situation_geometry as geom
wn.situation_geometry as geom,
CASE
WHEN status IN (7959, 6529, 6526) THEN 'planned'
ELSE 'current'
END as state
FROM qgep_od.discharge_point as dp
LEFT JOIN qgep_od.wastewater_structure ws ON ws.obj_id::text = dp.obj_id::text
LEFT JOIN qgep_od.wastewater_networkelement we ON we.fk_wastewater_structure::text = ws.obj_id::text
LEFT JOIN qgep_od.wastewater_node wn on wn.obj_id = we.obj_id
WHERE wn.obj_id IS NOT NULL
AND ws._function_hierarchic in (5066, 5068, 5069, 5070, 5064, 5071, 5062, 5072, 5074);
AND ws._function_hierarchic in (5066, 5068, 5069, 5070, 5064, 5071, 5062, 5072, 5074)
AND status IN (6530, 6533, 8493, 6529, 6526, 7959)
;
Loading

0 comments on commit f32001d

Please sign in to comment.