Skip to content

Commit

Permalink
Merge pull request #90 from QGEP/geometry_altitude
Browse files Browse the repository at this point in the history
Geometry altitude integration
  • Loading branch information
m-kuhn authored Feb 20, 2019
2 parents e06e652 + ac2f13f commit 76cf0d9
Show file tree
Hide file tree
Showing 12 changed files with 2,147 additions and 44 deletions.
2 changes: 1 addition & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ before_script:
script:
- $TRAVIS_BUILD_DIR/scripts/db_setup.sh -r > /dev/null
- nosetests -e test_import.py
- nosetests -e test_import.py -e test_geometry.py

# Get current version
- export VERSION=$(sed 'r' "$TRAVIS_BUILD_DIR/system/CURRENT_VERSION.txt")
Expand Down
6 changes: 3 additions & 3 deletions 03_qgep_db_dss.sql
Original file line number Diff line number Diff line change
Expand Up @@ -1825,7 +1825,7 @@ ALTER TABLE qgep_od.reach_point ADD COLUMN position_of_connection smallint ;
COMMENT ON COLUMN qgep_od.reach_point.position_of_connection IS 'yyy_Anschlussstelle bezogen auf Querschnitt im Kanal; in Fliessrichtung (für Haus- und Strassenanschlüsse) / Anschlussstelle bezogen auf Querschnitt im Kanal; in Fliessrichtung (für Haus- und Strassenanschlüsse) / Emplacement de raccordement Référence à la section transversale dans le canal dans le sens d’écoulement (pour les raccordements domestiques et de rue).';
ALTER TABLE qgep_od.reach_point ADD COLUMN remark varchar(80) ;
COMMENT ON COLUMN qgep_od.reach_point.remark IS 'General remarks / Allgemeine Bemerkungen / Remarques générales';
ALTER TABLE qgep_od.reach_point ADD COLUMN situation_geometry geometry('POINT', :SRID);
ALTER TABLE qgep_od.reach_point ADD COLUMN situation_geometry geometry('POINTZ', :SRID);
CREATE INDEX in_qgep_od_reach_point_situation_geometry ON qgep_od.reach_point USING gist (situation_geometry );
COMMENT ON COLUMN qgep_od.reach_point.situation_geometry IS 'National position coordinates (East, North) / Landeskoordinate Ost/Nord / Coordonnées nationales Est/Nord';
ALTER TABLE qgep_od.reach_point ADD COLUMN last_modification TIMESTAMP without time zone DEFAULT now();
Expand Down Expand Up @@ -1859,7 +1859,7 @@ ALTER TABLE qgep_od.wastewater_node ADD COLUMN backflow_level decimal(7,3) ;
COMMENT ON COLUMN qgep_od.wastewater_node.backflow_level IS 'yyy_1. Massgebende Rückstaukote bezogen auf den Berechnungsregen (dss) 2. Höhe, unter der innerhalb der Grundstücksentwässerung besondere Massnahmen gegen Rückstau zu treffen sind. (DIN 4045) / 1. Massgebende Rückstaukote bezogen auf den Berechnungsregen (dss) 2. Höhe, unter der innerhalb der Grundstücksentwässerung besondere Massnahmen gegen Rückstau zu treffen sind. (DIN 4045) / Cote de refoulement déterminante calculée à partir des pluies de projet';
ALTER TABLE qgep_od.wastewater_node ADD COLUMN bottom_level decimal(7,3) ;
COMMENT ON COLUMN qgep_od.wastewater_node.bottom_level IS 'yyy_Tiefster Punkt des Abwasserbauwerks / Tiefster Punkt des Abwasserbauwerks / Point le plus bas du noeud';
ALTER TABLE qgep_od.wastewater_node ADD COLUMN situation_geometry geometry('POINT', :SRID);
ALTER TABLE qgep_od.wastewater_node ADD COLUMN situation_geometry geometry('POINTZ', :SRID);
CREATE INDEX in_qgep_od_wastewater_node_situation_geometry ON qgep_od.wastewater_node USING gist (situation_geometry );
COMMENT ON COLUMN qgep_od.wastewater_node.situation_geometry IS 'yyy Situation of node. Decisive reference point for sewer network simulation (In der Regel Lage des Pickellochs oder Lage des Trockenwetterauslauf) / Lage des Knotens, massgebender Bezugspunkt für die Kanalnetzberechnung. (In der Regel Lage des Pickellochs oder Lage des Trockenwetterauslaufs) / Positionnement du nœud. Point de référence déterminant pour le calcul de réseau de canalisations (en règle générale positionnement du milieu du couvercle ou de la sortie temps sec)';
-------
Expand Down Expand Up @@ -2255,7 +2255,7 @@ ALTER TABLE qgep_od.cover ADD COLUMN material integer ;
COMMENT ON COLUMN qgep_od.cover.material IS 'Material of cover / Deckelmaterial / Matériau du couvercle';
ALTER TABLE qgep_od.cover ADD COLUMN positional_accuracy integer ;
COMMENT ON COLUMN qgep_od.cover.positional_accuracy IS 'Quantfication of accuarcy of position of cover (center hole) / Quantifizierung der Genauigkeit der Lage des Deckels (Pickelloch) / Plage de précision des coordonnées planimétriques du couvercle.';
ALTER TABLE qgep_od.cover ADD COLUMN situation_geometry geometry('POINT', :SRID);
ALTER TABLE qgep_od.cover ADD COLUMN situation_geometry geometry('POINTZ', :SRID);
CREATE INDEX in_qgep_od_cover_situation_geometry ON qgep_od.cover USING gist (situation_geometry );
COMMENT ON COLUMN qgep_od.cover.situation_geometry IS 'Situation of cover (cover hole), National position coordinates (East, North) / Lage des Deckels (Pickelloch) / Positionnement du couvercle (milieu du couvercle)';
ALTER TABLE qgep_od.cover ADD COLUMN sludge_bucket integer ;
Expand Down
4 changes: 2 additions & 2 deletions 07_views_for_network_tracking.sql
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,8 @@ CREATE MATERIALIZED VIEW qgep_od.vw_network_node AS
NULL AS cover_level,
NULL AS backflow_level,
NULL AS description,
situation_geometry::geometry(Point,:SRID) AS detail_geometry,
situation_geometry::geometry(Point,:SRID)
situation_geometry::geometry(POINTZ,:SRID) AS detail_geometry,
situation_geometry::geometry(POINTZ,:SRID)
FROM qgep_od.reach_point

UNION
Expand Down
8 changes: 4 additions & 4 deletions 13_import.sql
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ CREATE TABLE qgep_import.manhole_quarantine
(
obj_id character varying(16),
identifier character varying(20),
situation_geometry geometry(Point,:SRID),
situation_geometry geometry(POINTZ,:SRID),
co_shape integer,
co_diameter smallint,
co_material integer,
Expand Down Expand Up @@ -57,7 +57,7 @@ CREATE TABLE qgep_import.manhole_quarantine
CREATE OR REPLACE VIEW qgep_import.vw_manhole AS
SELECT DISTINCT ON (ws.obj_id) ws.obj_id,
ws.identifier,
(st_dump(ws.situation_geometry)).geom::geometry(Point,:SRID) AS situation_geometry,
(st_dump(ws.situation_geometry)).geom::geometry(POINTZ,:SRID) AS situation_geometry,
ws.co_shape,
ws.co_diameter,
ws.co_material,
Expand Down Expand Up @@ -224,9 +224,9 @@ BEGIN
EXECUTE format($TRIGGER$
CREATE OR REPLACE FUNCTION qgep_import.manhole_quarantine_try_structure_update() RETURNS trigger AS $BODY$
DECLARE
multi_situation_geometry geometry(MultiPoint,%1$s);
multi_situation_geometry geometry(MULTIPOINTZ,%1$s);
BEGIN
multi_situation_geometry = st_collect(NEW.situation_geometry)::geometry(MultiPoint,%1$s);
multi_situation_geometry = st_collect(NEW.situation_geometry)::geometry(MULTIPOINTZ,%1$s);

-- in case there is a depth, but no refercing value - it should stay in quarantene
IF( NEW._depth IS NOT NULL AND NEW.co_level IS NULL AND NEW.wn_bottom_level IS NULL ) THEN
Expand Down
89 changes: 89 additions & 0 deletions 14_geometry_functions.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,89 @@
-----------------------------------------------
-----------------------------------------------
-- Synchronize GEOMETRY with bottom_level qgep_od.wastewater_node
-----------------------------------------------
-----------------------------------------------
SELECT set_config('qgep.srid', :SRID::text, false);
DO $DO$
BEGIN
EXECUTE format($TRIGGER$
CREATE OR REPLACE FUNCTION qgep_od.synchronize_level_with_altitude_on_wastewater_node()
RETURNS trigger AS
$BODY$
BEGIN
CASE
WHEN TG_OP = 'INSERT' THEN
NEW.situation_geometry = ST_SetSRID( ST_MakePoint( ST_X(NEW.situation_geometry), ST_Y(NEW.situation_geometry), COALESCE(NEW.bottom_level,'NaN') ), %1$s);
WHEN TG_OP = 'UPDATE' THEN
IF NEW.bottom_level <> OLD.bottom_level OR (NEW.bottom_level IS NULL AND OLD.bottom_level IS NOT NULL) OR (NEW.bottom_level IS NOT NULL AND OLD.bottom_level IS NULL) THEN
NEW.situation_geometry = ST_SetSRID( ST_MakePoint( ST_X(NEW.situation_geometry), ST_Y(NEW.situation_geometry), COALESCE(NEW.bottom_level,'NaN') ), %1$s);
ELSE
IF ST_Z(NEW.situation_geometry) <> ST_Z(OLD.situation_geometry) THEN
NEW.bottom_level = NULLIF(ST_Z(NEW.situation_geometry),'NaN');
END IF;
END IF;
END CASE;

RETURN NEW;
END; $BODY$
LANGUAGE plpgsql VOLATILE;
$TRIGGER$, current_setting('qgep.srid'));
END
$DO$;

DROP TRIGGER IF EXISTS synchronize_level_with_altitude ON qgep_od.wastewater_node;

CREATE TRIGGER synchronize_level_with_altitude
BEFORE INSERT OR UPDATE
ON qgep_od.wastewater_node
FOR EACH ROW
EXECUTE PROCEDURE qgep_od.synchronize_level_with_altitude_on_wastewater_node();


-----------------------------------------------
-----------------------------------------------
-- Synchronize GEOMETRY with level qgep_od.cover
-----------------------------------------------
-----------------------------------------------
SELECT set_config('qgep.srid', :SRID::text, false);
DO $DO$
BEGIN
EXECUTE format($TRIGGER$
CREATE OR REPLACE FUNCTION qgep_od.synchronize_level_with_altitude_on_cover()
RETURNS trigger AS
$BODY$
BEGIN
CASE
WHEN TG_OP = 'INSERT' THEN
NEW.situation_geometry = ST_SetSRID( ST_MakePoint( ST_X(NEW.situation_geometry), ST_Y(NEW.situation_geometry), COALESCE(NEW.level,'NaN') ), %1$s);
WHEN TG_OP = 'UPDATE' THEN
IF NEW.level <> OLD.level OR (NEW.level IS NULL AND OLD.level IS NOT NULL) OR (NEW.level IS NOT NULL AND OLD.level IS NULL) THEN
NEW.situation_geometry = ST_SetSRID( ST_MakePoint( ST_X(NEW.situation_geometry), ST_Y(NEW.situation_geometry), COALESCE(NEW.level,'NaN') ), %1$s);
ELSE
IF ST_Z(NEW.situation_geometry) <> ST_Z(OLD.situation_geometry) THEN
NEW.level = NULLIF(ST_Z(NEW.situation_geometry),'NaN');
END IF;
END IF;
END CASE;

RETURN NEW;
END; $BODY$
LANGUAGE plpgsql VOLATILE;
$TRIGGER$, current_setting('qgep.srid'));
END
$DO$;

DROP TRIGGER IF EXISTS synchronize_level_with_altitude ON qgep_od.cover;

CREATE TRIGGER synchronize_level_with_altitude
BEFORE INSERT OR UPDATE
ON qgep_od.cover
FOR EACH ROW
EXECUTE PROCEDURE qgep_od.synchronize_level_with_altitude_on_cover();


-----------------------------------------------
-----------------------------------------------
-- Synchronize reach and reach_point GEOMETRY with level qgep_od.vw_qgep_reach is implemented in vw_qgep_reach.sql
-----------------------------------------------
-----------------------------------------------
Loading

0 comments on commit 76cf0d9

Please sign in to comment.