diff --git a/ud/ftrg/ud_gw_trg_edit_arc.sql b/ud/ftrg/ud_gw_trg_edit_arc.sql index fe6155d2f5..0dc126ac7c 100644 --- a/ud/ftrg/ud_gw_trg_edit_arc.sql +++ b/ud/ftrg/ud_gw_trg_edit_arc.sql @@ -10,7 +10,7 @@ This version of Giswater is provided by Giswater Association CREATE OR REPLACE FUNCTION SCHEMA_NAME.gw_trg_edit_arc() RETURNS trigger AS $BODY$ -DECLARE +DECLARE v_inp_table varchar; v_man_table varchar; v_new_man_table varchar; @@ -49,12 +49,12 @@ BEGIN END IF; v_type_v_man_table:=v_man_table; - + v_promixity_buffer = (SELECT "value" FROM config_param_system WHERE "parameter"='edit_feature_buffer_on_mapzone'); v_edit_enable_arc_nodes_update = (SELECT "value" FROM config_param_system WHERE "parameter"='edit_arc_enable nodes_update'); v_autoupdate_fluid = (SELECT value::boolean FROM config_param_system WHERE parameter='edit_connect_autoupdate_fluid'); v_psector = (SELECT value::integer FROM config_param_user WHERE "parameter"='plan_psector_vdefault' AND cur_user=current_user); - + SELECT value::boolean into v_auto_sander FROM config_param_system WHERE parameter='edit_node_automatic_sander'; IF TG_OP = 'INSERT' OR TG_OP = 'UPDATE' THEN @@ -63,19 +63,19 @@ BEGIN EXECUTE 'SELECT gw_fct_getmessage($${"client":{"device":4, "infoType":1, "lang":"ES"},"feature":{}, "data":{"message":"3246", "function":"1202","debug_msg":null}}$$);'; END IF; - + -- transforming streetaxis name into id v_streetaxis = (SELECT id FROM v_ext_streetaxis WHERE (muni_id = NEW.muni_id OR muni_id IS NULL) AND descript = NEW.streetname LIMIT 1); v_streetaxis2 = (SELECT id FROM v_ext_streetaxis WHERE (muni_id = NEW.muni_id OR muni_id IS NULL) AND descript = NEW.streetname2 LIMIT 1); - + -- managing matcat IF (SELECT matcat_id FROM cat_arc WHERE id = NEW.arccat_id) IS NOT NULL THEN v_matfromcat = true; END IF; - - END IF; - IF TG_OP = 'INSERT' THEN + END IF; + + IF TG_OP = 'INSERT' THEN -- force current psector IF NEW.state = 2 THEN @@ -86,7 +86,7 @@ BEGIN IF NEW.arc_id != (SELECT last_value::text FROM urn_id_seq) OR NEW.arc_id IS NULL THEN NEW.arc_id = (SELECT nextval('urn_id_seq')); END IF; - + -- Arc type IF (NEW.arc_type IS NULL) THEN IF ((SELECT COUNT(*) FROM cat_feature_arc JOIN cat_feature USING (id) WHERE active IS TRUE) = 0) THEN @@ -107,7 +107,7 @@ BEGIN IF (NEW.arc_type IS NULL) AND v_man_table='parent' THEN NEW.arc_type:=(SELECT "value" FROM config_param_user WHERE "parameter"='edit_arctype_vdefault' AND "cur_user"="current_user"() LIMIT 1); END IF; - + IF (NEW.arc_type IS NULL) AND v_man_table !='parent' THEN NEW.arc_type:= (SELECT c.id FROM cat_feature_arc c JOIN sys_feature_cat s ON c.type = s.id WHERE man_table=v_type_v_man_table LIMIT 1); END IF; @@ -115,156 +115,156 @@ BEGIN -- Epa type IF (NEW.epa_type IS NULL) THEN - NEW.epa_type:= (SELECT epa_default FROM cat_feature_arc WHERE cat_feature_arc.id=NEW.arc_type)::text; + NEW.epa_type:= (SELECT epa_default FROM cat_feature_arc WHERE cat_feature_arc.id=NEW.arc_type)::text; END IF; - + -- Arc catalog ID IF (NEW.arccat_id IS NULL) THEN IF ((SELECT COUNT(*) FROM cat_arc WHERE active IS TRUE) = 0) THEN EXECUTE 'SELECT gw_fct_getmessage($${"client":{"device":4, "infoType":1, "lang":"ES"},"feature":{}, "data":{"message":"1020", "function":"1202","debug_msg":null}}$$);'; - END IF; + END IF; NEW.arccat_id:= (SELECT "value" FROM config_param_user WHERE "parameter"='edit_arccat_vdefault' AND "cur_user"="current_user"() LIMIT 1); IF (NEW.arccat_id IS NULL) THEN NEW.arccat_id := (SELECT arccat_id from arc WHERE ST_DWithin(NEW.the_geom, arc.the_geom,0.001) LIMIT 1); END IF; END IF; - - + + -- Exploitation IF (NEW.expl_id IS NULL) THEN - + -- control error without any mapzones defined on the table of mapzone IF ((SELECT COUNT(*) FROM exploitation WHERE active IS TRUE) = 0) THEN EXECUTE 'SELECT gw_fct_getmessage($${"client":{"device":4, "infoType":1, "lang":"ES"},"feature":{}, "data":{"message":"1110", "function":"1202","debug_msg":null}}$$);'; END IF; - + -- getting value default IF (NEW.expl_id IS NULL) THEN NEW.expl_id := (SELECT "value" FROM config_param_user WHERE "parameter"='edit_exploitation_vdefault' AND "cur_user"="current_user"() LIMIT 1); END IF; - + -- getting value from geometry of mapzone IF (NEW.expl_id IS NULL) THEN SELECT count(*) INTO v_count FROM exploitation WHERE ST_DWithin(NEW.the_geom, exploitation.the_geom,0.001) AND active IS TRUE; IF v_count = 1 THEN NEW.expl_id = (SELECT expl_id FROM exploitation WHERE ST_DWithin(NEW.the_geom, exploitation.the_geom,0.001) AND active IS TRUE LIMIT 1); ELSE - NEW.expl_id =(SELECT expl_id FROM v_edit_arc WHERE ST_DWithin(NEW.the_geom, v_edit_arc.the_geom, v_promixity_buffer) + NEW.expl_id =(SELECT expl_id FROM v_edit_arc WHERE ST_DWithin(NEW.the_geom, v_edit_arc.the_geom, v_promixity_buffer) order by ST_Distance (NEW.the_geom, v_edit_arc.the_geom) LIMIT 1); - END IF; + END IF; END IF; - + -- control error when no value IF (NEW.expl_id IS NULL) THEN EXECUTE 'SELECT gw_fct_getmessage($${"client":{"device":4, "infoType":1, "lang":"ES"},"feature":{}, "data":{"message":"2012", "function":"1202","debug_msg":"'||NEW.arc_id::text||'"}}$$);'; - END IF; + END IF; END IF; - - + + -- Sector ID IF (NEW.sector_id IS NULL ) THEN - + -- control error without any mapzones defined on the table of mapzone IF ((SELECT COUNT(*) FROM sector WHERE active IS TRUE) = 0) THEN EXECUTE 'SELECT gw_fct_getmessage($${"client":{"device":4, "infoType":1, "lang":"ES"},"feature":{}, "data":{"message":"1008", "function":"1202","debug_msg":null}}$$);'; END IF; - + -- getting value default IF (NEW.sector_id IS NULL) THEN NEW.sector_id := (SELECT "value" FROM config_param_user WHERE "parameter"='edit_sector_vdefault' AND "cur_user"="current_user"() LIMIT 1); END IF; - + -- getting value from geometry of mapzone IF (NEW.sector_id IS NULL) THEN SELECT count(*) INTO v_count FROM sector WHERE ST_DWithin(NEW.the_geom, sector.the_geom,0.001) AND active IS TRUE; IF v_count = 1 THEN NEW.sector_id = (SELECT sector_id FROM sector WHERE ST_DWithin(NEW.the_geom, sector.the_geom,0.001) AND active IS TRUE LIMIT 1); ELSE - NEW.sector_id =(SELECT sector_id FROM v_edit_arc WHERE ST_DWithin(NEW.the_geom, v_edit_arc.the_geom, v_promixity_buffer) + NEW.sector_id =(SELECT sector_id FROM v_edit_arc WHERE ST_DWithin(NEW.the_geom, v_edit_arc.the_geom, v_promixity_buffer) order by ST_Distance (NEW.the_geom, v_edit_arc.the_geom) LIMIT 1); - END IF; + END IF; END IF; - + -- control error when no value IF (NEW.sector_id IS NULL) THEN NEW.sector_id = 0; - END IF; + END IF; END IF; - - + + -- Dma ID IF (NEW.dma_id IS NULL) THEN - + -- control error without any mapzones defined on the table of mapzone IF ((SELECT COUNT(*) FROM dma WHERE active IS TRUE) = 0) THEN EXECUTE 'SELECT gw_fct_getmessage($${"client":{"device":4, "infoType":1, "lang":"ES"},"feature":{}, "data":{"message":"1012", "function":"1202","debug_msg":null}}$$);'; END IF; - + -- getting value default IF (NEW.dma_id IS NULL) THEN NEW.dma_id := (SELECT "value" FROM config_param_user WHERE "parameter"='edit_dma_vdefault' AND "cur_user"="current_user"() LIMIT 1); END IF; - + -- getting value from geometry of mapzone IF (NEW.dma_id IS NULL) THEN SELECT count(*) INTO v_count FROM dma WHERE ST_DWithin(NEW.the_geom, dma.the_geom,0.001) AND active IS TRUE; IF v_count = 1 THEN NEW.dma_id = (SELECT dma_id FROM dma WHERE ST_DWithin(NEW.the_geom, dma.the_geom,0.001) AND active IS TRUE LIMIT 1); ELSE - NEW.dma_id =(SELECT dma_id FROM v_edit_arc WHERE ST_DWithin(NEW.the_geom, v_edit_arc.the_geom, v_promixity_buffer) + NEW.dma_id =(SELECT dma_id FROM v_edit_arc WHERE ST_DWithin(NEW.the_geom, v_edit_arc.the_geom, v_promixity_buffer) order by ST_Distance (NEW.the_geom, v_edit_arc.the_geom) LIMIT 1); - END IF; + END IF; END IF; - + -- control error when no value IF (NEW.dma_id IS NULL) THEN NEW.dma_id = 0; - END IF; + END IF; END IF; - - - -- Municipality + + + -- Municipality IF (NEW.muni_id IS NULL) THEN - + -- getting value default IF (NEW.muni_id IS NULL) THEN NEW.muni_id := (SELECT "value" FROM config_param_user WHERE "parameter"='edit_municipality_vdefault' AND "cur_user"="current_user"() LIMIT 1); END IF; - + -- getting value from geometry of mapzone IF (NEW.muni_id IS NULL) THEN SELECT count(*) INTO v_count FROM ext_municipality WHERE ST_DWithin(NEW.the_geom, ext_municipality.the_geom,0.001); IF v_count = 1 THEN - NEW.muni_id = (SELECT muni_id FROM ext_municipality WHERE ST_DWithin(NEW.the_geom, ext_municipality.the_geom,0.001) + NEW.muni_id = (SELECT muni_id FROM ext_municipality WHERE ST_DWithin(NEW.the_geom, ext_municipality.the_geom,0.001) AND active IS TRUE LIMIT 1); ELSE - NEW.muni_id =(SELECT muni_id FROM v_edit_arc WHERE ST_DWithin(NEW.the_geom, v_edit_arc.the_geom, v_promixity_buffer) + NEW.muni_id =(SELECT muni_id FROM v_edit_arc WHERE ST_DWithin(NEW.the_geom, v_edit_arc.the_geom, v_promixity_buffer) order by ST_Distance (NEW.the_geom, v_edit_arc.the_geom) LIMIT 1); - END IF; - END IF; + END IF; + END IF; END IF; - - -- District + + -- District IF (NEW.district_id IS NULL) THEN - + -- getting value from geometry of mapzone IF (NEW.district_id IS NULL) THEN SELECT count(*) INTO v_count FROM ext_district WHERE ST_DWithin(NEW.the_geom, ext_district.the_geom,0.001); IF v_count = 1 THEN NEW.district_id = (SELECT district_id FROM ext_district WHERE ST_DWithin(NEW.the_geom, ext_district.the_geom,0.001) LIMIT 1); ELSIF v_count > 1 THEN - NEW.district_id =(SELECT district_id FROM v_edit_arc WHERE ST_DWithin(NEW.the_geom, v_edit_arc.the_geom, v_promixity_buffer) + NEW.district_id =(SELECT district_id FROM v_edit_arc WHERE ST_DWithin(NEW.the_geom, v_edit_arc.the_geom, v_promixity_buffer) order by ST_Distance (NEW.the_geom, v_edit_arc.the_geom) LIMIT 1); - END IF; - END IF; + END IF; + END IF; END IF; - - + + -- Verified IF (NEW.verified IS NULL) THEN NEW.verified := (SELECT "value" FROM config_param_user WHERE "parameter"='edit_verified_vdefault' AND "cur_user"="current_user"() LIMIT 1); @@ -274,7 +274,7 @@ BEGIN IF (NEW.state IS NULL) THEN NEW.state := (SELECT "value" FROM config_param_user WHERE "parameter"='edit_state_vdefault' AND "cur_user"="current_user"() LIMIT 1); END IF; - + -- State_type IF (NEW.state=0) THEN IF (NEW.state_type IS NULL) THEN @@ -298,40 +298,40 @@ BEGIN v_sql = 'null'; END IF; EXECUTE 'SELECT gw_fct_getmessage($${"client":{"device":4, "infoType":1, "lang":"ES"},"feature":{}, - "data":{"message":"3036", "function":"1202","debug_msg":"'||v_sql::text||'"}}$$);'; - END IF; - + "data":{"message":"3036", "function":"1202","debug_msg":"'||v_sql::text||'"}}$$);'; + END IF; + --Inventory IF NEW.inventory IS NULL THEN NEW.inventory := (SELECT "value" FROM config_param_system WHERE "parameter"='edit_inventory_sysvdefault'); END IF; - + --Publish IF NEW.publish IS NULL THEN NEW.publish := (SELECT "value" FROM config_param_system WHERE "parameter"='edit_publish_sysvdefault'); - END IF; - + END IF; + --Uncertain IF NEW.uncertain IS NULL THEN NEW.uncertain := (SELECT "value" FROM config_param_system WHERE "parameter"='edit_uncertain_sysvdefault'); END IF; - + -- Workcat_id IF (NEW.workcat_id IS NULL) THEN NEW.workcat_id := (SELECT "value" FROM config_param_user WHERE "parameter"='edit_workcat_vdefault' AND "cur_user"="current_user"() LIMIT 1); END IF; - + --Workcat_id_plan IF (NEW.workcat_id_plan IS NULL AND NEW.state = 2) THEN NEW.workcat_id_plan := (SELECT "value" FROM config_param_user WHERE "parameter"='edit_workcat_id_plan' AND "cur_user"="current_user"() LIMIT 1); END IF; - + -- Ownercat_id IF (NEW.ownercat_id IS NULL) THEN NEW.ownercat_id := (SELECT "value" FROM config_param_user WHERE "parameter"='edit_ownercat_vdefault' AND "cur_user"="current_user"() LIMIT 1); END IF; - + -- Soilcat_id IF (NEW.soilcat_id IS NULL) THEN NEW.soilcat_id := (SELECT "value" FROM config_param_user WHERE "parameter"='edit_soilcat_vdefault' AND "cur_user"="current_user"() LIMIT 1); @@ -353,17 +353,17 @@ BEGIN -- use specific sequence for code when its name matches featurecat_code_seq EXECUTE 'SELECT concat('||quote_literal(lower(v_featurecat))||',''_code_seq'');' INTO v_seq_name; EXECUTE 'SELECT relname FROM pg_catalog.pg_class WHERE relname='||quote_literal(v_seq_name)||';' INTO v_sql; - + IF v_sql IS NOT NULL AND NEW.code IS NULL THEN EXECUTE 'SELECT nextval('||quote_literal(v_seq_name)||');' INTO v_seq_code; NEW.code=concat(v_code_prefix,v_seq_code); END IF; - - IF (v_code_autofill_bool IS TRUE) AND NEW.code IS NULL THEN + + IF (v_code_autofill_bool IS TRUE) AND NEW.code IS NULL THEN NEW.code=NEW.arc_id; END IF; END IF; - + -- LINK IF (SELECT (value::json->>'fid')::boolean FROM config_param_system WHERE parameter='edit_custom_link') IS TRUE THEN NEW.link=NEW.arc_id; @@ -394,7 +394,7 @@ BEGIN IF NEW.category_type IS NULL THEN NEW.category_type = (SELECT value FROM config_param_user WHERE parameter = 'edit_arc_category_vdefault' AND cur_user = current_user); - END IF; + END IF; --Function type IF NEW.function_type IS NULL AND (SELECT value FROM config_param_user WHERE parameter = 'edit_feature_function_vdefault' AND cur_user = current_user) = v_featurecat THEN @@ -409,38 +409,38 @@ BEGIN IF NEW.pavcat_id IS NULL THEN NEW.pavcat_id = (SELECT value FROM config_param_user WHERE parameter = 'edit_pavementcat_vdefault' AND cur_user = current_user); END IF; - + -- FEATURE INSERT IF v_matfromcat THEN INSERT INTO arc (arc_id, code, node_1, node_2, y1, y2, custom_y1, custom_y2, elev1, elev2, custom_elev1, custom_elev2, arc_type, arccat_id, epa_type, sector_id, "state", state_type, - annotation, observ, "comment", inverted_slope, custom_length, dma_id, soilcat_id, function_type, category_type, fluid_type, location_type, workcat_id, workcat_id_end, workcat_id_plan, buildercat_id, - builtdate, enddate, ownercat_id, muni_id, streetaxis_id, postcode, district_id, streetaxis2_id, postnumber, postnumber2, postcomplement, postcomplement2, descript, link, verified, - the_geom,undelete,label_x,label_y, label_rotation, expl_id, publish, inventory, uncertain, num_value, lastupdate, lastupdate_user, asset_id, pavcat_id, - drainzone_id, parent_id, expl_id2, adate, adescript) - VALUES (NEW.arc_id, NEW.code, NEW.node_1, NEW.node_2, NEW.y1, NEW.y2, NEW.custom_y1, NEW.custom_y2, NEW.elev1, NEW.elev2, - NEW.custom_elev1, NEW.custom_elev2,NEW.arc_type, NEW.arccat_id, NEW.epa_type, NEW.sector_id, NEW.state, NEW.state_type, NEW.annotation, NEW.observ, NEW.comment, - NEW.inverted_slope, NEW.custom_length, NEW.dma_id, NEW.soilcat_id, NEW.function_type, NEW.category_type, NEW.fluid_type, - NEW.location_type, NEW.workcat_id,NEW.workcat_id_end, NEW.workcat_id_plan,NEW.buildercat_id, NEW.builtdate, NEW.enddate, NEW.ownercat_id, + annotation, observ, "comment", inverted_slope, custom_length, dma_id, soilcat_id, function_type, category_type, fluid_type, location_type, workcat_id, workcat_id_end, workcat_id_plan, buildercat_id, + builtdate, enddate, ownercat_id, muni_id, streetaxis_id, postcode, district_id, streetaxis2_id, postnumber, postnumber2, postcomplement, postcomplement2, descript, link, verified, + the_geom,undelete,label_x,label_y, label_rotation, expl_id, publish, inventory, uncertain, num_value, lastupdate, lastupdate_user, asset_id, pavcat_id, + drainzone_id, parent_id, expl_id2, adate, adescript, placement_type) + VALUES (NEW.arc_id, NEW.code, NEW.node_1, NEW.node_2, NEW.y1, NEW.y2, NEW.custom_y1, NEW.custom_y2, NEW.elev1, NEW.elev2, + NEW.custom_elev1, NEW.custom_elev2,NEW.arc_type, NEW.arccat_id, NEW.epa_type, NEW.sector_id, NEW.state, NEW.state_type, NEW.annotation, NEW.observ, NEW.comment, + NEW.inverted_slope, NEW.custom_length, NEW.dma_id, NEW.soilcat_id, NEW.function_type, NEW.category_type, NEW.fluid_type, + NEW.location_type, NEW.workcat_id,NEW.workcat_id_end, NEW.workcat_id_plan,NEW.buildercat_id, NEW.builtdate, NEW.enddate, NEW.ownercat_id, NEW.muni_id, v_streetaxis, NEW.postcode, NEW.district_id, v_streetaxis2, NEW.postnumber, NEW.postnumber2, NEW.postcomplement, NEW.postcomplement2, - NEW.descript, NEW.link, NEW.verified, NEW.the_geom,NEW.undelete,NEW.label_x, + NEW.descript, NEW.link, NEW.verified, NEW.the_geom,NEW.undelete,NEW.label_x, NEW.label_y, NEW.label_rotation, NEW.expl_id, NEW.publish, NEW.inventory, NEW.uncertain, NEW.num_value, NEW.lastupdate, NEW.lastupdate_user, NEW.asset_id, NEW.pavcat_id, - NEW.drainzone_id, NEW.parent_id, NEW.expl_id2, NEW.adate, NEW.adescript); + NEW.drainzone_id, NEW.parent_id, NEW.expl_id2, NEW.adate, NEW.adescript, NEW.placement_type); ELSE INSERT INTO arc (arc_id, code, y1, y2, custom_y1, custom_y2, elev1, elev2, custom_elev1, custom_elev2, arc_type, arccat_id, epa_type, sector_id, "state", state_type, - annotation, observ, "comment", inverted_slope, custom_length, dma_id, soilcat_id, function_type, category_type, fluid_type, location_type, workcat_id, workcat_id_end, workcat_id_plan, buildercat_id, - builtdate, enddate, ownercat_id, muni_id, streetaxis_id, postcode, district_id, streetaxis2_id, postnumber, postnumber2, postcomplement, postcomplement2, descript, link, verified, + annotation, observ, "comment", inverted_slope, custom_length, dma_id, soilcat_id, function_type, category_type, fluid_type, location_type, workcat_id, workcat_id_end, workcat_id_plan, buildercat_id, + builtdate, enddate, ownercat_id, muni_id, streetaxis_id, postcode, district_id, streetaxis2_id, postnumber, postnumber2, postcomplement, postcomplement2, descript, link, verified, the_geom,undelete,label_x,label_y, label_rotation, expl_id, publish, inventory, uncertain, num_value, matcat_id, lastupdate, lastupdate_user, asset_id, pavcat_id, - drainzone_id, parent_id, expl_id2, adate, adescript) - VALUES (NEW.arc_id, NEW.code, NEW.y1, NEW.y2, NEW.custom_y1, NEW.custom_y2, NEW.elev1, NEW.elev2, - NEW.custom_elev1, NEW.custom_elev2,NEW.arc_type, NEW.arccat_id, NEW.epa_type, NEW.sector_id, NEW.state, NEW.state_type, NEW.annotation, NEW.observ, NEW.comment, - NEW.inverted_slope, NEW.custom_length, NEW.dma_id, NEW.soilcat_id, NEW.function_type, NEW.category_type, NEW.fluid_type, - NEW.location_type, NEW.workcat_id,NEW.workcat_id_end, NEW.workcat_id_plan, NEW.buildercat_id, NEW.builtdate, NEW.enddate, NEW.ownercat_id, + drainzone_id, parent_id, expl_id2, adate, adescript, placement_type) + VALUES (NEW.arc_id, NEW.code, NEW.y1, NEW.y2, NEW.custom_y1, NEW.custom_y2, NEW.elev1, NEW.elev2, + NEW.custom_elev1, NEW.custom_elev2,NEW.arc_type, NEW.arccat_id, NEW.epa_type, NEW.sector_id, NEW.state, NEW.state_type, NEW.annotation, NEW.observ, NEW.comment, + NEW.inverted_slope, NEW.custom_length, NEW.dma_id, NEW.soilcat_id, NEW.function_type, NEW.category_type, NEW.fluid_type, + NEW.location_type, NEW.workcat_id,NEW.workcat_id_end, NEW.workcat_id_plan, NEW.buildercat_id, NEW.builtdate, NEW.enddate, NEW.ownercat_id, NEW.muni_id, v_streetaxis, NEW.postcode, NEW.district_id, v_streetaxis2, NEW.postnumber, NEW.postnumber2, NEW.postcomplement, NEW.postcomplement2, - NEW.descript, NEW.link, NEW.verified, NEW.the_geom,NEW.undelete,NEW.label_x, - NEW.label_y, NEW.label_rotation, NEW.expl_id, NEW.publish, NEW.inventory, NEW.uncertain, NEW.num_value, NEW.matcat_id, NEW.lastupdate, NEW.lastupdate_user, - NEW.asset_id, NEW.pavcat_id, NEW.drainzone_id, NEW.parent_id, NEW.expl_id2, NEW.adate, NEW.adescript); + NEW.descript, NEW.link, NEW.verified, NEW.the_geom,NEW.undelete,NEW.label_x, + NEW.label_y, NEW.label_rotation, NEW.expl_id, NEW.publish, NEW.inventory, NEW.uncertain, NEW.num_value, NEW.matcat_id, NEW.lastupdate, NEW.lastupdate_user, + NEW.asset_id, NEW.pavcat_id, NEW.drainzone_id, NEW.parent_id, NEW.expl_id2, NEW.adate, NEW.adescript, NEW.placement_type); END IF; - + -- this overwrites triger topocontrol arc values (triggered before insertion) just in that moment: In order to make more profilactic this issue only will be overwrited in case of NEW.node_* not nulls IF v_edit_enable_arc_nodes_update IS TRUE THEN IF NEW.node_1 IS NOT NULL THEN @@ -450,55 +450,55 @@ BEGIN UPDATE arc SET node_2=NEW.node_2 WHERE arc_id=NEW.arc_id; END IF; END IF; - + IF v_man_table='man_conduit' THEN - + INSERT INTO man_conduit VALUES (NEW.arc_id, NEW.inlet_offset, NEW.bottom_mat); - + ELSIF v_man_table='man_siphon' THEN - + INSERT INTO man_siphon (arc_id,name) VALUES (NEW.arc_id,NEW.name); - + ELSIF v_man_table='man_waccel' THEN - - INSERT INTO man_waccel (arc_id, sander_length,sander_depth,prot_surface,accessibility, name) + + INSERT INTO man_waccel (arc_id, sander_length,sander_depth,prot_surface,accessibility, name) VALUES (NEW.arc_id, NEW.sander_length, NEW.sander_depth,NEW.prot_surface,NEW.accessibility, NEW.name); - + ELSIF v_man_table='man_varc' THEN - + INSERT INTO man_varc (arc_id) VALUES (NEW.arc_id); - + ELSIF v_man_table='parent' THEN v_man_table := (SELECT man_table FROM cat_feature_arc c JOIN sys_feature_cat s ON c.type = s.id WHERE c.id=NEW.arc_type); - v_sql:= 'INSERT INTO '||v_man_table||' (arc_id) VALUES ('||quote_literal(NEW.arc_id)||')'; - EXECUTE v_sql; - + v_sql:= 'INSERT INTO '||v_man_table||' (arc_id) VALUES ('||quote_literal(NEW.arc_id)||')'; + EXECUTE v_sql; + END IF; --sander calculation IF v_auto_sander IS TRUE THEN EXECUTE 'SELECT gw_fct_calculate_sander($${"client":{"device":4, "infoType":1, "lang":"ES"},"feature":{"id":"'||NEW.node_1||'"}}$$)'; - END IF; - + END IF; + -- EPA INSERT - IF (NEW.epa_type = 'CONDUIT') THEN - INSERT INTO inp_conduit (arc_id, q0, qmax) VALUES (NEW.arc_id,0,0); - - ELSIF (NEW.epa_type = 'PUMP') THEN - INSERT INTO inp_pump (arc_id) VALUES (NEW.arc_id); - - ELSIF (NEW.epa_type = 'ORIFICE') THEN + IF (NEW.epa_type = 'CONDUIT') THEN + INSERT INTO inp_conduit (arc_id, q0, qmax) VALUES (NEW.arc_id,0,0); + + ELSIF (NEW.epa_type = 'PUMP') THEN + INSERT INTO inp_pump (arc_id) VALUES (NEW.arc_id); + + ELSIF (NEW.epa_type = 'ORIFICE') THEN INSERT INTO inp_orifice (arc_id, ori_type) VALUES (NEW.arc_id,'BOTTOM'); - - ELSIF (NEW.epa_type = 'WEIR') THEN + + ELSIF (NEW.epa_type = 'WEIR') THEN INSERT INTO inp_weir (arc_id, weir_type) VALUES (NEW.arc_id,'SIDEFLOW'); - - ELSIF (NEW.epa_type = 'OUTLET') THEN + + ELSIF (NEW.epa_type = 'OUTLET') THEN INSERT INTO inp_outlet (arc_id, outlet_type) VALUES (NEW.arc_id,'TABULAR/HEAD'); - - ELSIF (NEW.epa_type = 'VIRTUAL') THEN + + ELSIF (NEW.epa_type = 'VIRTUAL') THEN INSERT INTO inp_virtual (arc_id, add_length) VALUES (NEW.arc_id, false); - + END IF; -- childtable insert @@ -517,11 +517,11 @@ BEGIN END LOOP; END IF; - + RETURN NEW; - + ELSIF TG_OP = 'UPDATE' THEN - + -- this overwrites triger topocontrol arc values (triggered before insertion) just in that moment: In order to make more profilactic this issue only will be overwrited in case of NEW.node_* not nulls IF v_edit_enable_arc_nodes_update IS TRUE THEN IF NEW.node_1 IS NOT NULL THEN @@ -531,7 +531,7 @@ BEGIN UPDATE arc SET node_2=NEW.node_2 WHERE arc_id=NEW.arc_id; END IF; END IF; - + -- State IF (NEW.state != OLD.state) THEN UPDATE arc SET state=NEW.state WHERE arc_id = OLD.arc_id; @@ -541,13 +541,13 @@ BEGIN = 'plan_psector_vdefault'::text AND config_param_user.cur_user::name = "current_user"() LIMIT 1), 1, true); END IF; IF NEW.state = 1 AND OLD.state=2 THEN - DELETE FROM plan_psector_x_arc WHERE arc_id=NEW.arc_id; - END IF; + DELETE FROM plan_psector_x_arc WHERE arc_id=NEW.arc_id; + END IF; IF NEW.state=0 THEN UPDATE arc SET node_1=NULL, node_2=NULL WHERE arc_id = OLD.arc_id; END IF; END IF; - + -- State_type IF NEW.state=0 AND OLD.state=1 THEN IF (SELECT state FROM value_state_type WHERE id=NEW.state_type) != NEW.state THEN @@ -566,47 +566,47 @@ BEGIN IF (NEW.state_type != OLD.state_type) AND NEW.state_type NOT IN (SELECT id FROM value_state_type WHERE state = NEW.state) THEN EXECUTE 'SELECT gw_fct_getmessage($${"client":{"device":4, "infoType":1, "lang":"ES"},"feature":{}, "data":{"message":"3036", "function":"1202","debug_msg":"'||NEW.state::text||'"}}$$);'; - END IF; - + END IF; + -- The geom IF st_orderingequals(NEW.the_geom, OLD.the_geom) IS FALSE OR NEW.node_1 IS NULL OR NEW.node_2 IS NULL THEN UPDATE arc SET the_geom=NEW.the_geom WHERE arc_id = OLD.arc_id; END IF; - IF (NEW.epa_type != OLD.epa_type) THEN - - IF (OLD.epa_type = 'CONDUIT') THEN + IF (NEW.epa_type != OLD.epa_type) THEN + + IF (OLD.epa_type = 'CONDUIT') THEN v_inp_table:= 'inp_conduit'; - ELSIF (OLD.epa_type = 'PUMP') THEN + ELSIF (OLD.epa_type = 'PUMP') THEN v_inp_table:= 'inp_pump'; - ELSIF (OLD.epa_type = 'ORIFICE') THEN + ELSIF (OLD.epa_type = 'ORIFICE') THEN v_inp_table:= 'inp_orifice'; - ELSIF (OLD.epa_type = 'WEIR') THEN + ELSIF (OLD.epa_type = 'WEIR') THEN v_inp_table:= 'inp_weir'; - ELSIF (OLD.epa_type = 'OUTLET') THEN + ELSIF (OLD.epa_type = 'OUTLET') THEN v_inp_table:= 'inp_outlet'; - ELSIF (OLD.epa_type = 'VIRTUAL') THEN + ELSIF (OLD.epa_type = 'VIRTUAL') THEN v_inp_table:= 'inp_virtual'; END IF; - + IF v_inp_table IS NOT NULL THEN v_sql:= 'DELETE FROM '||v_inp_table||' WHERE arc_id = '||quote_literal(OLD.arc_id); EXECUTE v_sql; END IF; - + v_inp_table := NULL; - IF (NEW.epa_type = 'CONDUIT') THEN + IF (NEW.epa_type = 'CONDUIT') THEN v_inp_table:= 'inp_conduit'; - ELSIF (NEW.epa_type = 'PUMP') THEN + ELSIF (NEW.epa_type = 'PUMP') THEN v_inp_table:= 'inp_pump'; - ELSIF (NEW.epa_type = 'ORIFICE') THEN + ELSIF (NEW.epa_type = 'ORIFICE') THEN v_inp_table:= 'inp_orifice'; - ELSIF (NEW.epa_type = 'WEIR') THEN + ELSIF (NEW.epa_type = 'WEIR') THEN v_inp_table:= 'inp_weir'; - ELSIF (NEW.epa_type = 'OUTLET') THEN + ELSIF (NEW.epa_type = 'OUTLET') THEN v_inp_table:= 'inp_outlet'; - ELSIF (NEW.epa_type = 'VIRTUAL') THEN + ELSIF (NEW.epa_type = 'VIRTUAL') THEN v_inp_table:= 'inp_virtual'; END IF; IF v_inp_table IS NOT NULL THEN @@ -617,7 +617,7 @@ BEGIN END IF; -- UPDATE management values - IF (NEW.arc_type <> OLD.arc_type) THEN + IF (NEW.arc_type <> OLD.arc_type) THEN v_new_man_table:= (SELECT man_table FROM cat_feature_arc c JOIN sys_feature_cat s ON c.type = s.id WHERE c.id = NEW.arc_type); v_old_man_table:= (SELECT man_table FROM cat_feature_arc c JOIN sys_feature_cat s ON c.type = s.id WHERE c.id = OLD.arc_type); IF v_new_man_table IS NOT NULL THEN @@ -627,7 +627,7 @@ BEGIN EXECUTE v_sql; END IF; END IF; - + --link_path SELECT link_path INTO v_link_path FROM cat_feature WHERE id=NEW.arc_type; IF v_link_path IS NOT NULL THEN @@ -643,65 +643,65 @@ BEGIN (NEW.elev2 != OLD.elev2) OR (NEW.elev2 IS NULL AND OLD.elev2 IS NOT NULL) OR (NEW.elev2 IS NOT NULL AND OLD.elev2 IS NULL) OR (NEW.custom_elev1 != OLD.custom_elev1) OR (NEW.custom_elev1 IS NULL AND OLD.custom_elev1 IS NOT NULL) OR (NEW.custom_elev1 IS NOT NULL AND OLD.custom_elev1 IS NULL) OR (NEW.custom_elev2 != OLD.custom_elev2) OR (NEW.custom_elev2 IS NULL AND OLD.custom_elev2 IS NOT NULL) OR (NEW.custom_elev2 IS NOT NULL AND OLD.custom_elev2 IS NULL) OR - (NEW.inverted_slope::text != OLD.inverted_slope::text) OR (NEW.inverted_slope is null and OLD.inverted_slope is not null) - OR (NEW.inverted_slope is not null and OLD.inverted_slope is null) - THEN + (NEW.inverted_slope::text != OLD.inverted_slope::text) OR (NEW.inverted_slope is null and OLD.inverted_slope is not null) + OR (NEW.inverted_slope is not null and OLD.inverted_slope is null) + THEN UPDATE arc SET y1=NEW.y1, y2=NEW.y2, custom_y1=NEW.custom_y1, custom_y2=NEW.custom_y2, elev1=NEW.elev1, elev2=NEW.elev2, custom_elev1=NEW.custom_elev1, custom_elev2=NEW.custom_elev2, inverted_slope=NEW.inverted_slope WHERE arc_id=NEW.arc_id; END IF; - + -- parent table fields IF v_matfromcat THEN - - UPDATE arc + + UPDATE arc SET arc_type=NEW.arc_type, arccat_id=NEW.arccat_id, epa_type=NEW.epa_type, sector_id=NEW.sector_id, state_type=NEW.state_type, - annotation= NEW.annotation, "observ"=NEW.observ,"comment"=NEW.comment, custom_length=NEW.custom_length, dma_id=NEW.dma_id, - soilcat_id=NEW.soilcat_id, function_type=NEW.function_type, category_type=NEW.category_type, fluid_type=NEW.fluid_type,location_type=NEW.location_type, - workcat_id=NEW.workcat_id, buildercat_id=NEW.buildercat_id, builtdate=NEW.builtdate,ownercat_id=NEW.ownercat_id, muni_id=NEW.muni_id, streetaxis_id=v_streetaxis, - postcode=NEW.postcode, district_id = NEW.district_id, streetaxis2_id=v_streetaxis2, postcomplement=NEW.postcomplement, - postcomplement2=NEW.postcomplement2, postnumber=NEW.postnumber, postnumber2=NEW.postnumber2, descript=NEW.descript, link=NEW.link, + annotation= NEW.annotation, "observ"=NEW.observ,"comment"=NEW.comment, custom_length=NEW.custom_length, dma_id=NEW.dma_id, + soilcat_id=NEW.soilcat_id, function_type=NEW.function_type, category_type=NEW.category_type, fluid_type=NEW.fluid_type,location_type=NEW.location_type, + workcat_id=NEW.workcat_id, buildercat_id=NEW.buildercat_id, builtdate=NEW.builtdate,ownercat_id=NEW.ownercat_id, muni_id=NEW.muni_id, streetaxis_id=v_streetaxis, + postcode=NEW.postcode, district_id = NEW.district_id, streetaxis2_id=v_streetaxis2, postcomplement=NEW.postcomplement, + postcomplement2=NEW.postcomplement2, postnumber=NEW.postnumber, postnumber2=NEW.postnumber2, descript=NEW.descript, link=NEW.link, verified=NEW.verified, undelete=NEW.undelete,label_x=NEW.label_x, - label_y=NEW.label_y, label_rotation=NEW.label_rotation,workcat_id_end=NEW.workcat_id_end, workcat_id_plan=NEW.workcat_id_plan, code=NEW.code, publish=NEW.publish, inventory=NEW.inventory, + label_y=NEW.label_y, label_rotation=NEW.label_rotation,workcat_id_end=NEW.workcat_id_end, workcat_id_plan=NEW.workcat_id_plan, code=NEW.code, publish=NEW.publish, inventory=NEW.inventory, enddate=NEW.enddate, uncertain=NEW.uncertain, expl_id=NEW.expl_id, num_value = NEW.num_value,lastupdate=now(), lastupdate_user=current_user, - asset_id=NEW.asset_id, pavcat_id=NEW.pavcat_id, drainzone_id=NEW.drainzone_id, parent_id=NEW.parent_id, expl_id2=NEW.expl_id2, adate=NEW.adate, adescript=NEW.adescript - WHERE arc_id=OLD.arc_id; + asset_id=NEW.asset_id, pavcat_id=NEW.pavcat_id, drainzone_id=NEW.drainzone_id, parent_id=NEW.parent_id, expl_id2=NEW.expl_id2, adate=NEW.adate, adescript=NEW.adescript, placement_type=NEW.placement_type + WHERE arc_id=OLD.arc_id; ELSE UPDATE arc SET arc_type=NEW.arc_type, arccat_id=NEW.arccat_id, epa_type=NEW.epa_type, sector_id=NEW.sector_id, state_type=NEW.state_type, - annotation= NEW.annotation, "observ"=NEW.observ,"comment"=NEW.comment, custom_length=NEW.custom_length, dma_id=NEW.dma_id, - soilcat_id=NEW.soilcat_id, function_type=NEW.function_type, category_type=NEW.category_type, fluid_type=NEW.fluid_type,location_type=NEW.location_type, - workcat_id=NEW.workcat_id, buildercat_id=NEW.buildercat_id, builtdate=NEW.builtdate,ownercat_id=NEW.ownercat_id, muni_id=NEW.muni_id, streetaxis_id=v_streetaxis, - postcode=NEW.postcode, district_id=NEW.district_id, streetaxis2_id=v_streetaxis2, postcomplement=NEW.postcomplement, postcomplement2=NEW.postcomplement2, postnumber=NEW.postnumber, + annotation= NEW.annotation, "observ"=NEW.observ,"comment"=NEW.comment, custom_length=NEW.custom_length, dma_id=NEW.dma_id, + soilcat_id=NEW.soilcat_id, function_type=NEW.function_type, category_type=NEW.category_type, fluid_type=NEW.fluid_type,location_type=NEW.location_type, + workcat_id=NEW.workcat_id, buildercat_id=NEW.buildercat_id, builtdate=NEW.builtdate,ownercat_id=NEW.ownercat_id, muni_id=NEW.muni_id, streetaxis_id=v_streetaxis, + postcode=NEW.postcode, district_id=NEW.district_id, streetaxis2_id=v_streetaxis2, postcomplement=NEW.postcomplement, postcomplement2=NEW.postcomplement2, postnumber=NEW.postnumber, postnumber2=NEW.postnumber2, descript=NEW.descript, link=NEW.link, verified=NEW.verified, undelete=NEW.undelete,label_x=NEW.label_x, - label_y=NEW.label_y, label_rotation=NEW.label_rotation,workcat_id_end=NEW.workcat_id_end, workcat_id_plan=NEW.workcat_id_plan, code=NEW.code, publish=NEW.publish, inventory=NEW.inventory, + label_y=NEW.label_y, label_rotation=NEW.label_rotation,workcat_id_end=NEW.workcat_id_end, workcat_id_plan=NEW.workcat_id_plan, code=NEW.code, publish=NEW.publish, inventory=NEW.inventory, enddate=NEW.enddate, uncertain=NEW.uncertain, expl_id=NEW.expl_id, num_value = NEW.num_value,lastupdate=now(), lastupdate_user=current_user, matcat_id=NEW.matcat_id, - asset_id=NEW.asset_id, pavcat_id=NEW.pavcat_id, drainzone_id=NEW.drainzone_id, parent_id=NEW.parent_id, expl_id2=NEW.expl_id2, adate=NEW.adate, adescript=NEW.adescript - WHERE arc_id=OLD.arc_id; + asset_id=NEW.asset_id, pavcat_id=NEW.pavcat_id, drainzone_id=NEW.drainzone_id, parent_id=NEW.parent_id, expl_id2=NEW.expl_id2, adate=NEW.adate, adescript=NEW.adescript, placement_type=NEW.placement_type + WHERE arc_id=OLD.arc_id; END IF; -- child tables fields IF v_man_table='man_conduit' THEN UPDATE man_conduit SET arc_id=NEW.arc_id, inlet_offset = NEW.inlet_offset, bottom_mat=NEW.bottom_mat WHERE arc_id=OLD.arc_id; - - ELSIF v_man_table='man_siphon' THEN + + ELSIF v_man_table='man_siphon' THEN UPDATE man_siphon SET name=NEW.name WHERE arc_id=OLD.arc_id; - + ELSIF v_man_table='man_waccel' THEN - + UPDATE man_waccel SET sander_length=NEW.sander_length, sander_depth=NEW.sander_depth, prot_surface=NEW.prot_surface, accessibility=NEW.accessibility, name=NEW.name WHERE arc_id=OLD.arc_id; - + ELSIF v_man_table='man_varc' THEN - + UPDATE man_varc SET arc_id=NEW.arc_id WHERE arc_id=OLD.arc_id; - + END IF; --sander calculation @@ -733,8 +733,8 @@ BEGIN USING NEW.arc_id; END IF; END LOOP; - END IF; - + END IF; + --update values of related connecs; IF NEW.fluid_type != OLD.fluid_type AND v_autoupdate_fluid IS TRUE THEN UPDATE connec SET fluid_type = NEW.fluid_type WHERE arc_id = NEW.arc_id; @@ -758,18 +758,18 @@ BEGIN -- restore plan_psector_force_delete UPDATE config_param_user SET value = v_force_delete WHERE parameter = 'plan_psector_force_delete' and cur_user = current_user; - + -- Delete childtable addfields (after or before deletion of arc, doesn't matter) FOR v_addfields IN SELECT * FROM sys_addfields WHERE (cat_feature_id = v_customfeature OR cat_feature_id is null) AND active IS TRUE AND iseditable IS TRUE LOOP EXECUTE 'DELETE FROM man_arc_'||lower(v_addfields.cat_feature_id)||' WHERE arc_id = OLD.arc_id'; END LOOP; - + RETURN NULL; - + END IF; - + END; $BODY$ LANGUAGE plpgsql VOLATILE diff --git a/ud/ftrg/ud_gw_trg_edit_connec.sql b/ud/ftrg/ud_gw_trg_edit_connec.sql index 6b953e6ce7..db78ebf762 100644 --- a/ud/ftrg/ud_gw_trg_edit_connec.sql +++ b/ud/ftrg/ud_gw_trg_edit_connec.sql @@ -7,7 +7,7 @@ This version of Giswater is provided by Giswater Association --FUNCTION CODE: 1204 CREATE OR REPLACE FUNCTION "SCHEMA_NAME".gw_trg_edit_connec() RETURNS trigger AS $BODY$ -DECLARE +DECLARE v_link integer; v_sql varchar; @@ -64,19 +64,19 @@ BEGIN v_psector_vdefault = (SELECT config_param_user.value::integer AS value FROM config_param_user WHERE config_param_user.parameter::text = 'plan_psector_vdefault'::text AND config_param_user.cur_user::name = "current_user"() LIMIT 1); - - + + IF TG_OP = 'INSERT' OR TG_OP = 'UPDATE' THEN -- check if streetname exists IF NEW.streetname IS NOT NULL AND ((NEW.streetname NOT IN (SELECT DISTINCT descript FROM v_ext_streetaxis)) OR (NEW.streetname2 NOT IN (SELECT DISTINCT descript FROM v_ext_streetaxis))) THEN EXECUTE 'SELECT gw_fct_getmessage($${"client":{"device":4, "infoType":1, "lang":"ES"},"feature":{}, "data":{"message":"3246", "function":"1204","debug_msg":null}}$$);'; END IF; - + -- transforming streetaxis name into id v_streetaxis = (SELECT id FROM v_ext_streetaxis WHERE (muni_id = NEW.muni_id OR muni_id IS NULL) AND descript = NEW.streetname LIMIT 1); v_streetaxis2 = (SELECT id FROM v_ext_streetaxis WHERE (muni_id = NEW.muni_id OR muni_id IS NULL) AND descript = NEW.streetname2 LIMIT 1); - + -- managing matcat IF (SELECT matcat_id FROM cat_connec WHERE id = NEW.connecat_id) IS NOT NULL THEN v_matfromcat = true; @@ -89,13 +89,13 @@ BEGIN END IF; END IF; END IF; - + -- Control insertions ID IF TG_OP = 'INSERT' THEN -- setting psector vdefault as visible IF NEW.state = 2 THEN - INSERT INTO selector_psector (psector_id, cur_user) VALUES (v_psector_vdefault, current_user) + INSERT INTO selector_psector (psector_id, cur_user) VALUES (v_psector_vdefault, current_user) ON CONFLICT DO NOTHING; END IF; @@ -125,7 +125,7 @@ BEGIN END IF; END IF; END IF; - + -- connec Catalog ID IF (NEW.connecat_id IS NULL) THEN IF ((SELECT COUNT(*) FROM cat_connec WHERE active IS TRUE) = 0) THEN @@ -134,141 +134,141 @@ BEGIN END IF; NEW.connecat_id:= (SELECT "value" FROM config_param_user WHERE "parameter"='edit_connecat_vdefault' AND "cur_user"="current_user"() LIMIT 1); END IF; - + -- Exploitation IF (NEW.expl_id IS NULL) THEN - + -- control error without any mapzones defined on the table of mapzone IF ((SELECT COUNT(*) FROM exploitation WHERE active IS TRUE) = 0) THEN EXECUTE 'SELECT gw_fct_getmessage($${"client":{"device":4, "infoType":1, "lang":"ES"},"feature":{}, "data":{"message":"1110", "function":"1204","debug_msg":null}}$$);'; END IF; - + -- getting value default IF (NEW.expl_id IS NULL) THEN NEW.expl_id := (SELECT "value" FROM config_param_user WHERE "parameter"='edit_exploitation_vdefault' AND "cur_user"="current_user"() LIMIT 1); END IF; - + -- getting value from geometry of mapzone IF (NEW.expl_id IS NULL) THEN SELECT count(*) INTO v_count FROM exploitation WHERE ST_DWithin(NEW.the_geom, exploitation.the_geom,0.001) AND active IS TRUE; IF v_count = 1 THEN NEW.expl_id = (SELECT expl_id FROM exploitation WHERE ST_DWithin(NEW.the_geom, exploitation.the_geom,0.001) AND active IS TRUE LIMIT 1); ELSE - NEW.expl_id =(SELECT expl_id FROM v_edit_arc WHERE ST_DWithin(NEW.the_geom, v_edit_arc.the_geom, v_promixity_buffer) + NEW.expl_id =(SELECT expl_id FROM v_edit_arc WHERE ST_DWithin(NEW.the_geom, v_edit_arc.the_geom, v_promixity_buffer) order by ST_Distance (NEW.the_geom, v_edit_arc.the_geom) LIMIT 1); - END IF; + END IF; END IF; - + -- control error when no value IF (NEW.expl_id IS NULL) THEN EXECUTE 'SELECT gw_fct_getmessage($${"client":{"device":4, "infoType":1, "lang":"ES"},"feature":{}, "data":{"message":"2012", "function":"1204","debug_msg":"'||NEW.connec_id::text||'"}}$$);'; - END IF; + END IF; END IF; - - + + -- Sector ID IF (NEW.sector_id IS NULL) THEN - + -- control error without any mapzones defined on the table of mapzone IF ((SELECT COUNT(*) FROM sector WHERE active IS TRUE ) = 0) THEN EXECUTE 'SELECT gw_fct_getmessage($${"client":{"device":4, "infoType":1, "lang":"ES"},"feature":{}, "data":{"message":"1008", "function":"1204","debug_msg":null}}$$);'; END IF; - + -- getting value default IF (NEW.sector_id IS NULL) THEN NEW.sector_id := (SELECT "value" FROM config_param_user WHERE "parameter"='edit_sector_vdefault' AND "cur_user"="current_user"() LIMIT 1); END IF; - + -- getting value from geometry of mapzone IF (NEW.sector_id IS NULL) THEN SELECT count(*) INTO v_count FROM sector WHERE ST_DWithin(NEW.the_geom, sector.the_geom,0.001) AND active IS TRUE ; IF v_count = 1 THEN NEW.sector_id = (SELECT sector_id FROM sector WHERE ST_DWithin(NEW.the_geom, sector.the_geom,0.001) AND active IS TRUE LIMIT 1); ELSE - NEW.sector_id =(SELECT sector_id FROM v_edit_arc WHERE ST_DWithin(NEW.the_geom, v_edit_arc.the_geom, v_promixity_buffer) + NEW.sector_id =(SELECT sector_id FROM v_edit_arc WHERE ST_DWithin(NEW.the_geom, v_edit_arc.the_geom, v_promixity_buffer) order by ST_Distance (NEW.the_geom, v_edit_arc.the_geom) LIMIT 1); - END IF; + END IF; END IF; - + -- control error when no value IF (NEW.sector_id IS NULL) THEN NEW.sector_id = 0; - END IF; + END IF; END IF; - - + + -- Dma ID IF (NEW.dma_id IS NULL) THEN - + -- control error without any mapzones defined on the table of mapzone IF ((SELECT COUNT(*) FROM dma WHERE active IS TRUE ) = 0) THEN EXECUTE 'SELECT gw_fct_getmessage($${"client":{"device":4, "infoType":1, "lang":"ES"},"feature":{}, "data":{"message":"1012", "function":"1204","debug_msg":null}}$$);'; END IF; - + -- getting value default IF (NEW.dma_id IS NULL) THEN NEW.dma_id := (SELECT "value" FROM config_param_user WHERE "parameter"='edit_dma_vdefault' AND "cur_user"="current_user"() LIMIT 1); END IF; - + -- getting value from geometry of mapzone IF (NEW.dma_id IS NULL) THEN SELECT count(*) INTO v_count FROM dma WHERE ST_DWithin(NEW.the_geom, dma.the_geom,0.001) AND active IS TRUE ; IF v_count = 1 THEN NEW.dma_id = (SELECT dma_id FROM dma WHERE ST_DWithin(NEW.the_geom, dma.the_geom,0.001) AND active IS TRUE LIMIT 1); ELSE - NEW.dma_id =(SELECT dma_id FROM v_edit_arc WHERE ST_DWithin(NEW.the_geom, v_edit_arc.the_geom, v_promixity_buffer) + NEW.dma_id =(SELECT dma_id FROM v_edit_arc WHERE ST_DWithin(NEW.the_geom, v_edit_arc.the_geom, v_promixity_buffer) order by ST_Distance (NEW.the_geom, v_edit_arc.the_geom) LIMIT 1); - END IF; + END IF; END IF; - + -- control error when no value IF (NEW.dma_id IS NULL) THEN NEW.dma_id = 0; - END IF; + END IF; END IF; - - - -- Municipality + + + -- Municipality IF (NEW.muni_id IS NULL) THEN - + -- getting value default IF (NEW.muni_id IS NULL) THEN NEW.muni_id := (SELECT "value" FROM config_param_user WHERE "parameter"='edit_municipality_vdefault' AND "cur_user"="current_user"() LIMIT 1); END IF; - + -- getting value from geometry of mapzone IF (NEW.muni_id IS NULL) THEN SELECT count(*) INTO v_count FROM ext_municipality WHERE ST_DWithin(NEW.the_geom, ext_municipality.the_geom,0.001) AND active IS TRUE ; IF v_count = 1 THEN - NEW.muni_id = (SELECT muni_id FROM ext_municipality WHERE ST_DWithin(NEW.the_geom, ext_municipality.the_geom,0.001) + NEW.muni_id = (SELECT muni_id FROM ext_municipality WHERE ST_DWithin(NEW.the_geom, ext_municipality.the_geom,0.001) AND active IS TRUE LIMIT 1); ELSE - NEW.muni_id =(SELECT muni_id FROM v_edit_arc WHERE ST_DWithin(NEW.the_geom, v_edit_arc.the_geom, v_promixity_buffer) + NEW.muni_id =(SELECT muni_id FROM v_edit_arc WHERE ST_DWithin(NEW.the_geom, v_edit_arc.the_geom, v_promixity_buffer) order by ST_Distance (NEW.the_geom, v_edit_arc.the_geom) LIMIT 1); - END IF; - END IF; + END IF; + END IF; END IF; - - -- District + + -- District IF (NEW.district_id IS NULL) THEN - + -- getting value from geometry of mapzone IF (NEW.district_id IS NULL) THEN SELECT count(*) INTO v_count FROM ext_district WHERE ST_DWithin(NEW.the_geom, ext_district.the_geom,0.001); IF v_count = 1 THEN NEW.district_id = (SELECT district_id FROM ext_district WHERE ST_DWithin(NEW.the_geom, ext_district.the_geom,0.001) LIMIT 1); ELSIF v_count > 1 THEN - NEW.district_id =(SELECT district_id FROM v_edit_arc WHERE ST_DWithin(NEW.the_geom, v_edit_arc.the_geom, v_promixity_buffer) + NEW.district_id =(SELECT district_id FROM v_edit_arc WHERE ST_DWithin(NEW.the_geom, v_edit_arc.the_geom, v_promixity_buffer) order by ST_Distance (NEW.the_geom, v_edit_arc.the_geom) LIMIT 1); - END IF; - END IF; + END IF; + END IF; END IF; - - + + -- Verified IF (NEW.verified IS NULL) THEN NEW.verified := (SELECT "value" FROM config_param_user WHERE "parameter"='edit_verified_vdefault' AND "cur_user"="current_user"() LIMIT 1); @@ -278,7 +278,7 @@ BEGIN IF (NEW.state IS NULL) THEN NEW.state := (SELECT "value" FROM config_param_user WHERE "parameter"='edit_state_vdefault' AND "cur_user"="current_user"() LIMIT 1); END IF; - + -- State_type IF (NEW.state=0) THEN IF (NEW.state_type IS NULL) THEN @@ -302,30 +302,30 @@ BEGIN v_sql = 'null'; END IF; EXECUTE 'SELECT gw_fct_getmessage($${"client":{"device":4, "infoType":1, "lang":"ES"},"feature":{}, - "data":{"message":"3036", "function":"1204","debug_msg":"'||v_sql::text||'"}}$$);'; - END IF; + "data":{"message":"3036", "function":"1204","debug_msg":"'||v_sql::text||'"}}$$);'; + END IF; -- Workcat_id IF (NEW.workcat_id IS NULL) THEN NEW.workcat_id := (SELECT "value" FROM config_param_user WHERE "parameter"='edit_workcat_vdefault' AND "cur_user"="current_user"() LIMIT 1); END IF; - + --Workcat_id_plan IF (NEW.workcat_id_plan IS NULL AND NEW.state = 2) THEN NEW.workcat_id_plan := (SELECT "value" FROM config_param_user WHERE "parameter"='edit_workcat_id_plan' AND "cur_user"="current_user"() LIMIT 1); END IF; - + -- Ownercat_id IF (NEW.ownercat_id IS NULL) THEN NEW.ownercat_id := (SELECT "value" FROM config_param_user WHERE "parameter"='edit_ownercat_vdefault' AND "cur_user"="current_user"() LIMIT 1); END IF; - + -- Soilcat_id IF (NEW.soilcat_id IS NULL) THEN NEW.soilcat_id := (SELECT "value" FROM config_param_user WHERE "parameter"='edit_soilcat_vdefault' AND "cur_user"="current_user"() LIMIT 1); END IF; - - + + --Builtdate IF (NEW.builtdate IS NULL) THEN NEW.builtdate :=(SELECT "value" FROM config_param_user WHERE "parameter"='edit_builtdate_vdefault' AND "cur_user"="current_user"() LIMIT 1); @@ -333,10 +333,10 @@ BEGIN NEW.builtdate :=date(now()); END IF; END IF; - + --Address - IF (v_streetaxis IS NULL) THEN - IF (v_auto_streetvalues_status is true) THEN + IF (v_streetaxis IS NULL) THEN + IF (v_auto_streetvalues_status is true) THEN v_streetaxis := (select v_ext_streetaxis.id from v_ext_streetaxis join node on ST_DWithin(NEW.the_geom, v_ext_streetaxis.the_geom, v_auto_streetvalues_buffer) order by ST_Distance(NEW.the_geom, v_ext_streetaxis.the_geom) LIMIT 1); @@ -344,7 +344,7 @@ BEGIN END IF; --Postnumber/postcomplement - IF (v_auto_streetvalues_status) IS TRUE THEN + IF (v_auto_streetvalues_status) IS TRUE THEN IF (v_auto_streetvalues_field = 'postcomplement') THEN IF (NEW.postcomplement IS NULL) THEN NEW.postcomplement = (select ext_address.postnumber from ext_address @@ -363,19 +363,19 @@ BEGIN -- Code SELECT code_autofill, cat_feature.id, addparam::json->>'code_prefix' INTO v_code_autofill_bool, v_featurecat, v_code_prefix FROM cat_feature WHERE id=NEW.connec_type; - + IF v_featurecat IS NOT NULL THEN -- use specific sequence for code when its name matches featurecat_code_seq EXECUTE 'SELECT concat('||quote_literal(lower(v_featurecat))||',''_code_seq'');' INTO v_seq_name; EXECUTE 'SELECT relname FROM pg_catalog.pg_class WHERE relname='||quote_literal(v_seq_name)||';' INTO v_sql; - + IF v_sql IS NOT NULL AND NEW.code IS NULL THEN EXECUTE 'SELECT nextval('||quote_literal(v_seq_name)||');' INTO v_seq_code; NEW.code=concat(v_code_prefix,v_seq_code); END IF; - + --Copy id to code field - IF (v_code_autofill_bool IS TRUE) AND NEW.code IS NULL THEN + IF (v_code_autofill_bool IS TRUE) AND NEW.code IS NULL THEN NEW.code=NEW.connec_id; END IF; END IF; @@ -384,17 +384,17 @@ BEGIN IF NEW.inventory IS NULL THEN NEW.inventory := (SELECT "value" FROM config_param_system WHERE "parameter"='edit_inventory_sysvdefault'); END IF; - + --Publish IF NEW.publish IS NULL THEN NEW.publish := (SELECT "value" FROM config_param_system WHERE "parameter"='edit_publish_sysvdefault'); - END IF; - + END IF; + --Uncertain IF NEW.uncertain IS NULL THEN NEW.uncertain := (SELECT "value" FROM config_param_system WHERE "parameter"='edit_uncertain_sysvdefault'); END IF; - + -- LINK --google maps style IF (SELECT (value::json->>'google_maps')::boolean FROM config_param_system WHERE parameter='edit_custom_link') IS TRUE THEN @@ -403,13 +403,13 @@ BEGIN ELSIF (SELECT (value::json->>'fid')::boolean FROM config_param_system WHERE parameter='edit_custom_link') IS TRUE THEN NEW.link=NEW.connec_id; END IF; - - -- Customer code + + -- Customer code IF NEW.customer_code IS NULL AND (SELECT (value::json->>'status')::boolean FROM config_param_system WHERE parameter = 'edit_connec_autofill_ccode') IS TRUE AND (SELECT (value::json->>'field')::text FROM config_param_system WHERE parameter = 'edit_connec_autofill_ccode')='code' THEN - + NEW.customer_code = NEW.code; - + ELSIF NEW.customer_code IS NULL AND (SELECT (value::json->>'status')::boolean FROM config_param_system WHERE parameter = 'edit_connec_autofill_ccode') IS TRUE AND (SELECT (value::json->>'field')::text FROM config_param_system WHERE parameter = 'edit_connec_autofill_ccode')='connec_id' THEN @@ -448,7 +448,7 @@ BEGIN IF NEW.category_type IS NULL THEN NEW.category_type = (SELECT value FROM config_param_user WHERE parameter = 'connec_category_vdefault' AND cur_user = current_user); - END IF; + END IF; --Function type IF NEW.function_type IS NULL AND (SELECT value FROM config_param_user WHERE parameter = 'edit_feature_function_vdefault' AND cur_user = current_user) = v_featurecat THEN @@ -460,58 +460,58 @@ BEGIN END IF; --elevation from raster - IF (SELECT json_extract_path_text(value::json,'activated')::boolean FROM config_param_system WHERE parameter='admin_raster_dem') IS TRUE + IF (SELECT json_extract_path_text(value::json,'activated')::boolean FROM config_param_system WHERE parameter='admin_raster_dem') IS TRUE AND (NEW.top_elev IS NULL) AND (SELECT upper(value) FROM config_param_user WHERE parameter = 'edit_insert_elevation_from_dem' and cur_user = current_user) = 'TRUE' THEN NEW.top_elev = (SELECT ST_Value(rast,1,NEW.the_geom,true) FROM v_ext_raster_dem WHERE id = (SELECT id FROM v_ext_raster_dem WHERE st_dwithin (envelope, NEW.the_geom, 1) LIMIT 1)); - END IF; + END IF; -- plot_code from plot layer IF (SELECT value::boolean FROM config_param_system WHERE parameter = 'edit_connec_autofill_plotcode') = TRUE THEN NEW.plot_code = (SELECT plot_code FROM v_ext_plot WHERE st_dwithin(the_geom, NEW.the_geom, 0) LIMIT 1); END IF; - + -- FEATURE INSERT IF v_matfromcat THEN - INSERT INTO connec (connec_id, code, customer_code, top_elev, y1, y2,connecat_id, connec_type, sector_id, demand, "state", state_type, connec_depth, connec_length, arc_id, annotation, - "observ","comment", dma_id, soilcat_id, function_type, category_type, fluid_type, location_type, workcat_id, workcat_id_end, workcat_id_plan, buildercat_id, + INSERT INTO connec (connec_id, code, customer_code, top_elev, y1, y2,connecat_id, connec_type, sector_id, demand, "state", state_type, connec_depth, connec_length, arc_id, annotation, + "observ","comment", dma_id, soilcat_id, function_type, category_type, fluid_type, location_type, workcat_id, workcat_id_end, workcat_id_plan, buildercat_id, builtdate, enddate, ownercat_id, muni_id, postcode, district_id, - streetaxis2_id, streetaxis_id, postnumber, postnumber2, postcomplement, postcomplement2, descript, rotation, link, verified, the_geom, undelete, label_x, label_y, + streetaxis2_id, streetaxis_id, postnumber, postnumber2, postcomplement, postcomplement2, descript, rotation, link, verified, the_geom, undelete, label_x, label_y, label_rotation, accessibility,diagonal, expl_id, publish, inventory, uncertain, num_value, private_connecat_id, - lastupdate, lastupdate_user, asset_id, drainzone_id, expl_id2, adate, adescript, plot_code) - VALUES (NEW.connec_id, NEW.code, NEW.customer_code, NEW.top_elev, NEW.y1, NEW.y2, NEW.connecat_id, NEW.connec_type, NEW.sector_id, NEW.demand,NEW."state", NEW.state_type, NEW.connec_depth, - NEW.connec_length, NEW.arc_id, NEW.annotation, NEW."observ", NEW."comment", NEW.dma_id, NEW.soilcat_id, NEW.function_type, NEW.category_type, NEW.fluid_type, NEW.location_type, - NEW.workcat_id, NEW.workcat_id_end, NEW.workcat_id_plan, NEW.buildercat_id, NEW.builtdate, NEW.enddate, NEW.ownercat_id, NEW.muni_id, NEW.postcode, NEW.district_id, + lastupdate, lastupdate_user, asset_id, drainzone_id, expl_id2, adate, adescript, plot_code, placement_type) + VALUES (NEW.connec_id, NEW.code, NEW.customer_code, NEW.top_elev, NEW.y1, NEW.y2, NEW.connecat_id, NEW.connec_type, NEW.sector_id, NEW.demand,NEW."state", NEW.state_type, NEW.connec_depth, + NEW.connec_length, NEW.arc_id, NEW.annotation, NEW."observ", NEW."comment", NEW.dma_id, NEW.soilcat_id, NEW.function_type, NEW.category_type, NEW.fluid_type, NEW.location_type, + NEW.workcat_id, NEW.workcat_id_end, NEW.workcat_id_plan, NEW.buildercat_id, NEW.builtdate, NEW.enddate, NEW.ownercat_id, NEW.muni_id, NEW.postcode, NEW.district_id, v_streetaxis2, v_streetaxis, NEW.postnumber, NEW.postnumber2, NEW.postcomplement, NEW.postcomplement2, NEW.descript, NEW.rotation, NEW.link, NEW.verified, NEW.the_geom, NEW.undelete, NEW.label_x, NEW.label_y, NEW.label_rotation, NEW.accessibility, NEW.diagonal, NEW.expl_id, NEW.publish, NEW.inventory, NEW.uncertain, NEW.num_value, NEW.private_connecat_id, - NEW.lastupdate, NEW.lastupdate_user, NEW.asset_id, NEW.drainzone_id, NEW.expl_id2, NEW.adate, NEW.adescript, NEW.plot_code); + NEW.lastupdate, NEW.lastupdate_user, NEW.asset_id, NEW.drainzone_id, NEW.expl_id2, NEW.adate, NEW.adescript, NEW.plot_code, NEW.placement_type); ELSE - INSERT INTO connec (connec_id, code, customer_code, top_elev, y1, y2,connecat_id, connec_type, sector_id, demand, "state", state_type, connec_depth, connec_length, arc_id, annotation, - "observ","comment", dma_id, soilcat_id, function_type, category_type, fluid_type, location_type, workcat_id, workcat_id_end, workcat_id_plan, buildercat_id, + INSERT INTO connec (connec_id, code, customer_code, top_elev, y1, y2,connecat_id, connec_type, sector_id, demand, "state", state_type, connec_depth, connec_length, arc_id, annotation, + "observ","comment", dma_id, soilcat_id, function_type, category_type, fluid_type, location_type, workcat_id, workcat_id_end, workcat_id_plan, buildercat_id, builtdate, enddate, ownercat_id, muni_id,postcode,district_id, - streetaxis2_id, streetaxis_id, postnumber, postnumber2, postcomplement, postcomplement2, descript, rotation, link, verified, the_geom, undelete, label_x, label_y, + streetaxis2_id, streetaxis_id, postnumber, postnumber2, postcomplement, postcomplement2, descript, rotation, link, verified, the_geom, undelete, label_x, label_y, label_rotation, accessibility,diagonal, expl_id, publish, inventory, uncertain, num_value, private_connecat_id, matcat_id, - lastupdate, lastupdate_user, asset_id, drainzone_id, expl_id2, adate, adescript, plot_code) - VALUES (NEW.connec_id, NEW.code, NEW.customer_code, NEW.top_elev, NEW.y1, NEW.y2, NEW.connecat_id, NEW.connec_type, NEW.sector_id, NEW.demand,NEW."state", NEW.state_type, NEW.connec_depth, - NEW.connec_length, NEW.arc_id, NEW.annotation, NEW."observ", NEW."comment", NEW.dma_id, NEW.soilcat_id, NEW.function_type, NEW.category_type, NEW.fluid_type, NEW.location_type, + lastupdate, lastupdate_user, asset_id, drainzone_id, expl_id2, adate, adescript, plot_code, placement_type) + VALUES (NEW.connec_id, NEW.code, NEW.customer_code, NEW.top_elev, NEW.y1, NEW.y2, NEW.connecat_id, NEW.connec_type, NEW.sector_id, NEW.demand,NEW."state", NEW.state_type, NEW.connec_depth, + NEW.connec_length, NEW.arc_id, NEW.annotation, NEW."observ", NEW."comment", NEW.dma_id, NEW.soilcat_id, NEW.function_type, NEW.category_type, NEW.fluid_type, NEW.location_type, NEW.workcat_id, NEW.workcat_id_end, NEW.workcat_id_plan, NEW.buildercat_id, NEW.builtdate, NEW.enddate, NEW.ownercat_id, NEW.muni_id, NEW.postcode, NEW.district_id, v_streetaxis2, v_streetaxis, NEW.postnumber, NEW.postnumber2, NEW.postcomplement, NEW.postcomplement2, NEW.descript, NEW.rotation, NEW.link, NEW.verified, NEW.the_geom, NEW.undelete, NEW.label_x, NEW.label_y, NEW.label_rotation, NEW.accessibility, NEW.diagonal, NEW.expl_id, NEW.publish, NEW.inventory, NEW.uncertain, NEW.num_value, NEW.private_connecat_id, NEW.matcat_id, - NEW.lastupdate, NEW.lastupdate_user, NEW.asset_id, NEW.drainzone_id, NEW.expl_id2, NEW.adate, NEW.adescript, NEW.plot_code); + NEW.lastupdate, NEW.lastupdate_user, NEW.asset_id, NEW.drainzone_id, NEW.expl_id2, NEW.adate, NEW.adescript, NEW.plot_code, NEW.placement_type); END IF; - + --check if feature is double geom EXECUTE 'SELECT json_extract_path_text(double_geom,''activated'')::boolean, json_extract_path_text(double_geom,''value'') FROM cat_feature_connec WHERE id='||quote_literal(NEW.connec_type)||'' INTO v_doublegeometry, v_doublegeom_buffer; - + -- set and get id for polygon IF (v_doublegeometry IS TRUE) THEN - INSERT INTO polygon(sys_type, the_geom, featurecat_id,feature_id ) - VALUES ('CONNEC', (SELECT ST_Multi(ST_Envelope(ST_Buffer(connec.the_geom,v_doublegeom_buffer))) + INSERT INTO polygon(sys_type, the_geom, featurecat_id,feature_id ) + VALUES ('CONNEC', (SELECT ST_Multi(ST_Envelope(ST_Buffer(connec.the_geom,v_doublegeom_buffer))) from connec where connec_id=NEW.connec_id), NEW.connec_type, NEW.connec_id); END IF; @@ -523,7 +523,7 @@ BEGIN -- manage connect2network IF v_connect2network THEN - + IF NEW.arc_id IS NOT NULL THEN EXECUTE 'SELECT gw_fct_linktonetwork($${"client":{"device":4, "infoType":1, "lang":"ES"}, "feature":{"id":'|| array_to_json(array_agg(NEW.connec_id))||'},"data":{"feature_type":"CONNEC", "forcedArcs":["'||NEW.arc_id||'"]}}$$)'; @@ -536,7 +536,7 @@ BEGIN SELECT * INTO v_arc FROM arc WHERE arc_id = NEW.arc_id; NEW.pjoint_id = v_arc.arc_id; NEW.pjoint_type = 'ARC'; NEW.sector_id = v_arc.sector_id; NEW.dma_id = v_arc.dma_id; END IF; - + -- childtable insert IF v_customfeature IS NOT NULL THEN FOR v_addfields IN SELECT * FROM sys_addfields @@ -559,23 +559,23 @@ BEGIN -- UPDATE geom IF st_equals( NEW.the_geom, OLD.the_geom) IS FALSE THEN - UPDATE connec SET the_geom=NEW.the_geom WHERE connec_id = OLD.connec_id; + UPDATE connec SET the_geom=NEW.the_geom WHERE connec_id = OLD.connec_id; --update elevation from raster - IF (SELECT json_extract_path_text(value::json,'activated')::boolean FROM config_param_system WHERE parameter='admin_raster_dem') IS TRUE + IF (SELECT json_extract_path_text(value::json,'activated')::boolean FROM config_param_system WHERE parameter='admin_raster_dem') IS TRUE AND (NEW.top_elev = OLD.top_elev) AND (SELECT upper(value) FROM config_param_user WHERE parameter = 'edit_update_elevation_from_dem' and cur_user = current_user) = 'TRUE' THEN NEW.top_elev = (SELECT ST_Value(rast,1,NEW.the_geom,true) FROM v_ext_raster_dem WHERE id = (SELECT id FROM v_ext_raster_dem WHERE st_dwithin (envelope, NEW.the_geom, 1) LIMIT 1)); - END IF; - + END IF; + --update associated geometry of element (if exists) and trace_featuregeom is true - v_trace_featuregeom:= (SELECT trace_featuregeom FROM element JOIN element_x_connec using (element_id) + v_trace_featuregeom:= (SELECT trace_featuregeom FROM element JOIN element_x_connec using (element_id) WHERE connec_id=NEW.connec_id AND the_geom IS NOT NULL LIMIT 1); - + -- if trace_featuregeom is false, do nothing IF v_trace_featuregeom IS TRUE THEN - UPDATE v_edit_element SET the_geom = NEW.the_geom WHERE St_dwithin(OLD.the_geom, the_geom, 0.001) + UPDATE v_edit_element SET the_geom = NEW.the_geom WHERE St_dwithin(OLD.the_geom, the_geom, 0.001) AND element_id IN (SELECT element_id FROM element_x_connec WHERE connec_id=NEW.connec_id); END IF; @@ -583,7 +583,7 @@ BEGIN IF (SELECT value::boolean FROM config_param_system WHERE parameter = 'edit_connec_autofill_plotcode') = TRUE THEN NEW.plot_code = (SELECT plot_code FROM v_ext_plot WHERE st_dwithin(the_geom, NEW.the_geom, 0) LIMIT 1); END IF; - + END IF; -- Reconnect arc_id @@ -592,10 +592,10 @@ BEGIN -- when connec_id comes from psector_table IF NEW.state = 1 AND (SELECT connec_id FROM plan_psector_x_connec JOIN selector_psector USING (psector_id) WHERE connec_id=NEW.connec_id AND psector_id = v_psector_vdefault AND cur_user = current_user AND state = 1) IS NOT NULL THEN - + EXECUTE 'SELECT gw_fct_linktonetwork($${"client":{"device":4, "infoType":1, "lang":"ES"}, - "feature":{"id":'|| array_to_json(array_agg(NEW.connec_id))||'},"data":{"feature_type":"CONNEC", "forceEndPoint":"true", "forcedArcs":["'||NEW.arc_id||'"]}}$$)'; - + "feature":{"id":'|| array_to_json(array_agg(NEW.connec_id))||'},"data":{"feature_type":"CONNEC", "forceEndPoint":"true", "forcedArcs":["'||NEW.arc_id||'"]}}$$)'; + ELSIF NEW.state = 2 THEN IF NEW.arc_id IS NOT NULL THEN @@ -615,7 +615,7 @@ BEGIN UPDATE plan_psector_x_connec SET arc_id = null, link_id = null WHERE connec_id=NEW.connec_id AND psector_id = v_psector_vdefault AND state = 1; END IF; - -- setting values + -- setting values NEW.sector_id = 0; NEW.dma_id = 0; NEW.pjoint_id = null; NEW.pjoint_type = null; END IF; ELSE @@ -627,14 +627,14 @@ BEGIN -- when link exists IF (SELECT link_id FROM link WHERE state = 1 and feature_id = NEW.connec_id) IS NOT NULL THEN EXECUTE 'SELECT gw_fct_linktonetwork($${"client":{"device":4, "infoType":1, "lang":"ES"}, - "feature":{"id":'|| array_to_json(array_agg(NEW.connec_id))||'},"data":{"feature_type":"CONNEC", "forceEndPoint":"true", "forcedArcs":["'||NEW.arc_id||'"]}}$$)'; + "feature":{"id":'|| array_to_json(array_agg(NEW.connec_id))||'},"data":{"feature_type":"CONNEC", "forceEndPoint":"true", "forcedArcs":["'||NEW.arc_id||'"]}}$$)'; END IF; - + -- recover values in order to do not disturb this workflow SELECT * INTO v_arc FROM arc WHERE arc_id = NEW.arc_id; - NEW.pjoint_id = v_arc.arc_id; NEW.pjoint_type = 'ARC'; NEW.sector_id = v_arc.sector_id; NEW.dma_id = v_arc.dma_id; + NEW.pjoint_id = v_arc.arc_id; NEW.pjoint_type = 'ARC'; NEW.sector_id = v_arc.sector_id; NEW.dma_id = v_arc.dma_id; ELSE - + IF (SELECT count(*)FROM link WHERE feature_id = NEW.connec_id AND state = 1) > 0 THEN EXECUTE 'SELECT gw_fct_getmessage($${"client":{"device":4, "infoType":1, "lang":"ES"},"feature":{}, "data":{"message":"3204", "function":"1204","debug_msg":""}}$$);'; @@ -645,7 +645,7 @@ BEGIN END IF; END IF; END IF; - + -- State_type IF NEW.state=0 AND OLD.state=1 THEN IF (SELECT state FROM value_state_type WHERE id=NEW.state_type) != NEW.state THEN @@ -654,68 +654,68 @@ BEGIN NEW.state_type=(SELECT id from value_state_type WHERE state=0 LIMIT 1); IF NEW.state_type IS NULL THEN EXECUTE 'SELECT gw_fct_getmessage($${"client":{"device":4, "infoType":1, "lang":"ES"},"feature":{}, - "data":{"message":"2110", "function":"1204","debug_msg":null}}$$);'; + "data":{"message":"2110", "function":"1204","debug_msg":null}}$$);'; END IF; END IF; END IF; -- Automatic downgrade of associated link UPDATE link SET state=0 WHERE feature_id=OLD.connec_id; - + --check if there is any active hydrometer related to connec IF (SELECT count(id) FROM rtc_hydrometer_x_connec rhc JOIN ext_rtc_hydrometer hc ON hc.id=hydrometer_id WHERE (rhc.connec_id=NEW.connec_id OR hc.connec_id=NEW.connec_id) AND state_id = 1) > 0 THEN EXECUTE 'SELECT gw_fct_getmessage($${"client":{"device":4, "infoType":1, "lang":"ES"},"feature":{}, "data":{"message":"3184", "function":"1318","debug_msg":null}}$$);'; END IF; - + END IF; -- Looking for state control and insert planified connecs to default psector - IF (NEW.state != OLD.state) THEN - + IF (NEW.state != OLD.state) THEN + PERFORM gw_fct_state_control('CONNEC', NEW.connec_id, NEW.state, TG_OP); - + IF NEW.state = 2 AND OLD.state=1 THEN - + v_link = (SELECT link_id FROM link WHERE feature_id = NEW.connec_id AND state = 1 LIMIT 1); - + INSERT INTO plan_psector_x_connec (connec_id, psector_id, state, doable, link_id, arc_id) VALUES (NEW.connec_id, v_psector_vdefault, 1, true, v_link, NEW.arc_id); - + UPDATE link SET state = 2 WHERE link_id = v_link; END IF; - + IF NEW.state = 1 AND OLD.state=2 THEN - + v_link = (SELECT link_id FROM link WHERE feature_id = NEW.connec_id AND state = 2 LIMIT 1); - + -- force delete UPDATE config_param_user SET value = 'true' WHERE parameter = 'plan_psector_downgrade_feature' AND cur_user= current_user; DELETE FROM plan_psector_x_connec WHERE connec_id=NEW.connec_id; -- recover values UPDATE config_param_user SET value = 'false' WHERE parameter = 'plan_psector_downgrade_feature' AND cur_user= current_user; - UPDATE link SET state = 1 WHERE link_id = v_link; + UPDATE link SET state = 1 WHERE link_id = v_link; END IF; - + UPDATE connec SET state=NEW.state WHERE connec_id = OLD.connec_id; END IF; - IF (NEW.connecat_id != OLD.connecat_id) AND NEW.state > 0 THEN + IF (NEW.connecat_id != OLD.connecat_id) AND NEW.state > 0 THEN UPDATE link SET connecat_id=NEW.connecat_id WHERE feature_id = NEW.connec_id AND state>0; - END IF; - + END IF; + --check relation state - state_type IF (NEW.state_type != OLD.state_type) THEN - + IF NEW.state_type NOT IN (SELECT id FROM value_state_type WHERE state = NEW.state) THEN EXECUTE 'SELECT gw_fct_getmessage($${"client":{"device":4, "infoType":1, "lang":"ES"},"feature":{}, - "data":{"message":"3036", "function":"1204","debug_msg":"'||NEW.state::text||'"}}$$);'; + "data":{"message":"3036", "function":"1204","debug_msg":"'||NEW.state::text||'"}}$$);'; ELSE UPDATE connec SET state_type=NEW.state_type WHERE connec_id = OLD.connec_id; END IF; - END IF; + END IF; -- rotation IF NEW.rotation != OLD.rotation THEN @@ -726,43 +726,43 @@ BEGIN IF (NEW.customer_code != OLD.customer_code) OR (OLD.customer_code IS NULL AND NEW.customer_code IS NOT NULL) THEN UPDATE connec SET customer_code=NEW.customer_code WHERE connec_id = OLD.connec_id; END IF; - + --link_path SELECT link_path INTO v_link_path FROM cat_feature WHERE id=NEW.connec_type; IF v_link_path IS NOT NULL THEN NEW.link = replace(NEW.link, v_link_path,''); END IF; - + --fluid_type IF v_autoupdate_fluid IS TRUE AND NEW.arc_id IS NOT NULL THEN NEW.fluid_type = (SELECT fluid_type FROM arc WHERE arc_id = NEW.arc_id); END IF; IF v_matfromcat THEN - UPDATE connec + UPDATE connec SET code=NEW.code, top_elev=NEW.top_elev, y1=NEW.y1, y2=NEW.y2, connecat_id=NEW.connecat_id, connec_type=NEW.connec_type, sector_id=NEW.sector_id, demand=NEW.demand, connec_depth=NEW.connec_depth, connec_length=NEW.connec_length, annotation=NEW.annotation, "observ"=NEW."observ", - "comment"=NEW."comment", dma_id=NEW.dma_id, soilcat_id=NEW.soilcat_id, function_type=NEW.function_type, category_type=NEW.category_type, fluid_type=NEW.fluid_type, + "comment"=NEW."comment", dma_id=NEW.dma_id, soilcat_id=NEW.soilcat_id, function_type=NEW.function_type, category_type=NEW.category_type, fluid_type=NEW.fluid_type, location_type=NEW.location_type, workcat_id=NEW.workcat_id, workcat_id_end=NEW.workcat_id_end, workcat_id_plan=NEW.workcat_id_plan, buildercat_id=NEW.buildercat_id, builtdate=NEW.builtdate, enddate=NEW.enddate, - ownercat_id=NEW.ownercat_id, muni_id=NEW.muni_id, postcode=NEW.postcode, district_id =NEW.district_id, streetaxis2_id=v_streetaxis2, streetaxis_id=v_streetaxis, postnumber=NEW.postnumber, postnumber2=NEW.postnumber2, postcomplement=NEW.postcomplement, postcomplement2=NEW.postcomplement2, descript=NEW.descript, - rotation=NEW.rotation, link=NEW.link, verified=NEW.verified, undelete=NEW.undelete, + ownercat_id=NEW.ownercat_id, muni_id=NEW.muni_id, postcode=NEW.postcode, district_id =NEW.district_id, streetaxis2_id=v_streetaxis2, streetaxis_id=v_streetaxis, postnumber=NEW.postnumber, postnumber2=NEW.postnumber2, postcomplement=NEW.postcomplement, postcomplement2=NEW.postcomplement2, descript=NEW.descript, + rotation=NEW.rotation, link=NEW.link, verified=NEW.verified, undelete=NEW.undelete, label_x=NEW.label_x, label_y=NEW.label_y, label_rotation=NEW.label_rotation, accessibility=NEW.accessibility, diagonal=NEW.diagonal, publish=NEW.publish, pjoint_id=NEW.pjoint_id, pjoint_type = NEW.pjoint_type, inventory=NEW.inventory, uncertain=NEW.uncertain, expl_id=NEW.expl_id,num_value=NEW.num_value, private_connecat_id=NEW.private_connecat_id, lastupdate=now(), lastupdate_user=current_user, asset_id=NEW.asset_id, drainzone_id=NEW.drainzone_id, expl_id2=NEW.expl_id2, adate=NEW.adate, adescript=NEW.adescript, - plot_code=NEW.plot_code + plot_code=NEW.plot_code, placement_type=NEW.placement_type WHERE connec_id = OLD.connec_id; ELSE - UPDATE connec + UPDATE connec SET code=NEW.code, top_elev=NEW.top_elev, y1=NEW.y1, y2=NEW.y2, connecat_id=NEW.connecat_id, connec_type=NEW.connec_type, sector_id=NEW.sector_id, demand=NEW.demand, connec_depth=NEW.connec_depth, connec_length=NEW.connec_length, annotation=NEW.annotation, "observ"=NEW."observ", - "comment"=NEW."comment", dma_id=NEW.dma_id, soilcat_id=NEW.soilcat_id, function_type=NEW.function_type, category_type=NEW.category_type, fluid_type=NEW.fluid_type, + "comment"=NEW."comment", dma_id=NEW.dma_id, soilcat_id=NEW.soilcat_id, function_type=NEW.function_type, category_type=NEW.category_type, fluid_type=NEW.fluid_type, location_type=NEW.location_type, workcat_id=NEW.workcat_id, workcat_id_end=NEW.workcat_id_end, workcat_id_plan=NEW.workcat_id_plan, buildercat_id=NEW.buildercat_id, builtdate=NEW.builtdate, enddate=NEW.enddate, - ownercat_id=NEW.ownercat_id, muni_id=NEW.muni_id, postcode=NEW.postcode, district_id=NEW.district_id, streetaxis2_id=v_streetaxis2, streetaxis_id=v_streetaxis, postnumber=NEW.postnumber, postnumber2=NEW.postnumber2, postcomplement=NEW.postcomplement, postcomplement2=NEW.postcomplement2, descript=NEW.descript, + ownercat_id=NEW.ownercat_id, muni_id=NEW.muni_id, postcode=NEW.postcode, district_id=NEW.district_id, streetaxis2_id=v_streetaxis2, streetaxis_id=v_streetaxis, postnumber=NEW.postnumber, postnumber2=NEW.postnumber2, postcomplement=NEW.postcomplement, postcomplement2=NEW.postcomplement2, descript=NEW.descript, rotation=NEW.rotation, link=NEW.link, verified=NEW.verified, undelete=NEW.undelete, label_x=NEW.label_x, label_y=NEW.label_y, label_rotation=NEW.label_rotation, accessibility=NEW.accessibility, diagonal=NEW.diagonal, publish=NEW.publish, pjoint_id=NEW.pjoint_id, pjoint_type = NEW.pjoint_type, - inventory=NEW.inventory, uncertain=NEW.uncertain, expl_id=NEW.expl_id,num_value=NEW.num_value, private_connecat_id=NEW.private_connecat_id, lastupdate=now(), + inventory=NEW.inventory, uncertain=NEW.uncertain, expl_id=NEW.expl_id,num_value=NEW.num_value, private_connecat_id=NEW.private_connecat_id, lastupdate=now(), lastupdate_user=current_user, matcat_id = NEW.matcat_id, asset_id=NEW.asset_id, drainzone_id=NEW.drainzone_id, expl_id2=NEW.expl_id2, adate=NEW.adate, adescript=NEW.adescript, - plot_code=NEW.plot_code - WHERE connec_id = OLD.connec_id; + plot_code=NEW.plot_code, placement_type=NEW.placement_type + WHERE connec_id = OLD.connec_id; END IF; -- childtable update @@ -795,7 +795,7 @@ BEGIN ELSIF TG_OP = 'DELETE' THEN - + EXECUTE 'SELECT gw_fct_getcheckdelete($${"client":{"device":4, "infoType":1, "lang":"ES"}, "feature":{"id":"'||OLD.connec_id||'","featureType":"CONNEC"}, "data":{}}$$)'; @@ -805,9 +805,9 @@ BEGIN -- force plan_psector_force_delete SELECT value INTO v_force_delete FROM config_param_user WHERE parameter = 'plan_psector_force_delete' and cur_user = current_user; UPDATE config_param_user SET value = 'true' WHERE parameter = 'plan_psector_force_delete' and cur_user = current_user; - + DELETE FROM connec WHERE connec_id = OLD.connec_id; - + -- restore plan_psector_force_delete UPDATE config_param_user SET value = v_force_delete WHERE parameter = 'plan_psector_force_delete' and cur_user = current_user; @@ -826,10 +826,10 @@ BEGIN END LOOP; - RETURN NULL; + RETURN NULL; END IF; END; $BODY$ LANGUAGE plpgsql VOLATILE - COST 100; \ No newline at end of file + COST 100; \ No newline at end of file diff --git a/ud/ftrg/ud_gw_trg_edit_gully.sql b/ud/ftrg/ud_gw_trg_edit_gully.sql index 0e5c651275..8fbf3a19ae 100644 --- a/ud/ftrg/ud_gw_trg_edit_gully.sql +++ b/ud/ftrg/ud_gw_trg_edit_gully.sql @@ -8,7 +8,7 @@ This version of Giswater is provided by Giswater Association CREATE OR REPLACE FUNCTION "SCHEMA_NAME".gw_trg_edit_gully() RETURNS trigger AS $BODY$ -DECLARE +DECLARE v_sql varchar; v_count integer; v_promixity_buffer double precision; @@ -29,9 +29,9 @@ v_unitsfactor float; v_linelocatepoint float; v_thegeom public.geometry; v_the_geom_pol public.geometry; -p21x float; +p21x float; p02x float; -p21y float; +p21y float; p02y float; p22x float; p22y float; @@ -55,7 +55,7 @@ v_matfromcat boolean = false; v_epa_gully_efficiency float; v_epa_gully_method text; v_epa_gully_orifice_cd float; -v_epa_gully_outlet_type text; +v_epa_gully_outlet_type text; v_epa_gully_weir_cd float; v_arc record; v_link integer; @@ -95,7 +95,7 @@ BEGIN v_auto_streetvalues_field := (SELECT (value::json->>'field')::text FROM config_param_system WHERE parameter = 'edit_auto_streetvalues'); v_srid = (SELECT epsg FROM sys_version ORDER BY id DESC LIMIT 1); - + IF v_promixity_buffer IS NULL THEN v_promixity_buffer=0.5; END IF; v_psector_vdefault = (SELECT config_param_user.value::integer AS value FROM config_param_user WHERE config_param_user.parameter::text @@ -107,14 +107,14 @@ BEGIN IF (SELECT matcat_id FROM cat_grate WHERE id = NEW.gratecat_id) IS NOT NULL THEN v_matfromcat = true; END IF; - + -- managing gully_type IF NEW.gully_type IS NULL THEN EXECUTE 'SELECT gw_fct_getmessage($${"client":{"device":4, "infoType":1, "lang":"ES"},"feature":{}, "data":{"message":"3262", "function":"1206","debug_msg":null}}$$);'; END IF; - - --check if feature is double geom + + --check if feature is double geom EXECUTE 'SELECT json_extract_path_text(double_geom,''activated'')::boolean, json_extract_path_text(double_geom,''value'') FROM cat_feature_gully WHERE id='||quote_literal(NEW.gully_type)||'' INTO v_doublegeometry, v_unitsfactor; @@ -124,7 +124,7 @@ BEGIN EXECUTE 'SELECT gw_fct_getmessage($${"client":{"device":4, "infoType":1, "lang":"ES"},"feature":{}, "data":{"message":"3246", "function":"1206","debug_msg":null}}$$);'; END IF; - + -- transforming streetaxis name into id v_streetaxis = (SELECT id FROM v_ext_streetaxis WHERE (muni_id = NEW.muni_id OR muni_id IS NULL) AND descript = NEW.streetname LIMIT 1); v_streetaxis2 = (SELECT id FROM v_ext_streetaxis WHERE (muni_id = NEW.muni_id OR muni_id IS NULL) AND descript = NEW.streetname2 LIMIT 1); @@ -140,10 +140,10 @@ BEGIN -- Control insertions ID IF TG_OP = 'INSERT' THEN - + -- setting psector vdefault as visible IF NEW.state = 2 THEN - INSERT INTO selector_psector (psector_id, cur_user) VALUES (v_psector_vdefault, current_user) + INSERT INTO selector_psector (psector_id, cur_user) VALUES (v_psector_vdefault, current_user) ON CONFLICT DO NOTHING; END IF; @@ -151,7 +151,7 @@ BEGIN IF NEW.gully_id != (SELECT last_value::text FROM urn_id_seq) OR NEW.gully_id IS NULL THEN NEW.gully_id = (SELECT nextval('urn_id_seq')); END IF; - + -- grate Catalog ID IF (NEW.gratecat_id IS NULL OR NEW.gratecat_id = '') THEN NEW.gratecat_id := (SELECT "value" FROM config_param_user WHERE "parameter"='edit_gratecat_vdefault' AND "cur_user"="current_user"() LIMIT 1); @@ -161,142 +161,142 @@ BEGIN IF (NEW.connec_arccat_id IS NULL) THEN NEW.connec_arccat_id := (SELECT "value" FROM config_param_user WHERE "parameter"='connecarccat_vdefault' AND "cur_user"="current_user"() LIMIT 1); END IF; - - + + -- Exploitation IF (NEW.expl_id IS NULL) THEN - + -- control error without any mapzones defined on the table of mapzone IF ((SELECT COUNT(*) FROM exploitation WHERE active IS TRUE) = 0) THEN EXECUTE 'SELECT gw_fct_getmessage($${"client":{"device":4, "infoType":1, "lang":"ES"},"feature":{}, "data":{"message":"1110", "function":"1206","debug_msg":null}}$$);'; END IF; - + -- getting value default IF (NEW.expl_id IS NULL) THEN NEW.expl_id := (SELECT "value" FROM config_param_user WHERE "parameter"='edit_exploitation_vdefault' AND "cur_user"="current_user"() LIMIT 1); END IF; - + -- getting value from geometry of mapzone IF (NEW.expl_id IS NULL) THEN SELECT count(*) INTO v_count FROM exploitation WHERE ST_DWithin(NEW.the_geom, exploitation.the_geom,0.001) AND active IS TRUE; IF v_count = 1 THEN NEW.expl_id = (SELECT expl_id FROM exploitation WHERE ST_DWithin(NEW.the_geom, exploitation.the_geom,0.001) AND active IS TRUE LIMIT 1); ELSE - NEW.expl_id =(SELECT expl_id FROM v_edit_arc WHERE ST_DWithin(NEW.the_geom, v_edit_arc.the_geom, v_promixity_buffer) + NEW.expl_id =(SELECT expl_id FROM v_edit_arc WHERE ST_DWithin(NEW.the_geom, v_edit_arc.the_geom, v_promixity_buffer) order by ST_Distance (NEW.the_geom, v_edit_arc.the_geom) LIMIT 1); - END IF; + END IF; END IF; - + -- control error when no value IF (NEW.expl_id IS NULL) THEN EXECUTE 'SELECT gw_fct_getmessage($${"client":{"device":4, "infoType":1, "lang":"ES"},"feature":{}, "data":{"message":"2012", "function":"1206","debug_msg":"'||NEW.gully_id::text||'"}}$$);'; - END IF; + END IF; END IF; - - + + -- Sector ID IF (NEW.sector_id IS NULL) THEN - + -- control error without any mapzones defined on the table of mapzone IF ((SELECT COUNT(*) FROM sector WHERE active IS TRUE ) = 0) THEN EXECUTE 'SELECT gw_fct_getmessage($${"client":{"device":4, "infoType":1, "lang":"ES"},"feature":{}, "data":{"message":"1008", "function":"1206","debug_msg":null}}$$);'; END IF; - + -- getting value default IF (NEW.sector_id IS NULL) THEN NEW.sector_id := (SELECT "value" FROM config_param_user WHERE "parameter"='edit_sector_vdefault' AND "cur_user"="current_user"() LIMIT 1); END IF; - + -- getting value from geometry of mapzone IF (NEW.sector_id IS NULL) THEN SELECT count(*) INTO v_count FROM sector WHERE ST_DWithin(NEW.the_geom, sector.the_geom,0.001) AND active IS TRUE ; IF v_count = 1 THEN NEW.sector_id = (SELECT sector_id FROM sector WHERE ST_DWithin(NEW.the_geom, sector.the_geom,0.001) AND active IS TRUE LIMIT 1); ELSE - NEW.sector_id =(SELECT sector_id FROM v_edit_arc WHERE ST_DWithin(NEW.the_geom, v_edit_arc.the_geom, v_promixity_buffer) + NEW.sector_id =(SELECT sector_id FROM v_edit_arc WHERE ST_DWithin(NEW.the_geom, v_edit_arc.the_geom, v_promixity_buffer) order by ST_Distance (NEW.the_geom, v_edit_arc.the_geom) LIMIT 1); - END IF; + END IF; END IF; - + -- control error when no value IF (NEW.sector_id IS NULL) THEN NEW.sector_id = 0; - END IF; + END IF; END IF; - - + + -- Dma ID IF (NEW.dma_id IS NULL) THEN - + -- control error without any mapzones defined on the table of mapzone IF ((SELECT COUNT(*) FROM dma WHERE active IS TRUE) = 0) THEN EXECUTE 'SELECT gw_fct_getmessage($${"client":{"device":4, "infoType":1, "lang":"ES"},"feature":{}, "data":{"message":"1012", "function":"1206","debug_msg":null}}$$);'; END IF; - + -- getting value default IF (NEW.dma_id IS NULL) THEN NEW.dma_id := (SELECT "value" FROM config_param_user WHERE "parameter"='edit_dma_vdefault' AND "cur_user"="current_user"() LIMIT 1); END IF; - + -- getting value from geometry of mapzone IF (NEW.dma_id IS NULL) THEN SELECT count(*) INTO v_count FROM dma WHERE ST_DWithin(NEW.the_geom, dma.the_geom,0.001) AND active IS TRUE ; IF v_count = 1 THEN NEW.dma_id = (SELECT dma_id FROM dma WHERE ST_DWithin(NEW.the_geom, dma.the_geom,0.001) AND active IS TRUE LIMIT 1); ELSE - NEW.dma_id =(SELECT dma_id FROM v_edit_arc WHERE ST_DWithin(NEW.the_geom, v_edit_arc.the_geom, v_promixity_buffer) + NEW.dma_id =(SELECT dma_id FROM v_edit_arc WHERE ST_DWithin(NEW.the_geom, v_edit_arc.the_geom, v_promixity_buffer) order by ST_Distance (NEW.the_geom, v_edit_arc.the_geom) LIMIT 1); - END IF; + END IF; END IF; - + -- control error when no value IF (NEW.dma_id IS NULL) THEN NEW.dma_id = 0; - END IF; + END IF; END IF; - - - -- Municipality + + + -- Municipality IF (NEW.muni_id IS NULL) THEN - + -- getting value default IF (NEW.muni_id IS NULL) THEN NEW.muni_id := (SELECT "value" FROM config_param_user WHERE "parameter"='edit_municipality_vdefault' AND "cur_user"="current_user"() LIMIT 1); END IF; - + -- getting value from geometry of mapzone IF (NEW.muni_id IS NULL) THEN SELECT count(*) INTO v_count FROM ext_municipality WHERE ST_DWithin(NEW.the_geom, ext_municipality.the_geom,0.001) AND active IS TRUE ; IF v_count = 1 THEN - NEW.muni_id = (SELECT muni_id FROM ext_municipality WHERE ST_DWithin(NEW.the_geom, ext_municipality.the_geom,0.001) + NEW.muni_id = (SELECT muni_id FROM ext_municipality WHERE ST_DWithin(NEW.the_geom, ext_municipality.the_geom,0.001) AND active IS TRUE LIMIT 1); ELSE - NEW.muni_id =(SELECT muni_id FROM v_edit_arc WHERE ST_DWithin(NEW.the_geom, v_edit_arc.the_geom, v_promixity_buffer) + NEW.muni_id =(SELECT muni_id FROM v_edit_arc WHERE ST_DWithin(NEW.the_geom, v_edit_arc.the_geom, v_promixity_buffer) order by ST_Distance (NEW.the_geom, v_edit_arc.the_geom) LIMIT 1); - END IF; - END IF; + END IF; + END IF; END IF; - - -- District + + -- District IF (NEW.district_id IS NULL) THEN - + -- getting value from geometry of mapzone IF (NEW.district_id IS NULL) THEN SELECT count(*) INTO v_count FROM ext_district WHERE ST_DWithin(NEW.the_geom, ext_district.the_geom,0.001); IF v_count = 1 THEN NEW.district_id = (SELECT district_id FROM ext_district WHERE ST_DWithin(NEW.the_geom, ext_district.the_geom,0.001) LIMIT 1); ELSIF v_count > 1 THEN - NEW.district_id =(SELECT district_id FROM v_edit_arc WHERE ST_DWithin(NEW.the_geom, v_edit_arc.the_geom, v_promixity_buffer) + NEW.district_id =(SELECT district_id FROM v_edit_arc WHERE ST_DWithin(NEW.the_geom, v_edit_arc.the_geom, v_promixity_buffer) order by ST_Distance (NEW.the_geom, v_edit_arc.the_geom) LIMIT 1); - END IF; - END IF; + END IF; + END IF; END IF; - - + + -- Verified IF (NEW.verified IS NULL) THEN NEW.verified := (SELECT "value" FROM config_param_user WHERE "parameter"='edit_verified_vdefault' AND "cur_user"="current_user"() LIMIT 1); @@ -306,7 +306,7 @@ BEGIN IF (NEW.state IS NULL) THEN NEW.state := (SELECT "value" FROM config_param_user WHERE "parameter"='edit_state_vdefault' AND "cur_user"="current_user"() LIMIT 1); END IF; - + -- State_type IF (NEW.state=0) THEN IF (NEW.state_type IS NULL) THEN @@ -331,29 +331,29 @@ BEGIN END IF; EXECUTE 'SELECT gw_fct_getmessage($${"client":{"device":4, "infoType":1, "lang":"ES"},"feature":{}, - "data":{"message":"3036", "function":"1206","debug_msg":"'||v_sql::text||'"}}$$);'; - END IF; + "data":{"message":"3036", "function":"1206","debug_msg":"'||v_sql::text||'"}}$$);'; + END IF; -- Workcat_id IF (NEW.workcat_id IS NULL) THEN NEW.workcat_id := (SELECT "value" FROM config_param_user WHERE "parameter"='edit_workcat_vdefault' AND "cur_user"="current_user"() LIMIT 1); END IF; - + --Workcat_id_plan IF (NEW.workcat_id_plan IS NULL AND NEW.state = 2) THEN NEW.workcat_id_plan := (SELECT "value" FROM config_param_user WHERE "parameter"='edit_workcat_id_plan' AND "cur_user"="current_user"() LIMIT 1); END IF; - + -- Ownercat_id IF (NEW.ownercat_id IS NULL) THEN NEW.ownercat_id := (SELECT "value" FROM config_param_user WHERE "parameter"='edit_ownercat_vdefault' AND "cur_user"="current_user"() LIMIT 1); END IF; - + -- Soilcat_id IF (NEW.soilcat_id IS NULL) THEN NEW.soilcat_id := (SELECT "value" FROM config_param_user WHERE "parameter"='edit_soilcat_vdefault' AND "cur_user"="current_user"() LIMIT 1); END IF; - + --Builtdate IF (NEW.builtdate IS NULL) THEN NEW.builtdate :=(SELECT "value" FROM config_param_user WHERE "parameter"='edit_builtdate_vdefault' AND "cur_user"="current_user"() LIMIT 1); @@ -361,10 +361,10 @@ BEGIN NEW.builtdate :=date(now()); END IF; END IF; - + --Address - IF (v_streetaxis IS NULL) THEN - IF (v_auto_streetvalues_status is true) THEN + IF (v_streetaxis IS NULL) THEN + IF (v_auto_streetvalues_status is true) THEN v_streetaxis := (select v_ext_streetaxis.id from v_ext_streetaxis join node on ST_DWithin(NEW.the_geom, v_ext_streetaxis.the_geom, v_auto_streetvalues_buffer) order by ST_Distance(NEW.the_geom, v_ext_streetaxis.the_geom) LIMIT 1); @@ -372,7 +372,7 @@ BEGIN END IF; --Postnumber/postcomplement - IF (v_auto_streetvalues_status) IS TRUE THEN + IF (v_auto_streetvalues_status) IS TRUE THEN IF (v_auto_streetvalues_field = 'postcomplement') THEN IF (NEW.postcomplement IS NULL) THEN NEW.postcomplement = (select ext_address.postnumber from ext_address @@ -385,24 +385,24 @@ BEGIN join node on ST_DWithin(NEW.the_geom, ext_address.the_geom, v_auto_streetvalues_buffer) order by ST_Distance(NEW.the_geom, ext_address.the_geom) LIMIT 1); END IF; - END IF; + END IF; END IF; - + --Inventory IF NEW.inventory IS NULL THEN NEW.inventory := (SELECT "value" FROM config_param_system WHERE "parameter"='edit_inventory_sysvdefault'); END IF; - + --Publish IF NEW.publish IS NULL THEN NEW.publish := (SELECT "value" FROM config_param_system WHERE "parameter"='edit_publish_sysvdefault'); - END IF; - + END IF; + --Uncertain IF NEW.uncertain IS NULL THEN NEW.uncertain := (SELECT "value" FROM config_param_system WHERE "parameter"='edit_uncertain_sysvdefault'); END IF; - + -- Code SELECT code_autofill, cat_feature.id, addparam::json->>'code_prefix' INTO v_code_autofill_bool, v_featurecat, v_code_prefix FROM cat_feature WHERE id=NEW.gully_type; @@ -411,27 +411,27 @@ BEGIN -- use specific sequence for code when its name matches featurecat_code_seq EXECUTE 'SELECT concat('||quote_literal(lower(v_featurecat))||',''_code_seq'');' INTO v_seq_name; EXECUTE 'SELECT relname FROM pg_catalog.pg_class WHERE relname='||quote_literal(v_seq_name)||';' INTO v_sql; - + IF v_sql IS NOT NULL AND NEW.code IS NULL THEN EXECUTE 'SELECT nextval('||quote_literal(v_seq_name)||');' INTO v_seq_code; NEW.code=concat(v_code_prefix,v_seq_code); END IF; - - IF (v_code_autofill_bool IS TRUE) AND NEW.code IS NULL THEN + + IF (v_code_autofill_bool IS TRUE) AND NEW.code IS NULL THEN NEW.code=NEW.gully_id; END IF; END IF; - + --Units IF (NEW.units IS NULL) THEN NEW.units :='1'; - END IF; + END IF; --Inventory IF (NEW.inventory IS NULL) THEN NEW.inventory :='TRUE'; - END IF; - + END IF; + -- LINK --google maps style IF (SELECT (value::json->>'google_maps')::boolean FROM config_param_system WHERE parameter='edit_custom_link') IS TRUE THEN @@ -471,7 +471,7 @@ BEGIN IF NEW.category_type IS NULL THEN NEW.category_type = (SELECT value FROM config_param_user WHERE parameter = 'edit_gully_category_vdefault' AND cur_user = current_user); - END IF; + END IF; --Function type IF NEW.function_type IS NULL AND (SELECT value FROM config_param_user WHERE parameter = 'edit_feature_function_vdefault' AND cur_user = current_user) = v_featurecat THEN @@ -484,16 +484,16 @@ BEGIN -- Epa type IF (NEW.epa_type IS NULL) THEN - NEW.epa_type:= (SELECT epa_default FROM cat_feature_gully WHERE cat_feature_gully.id=NEW.gully_type)::text; + NEW.epa_type:= (SELECT epa_default FROM cat_feature_gully WHERE cat_feature_gully.id=NEW.gully_type)::text; END IF; -- elevation from raster - IF (SELECT json_extract_path_text(value::json,'activated')::boolean FROM config_param_system WHERE parameter='admin_raster_dem') IS TRUE + IF (SELECT json_extract_path_text(value::json,'activated')::boolean FROM config_param_system WHERE parameter='admin_raster_dem') IS TRUE AND (NEW.top_elev IS NULL) AND (SELECT upper(value) FROM config_param_user WHERE parameter = 'edit_insert_elevation_from_dem' and cur_user = current_user) = 'TRUE' THEN NEW.top_elev = (SELECT ST_Value(rast,1,NEW.the_geom,true) FROM v_ext_raster_dem WHERE id = (SELECT id FROM v_ext_raster_dem WHERE st_dwithin (envelope, NEW.the_geom, 1) LIMIT 1)); - END IF; + END IF; --set rotation field WITH index_query AS( @@ -506,12 +506,12 @@ BEGIN ELSE v_rotation = st_azimuth (st_lineinterpolatepoint(v_thegeom,v_linelocatepoint), st_lineinterpolatepoint(v_thegeom,v_linelocatepoint+0.01)); END IF; - - -- use automatic rotation only on INSERT. On update it's only posible manual rotation update + + -- use automatic rotation only on INSERT. On update it's only posible manual rotation update IF v_autorotation_disabled IS NULL OR v_autorotation_disabled IS FALSE THEN NEW.rotation = v_rotation*180/pi(); END IF; - + v_rotation = -(v_rotation - pi()/2); -- double geometry @@ -523,26 +523,26 @@ BEGIN IF v_length*v_width IS NULL THEN EXECUTE 'SELECT gw_fct_getmessage($${"client":{"device":4, "infoType":1, "lang":"ES"},"feature":{}, - "data":{"message":"3062", "function":"1206","debug_msg":"'||NEW.gratecat_id::text||'"}}$$);'; - + "data":{"message":"3062", "function":"1206","debug_msg":"'||NEW.gratecat_id::text||'"}}$$);'; + ELSIF v_length*v_width != 0 THEN - + -- get grate dimensions v_unitsfactor = 0.01*v_unitsfactor ; -- using 0.01 to convert from cms of catalog to meters of the map - + --multiply length x units if is not null IF NEW.units IS NOT NULL THEN v_length = v_length*v_unitsfactor*NEW.units; ELSE v_length = v_length*v_unitsfactor; END IF; - + v_width = v_width*v_unitsfactor; -- calculate center coordinates v_x = st_x(NEW.the_geom); v_y = st_y(NEW.the_geom); - + -- calculate dx & dy to fix extend from center dx = v_length/2; dy = v_width/2; @@ -550,23 +550,23 @@ BEGIN -- calculate the extend polygon p01x = v_x - dx*cos(v_rotation)-dy*sin(v_rotation); p01y = v_y - dx*sin(v_rotation)+dy*cos(v_rotation); - + p02x = v_x + dx*cos(v_rotation)-dy*sin(v_rotation); p02y = v_y + dx*sin(v_rotation)+dy*cos(v_rotation); p21x = v_x - dx*cos(v_rotation)+dy*sin(v_rotation); - p21y = v_y - dx*sin(v_rotation)-dy*cos(v_rotation); + p21y = v_y - dx*sin(v_rotation)-dy*cos(v_rotation); p22x = v_x + dx*cos(v_rotation)+dy*sin(v_rotation); p22y = v_y + dx*sin(v_rotation)-dy*cos(v_rotation); - + -- generating the geometry EXECUTE 'SELECT ST_Multi(ST_makePolygon(St_SetSrid(ST_GeomFromText(''LINESTRING(' || p21x ||' '|| p21y || ',' || p22x ||' '|| p22y || ',' || p02x || ' ' || p02y || ','|| p01x ||' '|| p01y || ',' || p21x ||' '|| p21y || ')''),'||v_srid||')))' INTO v_the_geom_pol; - - INSERT INTO polygon(sys_type, the_geom, featurecat_id,feature_id ) + + INSERT INTO polygon(sys_type, the_geom, featurecat_id,feature_id ) VALUES ('GULLY', v_the_geom_pol, NEW.gully_type, NEW.gully_id); END IF; END IF; @@ -574,42 +574,44 @@ BEGIN -- FEATURE INSERT IF v_matfromcat THEN - INSERT INTO gully (gully_id, code, top_elev, "ymax",sandbox, matcat_id, gully_type, gratecat_id, units, groove, connec_arccat_id, connec_length, - connec_depth, siphon, arc_id, sector_id, "state",state_type, annotation, "observ", "comment", dma_id, soilcat_id, function_type, - category_type, fluid_type, location_type, workcat_id, workcat_id_end, workcat_id_plan, buildercat_id, builtdate, enddate, ownercat_id, muni_id, - postcode, district_id, streetaxis_id, postnumber, postcomplement, streetaxis2_id, postnumber2, postcomplement2, descript, rotation, + INSERT INTO gully (gully_id, code, top_elev, "ymax",sandbox, matcat_id, gully_type, gratecat_id, units, groove, connec_arccat_id, connec_length, + connec_depth, siphon, arc_id, sector_id, "state",state_type, annotation, "observ", "comment", dma_id, soilcat_id, function_type, + category_type, fluid_type, location_type, workcat_id, workcat_id_end, workcat_id_plan, buildercat_id, builtdate, enddate, ownercat_id, muni_id, + postcode, district_id, streetaxis_id, postnumber, postcomplement, streetaxis2_id, postnumber2, postcomplement2, descript, rotation, link,verified, the_geom, undelete,label_x, label_y,label_rotation, expl_id, publish, inventory,uncertain, num_value, - lastupdate, lastupdate_user, asset_id, gratecat2_id, epa_type, units_placement, groove_height, groove_length, drainzone_id, expl_id2, adate, adescript, siphon_type, odorflap, connec_y2) - VALUES (NEW.gully_id, NEW.code, NEW.top_elev, NEW."ymax",NEW.sandbox, NEW.matcat_id, NEW.gully_type, NEW.gratecat_id, NEW.units, NEW.groove, - NEW.connec_arccat_id, NEW.connec_length, NEW.connec_depth, NEW.siphon, NEW.arc_id, NEW.sector_id, NEW."state", - NEW.state_type, NEW.annotation, NEW."observ", NEW."comment", NEW.dma_id, NEW.soilcat_id, NEW.function_type, NEW.category_type, - NEW.fluid_type, NEW.location_type, NEW.workcat_id, NEW.workcat_id_end, NEW.workcat_id_plan, NEW.buildercat_id, NEW.builtdate, NEW.enddate, - NEW.ownercat_id, NEW.muni_id, NEW.postcode, NEW.district_id, v_streetaxis, NEW.postnumber, NEW.postcomplement, v_streetaxis2, - NEW.postnumber2, NEW.postcomplement2, NEW.descript, NEW.rotation, NEW.link, NEW.verified, NEW.the_geom, NEW.undelete, - NEW.label_x, NEW.label_y, NEW.label_rotation, NEW.expl_id , NEW.publish, NEW.inventory, + lastupdate, lastupdate_user, asset_id, gratecat2_id, epa_type, units_placement, groove_height, groove_length, drainzone_id, expl_id2, adate, adescript, + siphon_type, odorflap, connec_y2, placement_type) + VALUES (NEW.gully_id, NEW.code, NEW.top_elev, NEW."ymax",NEW.sandbox, NEW.matcat_id, NEW.gully_type, NEW.gratecat_id, NEW.units, NEW.groove, + NEW.connec_arccat_id, NEW.connec_length, NEW.connec_depth, NEW.siphon, NEW.arc_id, NEW.sector_id, NEW."state", + NEW.state_type, NEW.annotation, NEW."observ", NEW."comment", NEW.dma_id, NEW.soilcat_id, NEW.function_type, NEW.category_type, + NEW.fluid_type, NEW.location_type, NEW.workcat_id, NEW.workcat_id_end, NEW.workcat_id_plan, NEW.buildercat_id, NEW.builtdate, NEW.enddate, + NEW.ownercat_id, NEW.muni_id, NEW.postcode, NEW.district_id, v_streetaxis, NEW.postnumber, NEW.postcomplement, v_streetaxis2, + NEW.postnumber2, NEW.postcomplement2, NEW.descript, NEW.rotation, NEW.link, NEW.verified, NEW.the_geom, NEW.undelete, + NEW.label_x, NEW.label_y, NEW.label_rotation, NEW.expl_id , NEW.publish, NEW.inventory, NEW.uncertain, NEW.num_value,NEW.lastupdate, NEW.lastupdate_user, NEW.asset_id, NEW.gratecat2_id, NEW.epa_type, NEW.units_placement, - NEW.groove_height, NEW.groove_length, NEW.drainzone_id,NEW.expl_id2, NEW.adate, NEW.adescript, NEW.siphon_type, NEW.odorflap, NEW.connec_y2); + NEW.groove_height, NEW.groove_length, NEW.drainzone_id,NEW.expl_id2, NEW.adate, NEW.adescript, NEW.siphon_type, NEW.odorflap, NEW.connec_y2, NEW.placement_type); ELSE - INSERT INTO gully (gully_id, code, top_elev, "ymax",sandbox, matcat_id, gully_type, gratecat_id, units, groove, connec_arccat_id, connec_length, - connec_depth, siphon, arc_id, sector_id, "state",state_type, annotation, "observ", "comment", dma_id, soilcat_id, function_type, - category_type, fluid_type, location_type, workcat_id, workcat_id_end, workcat_id_plan, buildercat_id, builtdate, enddate, ownercat_id, muni_id, - postcode, district_id, streetaxis_id, postnumber, postcomplement, streetaxis2_id, postnumber2, postcomplement2, descript, rotation, + INSERT INTO gully (gully_id, code, top_elev, "ymax",sandbox, matcat_id, gully_type, gratecat_id, units, groove, connec_arccat_id, connec_length, + connec_depth, siphon, arc_id, sector_id, "state",state_type, annotation, "observ", "comment", dma_id, soilcat_id, function_type, + category_type, fluid_type, location_type, workcat_id, workcat_id_end, workcat_id_plan, buildercat_id, builtdate, enddate, ownercat_id, muni_id, + postcode, district_id, streetaxis_id, postnumber, postcomplement, streetaxis2_id, postnumber2, postcomplement2, descript, rotation, link,verified, the_geom, undelete,label_x, label_y,label_rotation, expl_id, publish, inventory,uncertain, num_value, - lastupdate, lastupdate_user, asset_id, connec_matcat_id, gratecat2_id, epa_type, units_placement, groove_height, groove_length, drainzone_id, expl_id2, adate, adescript, siphon_type, odorflap, connec_y2) - VALUES (NEW.gully_id, NEW.code, NEW.top_elev, NEW."ymax",NEW.sandbox, NEW.matcat_id, NEW.gully_type, NEW.gratecat_id, NEW.units, NEW.groove, - NEW.connec_arccat_id, NEW.connec_length, NEW.connec_depth, NEW.siphon, NEW.arc_id, NEW.sector_id, NEW."state", - NEW.state_type, NEW.annotation, NEW."observ", NEW."comment", NEW.dma_id, NEW.soilcat_id, NEW.function_type, NEW.category_type, - NEW.fluid_type, NEW.location_type, NEW.workcat_id, NEW.workcat_id_end, NEW.workcat_id_plan, NEW.buildercat_id, NEW.builtdate, NEW.enddate, - NEW.ownercat_id, NEW.muni_id, NEW.postcode, NEW.district_id, v_streetaxis, NEW.postnumber, NEW.postcomplement, v_streetaxis2, - NEW.postnumber2, NEW.postcomplement2, NEW.descript, NEW.rotation, NEW.link, NEW.verified, NEW.the_geom, NEW.undelete, - NEW.label_x, NEW.label_y, NEW.label_rotation, NEW.expl_id , NEW.publish, NEW.inventory, + lastupdate, lastupdate_user, asset_id, connec_matcat_id, gratecat2_id, epa_type, units_placement, groove_height, groove_length, drainzone_id, expl_id2, adate, adescript, + siphon_type, odorflap, connec_y2, placement_type) + VALUES (NEW.gully_id, NEW.code, NEW.top_elev, NEW."ymax",NEW.sandbox, NEW.matcat_id, NEW.gully_type, NEW.gratecat_id, NEW.units, NEW.groove, + NEW.connec_arccat_id, NEW.connec_length, NEW.connec_depth, NEW.siphon, NEW.arc_id, NEW.sector_id, NEW."state", + NEW.state_type, NEW.annotation, NEW."observ", NEW."comment", NEW.dma_id, NEW.soilcat_id, NEW.function_type, NEW.category_type, + NEW.fluid_type, NEW.location_type, NEW.workcat_id, NEW.workcat_id_end, NEW.workcat_id_plan, NEW.buildercat_id, NEW.builtdate, NEW.enddate, + NEW.ownercat_id, NEW.muni_id, NEW.postcode, NEW.district_id, v_streetaxis, NEW.postnumber, NEW.postcomplement, v_streetaxis2, + NEW.postnumber2, NEW.postcomplement2, NEW.descript, NEW.rotation, NEW.link, NEW.verified, NEW.the_geom, NEW.undelete, + NEW.label_x, NEW.label_y, NEW.label_rotation, NEW.expl_id , NEW.publish, NEW.inventory, NEW.uncertain, NEW.num_value,NEW.lastupdate, NEW.lastupdate_user, NEW.asset_id, NEW.connec_matcat_id, NEW.gratecat2_id, - NEW.epa_type, NEW.units_placement, NEW.groove_height, NEW.groove_length, NEW.drainzone_id,NEW.expl_id2, NEW.adate, NEW.adescript, NEW.siphon_type, NEW.odorflap, NEW.connec_y2); + NEW.epa_type, NEW.units_placement, NEW.groove_height, NEW.groove_length, NEW.drainzone_id,NEW.expl_id2, NEW.adate, NEW.adescript, NEW.siphon_type, NEW.odorflap, NEW.connec_y2, NEW.placement_type); END IF; - -- insertint on psector table and setting visible + -- insertint on psector table and setting visible IF NEW.state=2 THEN INSERT INTO plan_psector_x_gully (gully_id, psector_id, state, doable, arc_id) VALUES (NEW.gully_id, v_psector_vdefault, 1, true, NEW.arc_id); @@ -617,7 +619,7 @@ BEGIN -- manage connect2network IF v_connect2network THEN - + IF NEW.arc_id IS NOT NULL THEN EXECUTE 'SELECT gw_fct_linktonetwork($${"client":{"device":4, "infoType":1, "lang":"ES"}, "feature":{"id":'|| array_to_json(array_agg(NEW.gully_id))||'},"data":{"feature_type":"GULLY", "forcedArcs":["'||NEW.arc_id||'"]}}$$)'; @@ -628,7 +630,7 @@ BEGIN -- recover values in order to do not disturb this workflow SELECT * INTO v_arc FROM arc WHERE arc_id = NEW.arc_id; - NEW.pjoint_id = v_arc.arc_id; NEW.pjoint_type = 'ARC'; NEW.sector_id = v_arc.sector_id; NEW.dma_id = v_arc.dma_id; + NEW.pjoint_id = v_arc.arc_id; NEW.pjoint_type = 'ARC'; NEW.sector_id = v_arc.sector_id; NEW.dma_id = v_arc.dma_id; END IF; -- childtable insert @@ -646,28 +648,28 @@ BEGIN END IF; END LOOP; END IF; - + -- EPA INSERT - IF (NEW.epa_type = 'GULLY') THEN - INSERT INTO inp_gully (gully_id, outlet_type, method, weir_cd, orifice_cd, efficiency) + IF (NEW.epa_type = 'GULLY') THEN + INSERT INTO inp_gully (gully_id, outlet_type, method, weir_cd, orifice_cd, efficiency) VALUES (NEW.gully_id, v_epa_gully_outlet_type, v_epa_gully_method, v_epa_gully_weir_cd, v_epa_gully_orifice_cd, v_epa_gully_efficiency); END IF; - + RETURN NEW; ELSIF TG_OP = 'UPDATE' THEN -- EPA update - IF (OLD.epa_type = 'GULLY') AND (NEW.epa_type = 'UNDEFINED') THEN + IF (OLD.epa_type = 'GULLY') AND (NEW.epa_type = 'UNDEFINED') THEN DELETE FROM inp_gully WHERE gully_id = OLD.gully_id; - ELSIF (OLD.epa_type = 'UNDEFINED') AND (NEW.epa_type = 'GULLY') THEN - INSERT INTO inp_gully (gully_id, outlet_type, method, weir_cd, orifice_cd, efficiency) - VALUES (NEW.gully_id, v_epa_gully_outlet_type, v_epa_gully_method, v_epa_gully_weir_cd, v_epa_gully_orifice_cd, v_epa_gully_efficiency); + ELSIF (OLD.epa_type = 'UNDEFINED') AND (NEW.epa_type = 'GULLY') THEN + INSERT INTO inp_gully (gully_id, outlet_type, method, weir_cd, orifice_cd, efficiency) + VALUES (NEW.gully_id, v_epa_gully_outlet_type, v_epa_gully_method, v_epa_gully_weir_cd, v_epa_gully_orifice_cd, v_epa_gully_efficiency); END IF; -- UPDATE geom - IF st_equals(NEW.the_geom, OLD.the_geom)is false THEN - UPDATE gully SET the_geom=NEW.the_geom WHERE gully_id = OLD.gully_id; + IF st_equals(NEW.the_geom, OLD.the_geom)is false THEN + UPDATE gully SET the_geom=NEW.the_geom WHERE gully_id = OLD.gully_id; --update elevation from raster IF (SELECT json_extract_path_text(value::json,'activated')::boolean FROM config_param_system WHERE parameter='admin_raster_dem') IS TRUE @@ -676,28 +678,28 @@ BEGIN NEW.top_elev = (SELECT ST_Value(rast,1,NEW.the_geom,true) FROM v_ext_raster_dem WHERE id = (SELECT id FROM v_ext_raster_dem WHERE st_dwithin (envelope, NEW.the_geom, 1) LIMIT 1)); END IF; - + --update associated geometry of element (if exists) and trace_featuregeom is true - v_trace_featuregeom:= (SELECT trace_featuregeom FROM element JOIN element_x_gully USING (element_id) + v_trace_featuregeom:= (SELECT trace_featuregeom FROM element JOIN element_x_gully USING (element_id) WHERE gully_id=NEW.gully_id AND the_geom IS NOT NULL LIMIT 1); -- if trace_featuregeom is false, do nothing IF v_trace_featuregeom IS TRUE THEN - UPDATE v_edit_element SET the_geom = NEW.the_geom WHERE St_dwithin(OLD.the_geom, the_geom, 0.001) + UPDATE v_edit_element SET the_geom = NEW.the_geom WHERE St_dwithin(OLD.the_geom, the_geom, 0.001) AND element_id IN (SELECT element_id FROM element_x_gully WHERE gully_id = NEW.gully_id); END IF; - - END IF; - + + END IF; + -- Reconnect arc_id IF (coalesce (NEW.arc_id,'') != coalesce(OLD.arc_id,'')) THEN -- when connec_id comes on psector_table IF NEW.state = 1 AND (SELECT gully_id FROM plan_psector_x_gully JOIN selector_psector USING (psector_id) WHERE gully_id=NEW.gully_id AND psector_id = v_psector_vdefault AND cur_user = current_user AND state = 1) IS NOT NULL THEN - + EXECUTE 'SELECT gw_fct_linktonetwork($${"client":{"device":4, "infoType":1, "lang":"ES"}, - "feature":{"id":'|| array_to_json(array_agg(NEW.gully_id))||'},"data":{"feature_type":"GULLY", "forceEndPoint":"true", "forcedArcs":["'||NEW.arc_id||'"]}}$$)'; - + "feature":{"id":'|| array_to_json(array_agg(NEW.gully_id))||'},"data":{"feature_type":"GULLY", "forceEndPoint":"true", "forcedArcs":["'||NEW.arc_id||'"]}}$$)'; + ELSIF NEW.state = 2 THEN IF NEW.arc_id IS NOT NULL THEN @@ -706,7 +708,7 @@ BEGIN WHERE gully_id=NEW.gully_id AND psector_id = v_psector_vdefault AND cur_user = current_user AND state = 1) IS NOT NULL THEN EXECUTE 'SELECT gw_fct_linktonetwork($${"client":{"device":4, "infoType":1, "lang":"ES"}, - "feature":{"id":'|| array_to_json(array_agg(NEW.gully_id))||'},"data":{"feature_type":"GULLY", "forceEndPoint":"true", "forcedArcs":["'||NEW.arc_id||'"]}}$$)'; + "feature":{"id":'|| array_to_json(array_agg(NEW.gully_id))||'},"data":{"feature_type":"GULLY", "forceEndPoint":"true", "forcedArcs":["'||NEW.arc_id||'"]}}$$)'; END IF; ELSE IF (SELECT link_id FROM plan_psector_x_gully JOIN selector_psector USING (psector_id) @@ -716,8 +718,8 @@ BEGIN ELSE UPDATE plan_psector_x_gully SET arc_id = null, link_id = null WHERE gully_id=NEW.gully_id AND psector_id = v_psector_vdefault AND state = 1; END IF; - - -- setting values + + -- setting values NEW.sector_id = 0; NEW.dma_id = 0; NEW.pjoint_id = null; NEW.pjoint_type = null; END IF; ELSE @@ -729,13 +731,13 @@ BEGIN -- when link exists IF (SELECT link_id FROM link WHERE state = 1 and feature_id = NEW.gully_id) IS NOT NULL THEN EXECUTE 'SELECT gw_fct_linktonetwork($${"client":{"device":4, "infoType":1, "lang":"ES"}, - "feature":{"id":'|| array_to_json(array_agg(NEW.gully_id))||'},"data":{"feature_type":"GULLY", "forceEndPoint":"true", "forcedArcs":["'||NEW.arc_id||'"]}}$$)'; + "feature":{"id":'|| array_to_json(array_agg(NEW.gully_id))||'},"data":{"feature_type":"GULLY", "forceEndPoint":"true", "forcedArcs":["'||NEW.arc_id||'"]}}$$)'; END IF; -- recover values in order to do not disturb this workflow SELECT * INTO v_arc FROM arc WHERE arc_id = NEW.arc_id; NEW.pjoint_id = v_arc.arc_id; NEW.pjoint_type = 'ARC'; NEW.sector_id = v_arc.sector_id; NEW.dma_id = v_arc.dma_id; - + ELSE IF (SELECT count(*)FROM link WHERE feature_id = NEW.gully_id AND state = 1) > 0 THEN EXECUTE 'SELECT gw_fct_getmessage($${"client":{"device":4, "infoType":1, "lang":"ES"},"feature":{}, @@ -746,7 +748,7 @@ BEGIN END IF; END IF; END IF; - + -- State_type IF NEW.state=0 AND OLD.state=1 THEN IF (SELECT state FROM value_state_type WHERE id=NEW.state_type) != NEW.state THEN @@ -755,53 +757,53 @@ BEGIN NEW.state_type=(SELECT id from value_state_type WHERE state=0 LIMIT 1); IF NEW.state_type IS NULL THEN EXECUTE 'SELECT gw_fct_getmessage($${"client":{"device":4, "infoType":1, "lang":"ES"},"feature":{}, - "data":{"message":"2110", "function":"1206","debug_msg":null}}$$);'; + "data":{"message":"2110", "function":"1206","debug_msg":null}}$$);'; END IF; END IF; END IF; - + -- Automatic downgrade of associated link UPDATE link SET state=0 WHERE feature_id=OLD.gully_id; END IF; -- Looking for state control and insert planified connecs to default psector - IF (NEW.state != OLD.state) THEN - + IF (NEW.state != OLD.state) THEN + PERFORM gw_fct_state_control('GULLY', NEW.gully_id, NEW.state, TG_OP); - + IF NEW.state = 2 AND OLD.state=1 THEN - + v_link = (SELECT link_id FROM link WHERE feature_id = NEW.gully_id AND state = 1 LIMIT 1); - + INSERT INTO plan_psector_x_gully (gully_id, psector_id, state, doable, link_id, arc_id) VALUES (NEW.gully_id, v_psector_vdefault, 1, true, v_link, NEW.arc_id); - + UPDATE link SET state = 2 WHERE link_id = v_link; END IF; - + IF NEW.state = 1 AND OLD.state=2 THEN - + v_link = (SELECT link_id FROM link WHERE feature_id = NEW.gully_id AND state = 2 LIMIT 1); - + -- force delete UPDATE config_param_user SET value = 'true' WHERE parameter = 'plan_psector_downgrade_feature' AND cur_user= current_user; DELETE FROM plan_psector_x_gully WHERE gully_id=NEW.gully_id; -- recover values UPDATE config_param_user SET value = 'false' WHERE parameter = 'plan_psector_downgrade_feature' AND cur_user= current_user; - UPDATE link SET state = 1 WHERE link_id = v_link; + UPDATE link SET state = 1 WHERE link_id = v_link; END IF; - + UPDATE gully SET state=NEW.state WHERE gully_id = OLD.gully_id; END IF; --check relation state - state_type IF (NEW.state_type != OLD.state_type) AND NEW.state_type NOT IN (SELECT id FROM value_state_type WHERE state = NEW.state) THEN EXECUTE 'SELECT gw_fct_getmessage($${"client":{"device":4, "infoType":1, "lang":"ES"},"feature":{}, - "data":{"message":"3036", "function":"1206","debug_msg":"'||NEW.state::text||'"}}$$);'; - END IF; - + "data":{"message":"3036", "function":"1206","debug_msg":"'||NEW.state::text||'"}}$$);'; + END IF; + --link_path SELECT link_path INTO v_link_path FROM cat_feature WHERE id=NEW.gully_type; IF v_link_path IS NOT NULL THEN @@ -832,29 +834,29 @@ BEGIN v_width = (SELECT width FROM cat_grate WHERE id=NEW.gratecat_id); IF v_length*v_width IS NULL THEN - + EXECUTE 'SELECT gw_fct_getmessage($${"client":{"device":4, "infoType":1, "lang":"ES"},"feature":{}, - "data":{"message":"3062", "function":"1206","debug_msg":"'||NEW.gratecat_id::text||'"}}$$);'; - + "data":{"message":"3062", "function":"1206","debug_msg":"'||NEW.gratecat_id::text||'"}}$$);'; + ELSIF v_length*v_width != 0 THEN -- get grate dimensions v_unitsfactor = 0.01*v_unitsfactor; -- using 0.01 to convert from cms of catalog to meters of the map - + --multiply length x units if is not null IF NEW.units IS NOT NULL THEN v_length = v_length*v_unitsfactor*NEW.units; ELSE v_length = v_length*v_unitsfactor; END IF; - + v_width = v_width*v_unitsfactor; -- calculate center coordinates v_x = st_x(NEW.the_geom); v_y = st_y(NEW.the_geom); - + -- calculate dx & dy to fix extend from center dx = v_length/2; dy = v_width/2; @@ -862,23 +864,23 @@ BEGIN -- calculate the extend polygon p01x = v_x - dx*cos(v_rotation)-dy*sin(v_rotation); p01y = v_y - dx*sin(v_rotation)+dy*cos(v_rotation); - + p02x = v_x + dx*cos(v_rotation)-dy*sin(v_rotation); p02y = v_y + dx*sin(v_rotation)+dy*cos(v_rotation); p21x = v_x - dx*cos(v_rotation)+dy*sin(v_rotation); - p21y = v_y - dx*sin(v_rotation)-dy*cos(v_rotation); + p21y = v_y - dx*sin(v_rotation)-dy*cos(v_rotation); p22x = v_x + dx*cos(v_rotation)+dy*sin(v_rotation); p22y = v_y + dx*sin(v_rotation)-dy*cos(v_rotation); - + -- generating the geometry EXECUTE 'SELECT ST_Multi(ST_makePolygon(St_SetSrid(ST_GeomFromText(''LINESTRING(' || p21x ||' '|| p21y || ',' || p22x ||' '|| p22y || ',' || p02x || ' ' || p02y || ','|| p01x ||' '|| p01y || ',' || p21x ||' '|| p21y || ')''),'||v_srid||')))' INTO v_the_geom_pol; IF (SELECT pol_id FROM polygon WHERE feature_id = NEW.gully_id) IS NULL THEN - INSERT INTO polygon(sys_type, the_geom, featurecat_id,feature_id ) + INSERT INTO polygon(sys_type, the_geom, featurecat_id,feature_id ) VALUES ('GULLY', v_the_geom_pol, NEW.gully_type, NEW.gully_id); ELSE UPDATE polygon SET the_geom = v_the_geom_pol WHERE feature_id =NEW.gully_id; @@ -893,37 +895,39 @@ BEGIN -- UPDATE values IF v_matfromcat THEN - UPDATE gully - SET code=NEW.code, top_elev=NEW.top_elev, ymax=NEW."ymax", sandbox=NEW.sandbox, matcat_id=NEW.matcat_id, gully_type=NEW.gully_type, gratecat_id=NEW.gratecat_id, units=NEW.units, - groove=NEW.groove, connec_arccat_id=NEW.connec_arccat_id, connec_length=NEW.connec_length, connec_depth=NEW.connec_depth, siphon=NEW.siphon, sector_id=NEW.sector_id, - "state"=NEW."state", state_type=NEW.state_type, annotation=NEW.annotation, "observ"=NEW."observ", "comment"=NEW."comment", dma_id=NEW.dma_id, soilcat_id=NEW.soilcat_id, - function_type=NEW.function_type, category_type=NEW.category_type, fluid_type=NEW.fluid_type, location_type=NEW.location_type, workcat_id=NEW.workcat_id, + UPDATE gully + SET code=NEW.code, top_elev=NEW.top_elev, ymax=NEW."ymax", sandbox=NEW.sandbox, matcat_id=NEW.matcat_id, gully_type=NEW.gully_type, gratecat_id=NEW.gratecat_id, units=NEW.units, + groove=NEW.groove, connec_arccat_id=NEW.connec_arccat_id, connec_length=NEW.connec_length, connec_depth=NEW.connec_depth, siphon=NEW.siphon, sector_id=NEW.sector_id, + "state"=NEW."state", state_type=NEW.state_type, annotation=NEW.annotation, "observ"=NEW."observ", "comment"=NEW."comment", dma_id=NEW.dma_id, soilcat_id=NEW.soilcat_id, + function_type=NEW.function_type, category_type=NEW.category_type, fluid_type=NEW.fluid_type, location_type=NEW.location_type, workcat_id=NEW.workcat_id, workcat_id_end=NEW.workcat_id_end, workcat_id_plan=NEW.workcat_id_plan, buildercat_id=NEW.buildercat_id, builtdate=NEW.builtdate, enddate=NEW.enddate, ownercat_id=NEW.ownercat_id, postcode=NEW.postcode, district_id=NEW.district_id, streetaxis2_id=v_streetaxis2, postnumber2=NEW.postnumber2, postcomplement=NEW.postcomplement, postcomplement2=NEW.postcomplement2, descript=NEW.descript, rotation=NEW.rotation, link=NEW.link, verified=NEW.verified, undelete=NEW.undelete, pjoint_id=NEW.pjoint_id, pjoint_type = NEW.pjoint_type, - label_x=NEW.label_x, label_y=NEW.label_y,label_rotation=NEW.label_rotation, publish=NEW.publish, inventory=NEW.inventory, muni_id=NEW.muni_id, streetaxis_id=v_streetaxis, + label_x=NEW.label_x, label_y=NEW.label_y,label_rotation=NEW.label_rotation, publish=NEW.publish, inventory=NEW.inventory, muni_id=NEW.muni_id, streetaxis_id=v_streetaxis, postnumber=NEW.postnumber, expl_id=NEW.expl_id, uncertain=NEW.uncertain, num_value=NEW.num_value, lastupdate=now(), lastupdate_user=current_user, - asset_id=NEW.asset_id, gratecat2_id = NEW.gratecat2_id, epa_type=NEW.epa_type, units_placement=NEW.units_placement, groove_height=NEW.groove_height, - groove_length=NEW.groove_length, drainzone_id=NEW.drainzone_id, expl_id2=NEW.expl_id2, adate=NEW.adate, adescript=NEW.adescript, siphon_type=NEW.siphon_type, odorflap=NEW.odorflap, connec_y2=NEW.connec_y2 + asset_id=NEW.asset_id, gratecat2_id = NEW.gratecat2_id, epa_type=NEW.epa_type, units_placement=NEW.units_placement, groove_height=NEW.groove_height, + groove_length=NEW.groove_length, drainzone_id=NEW.drainzone_id, expl_id2=NEW.expl_id2, adate=NEW.adate, adescript=NEW.adescript, siphon_type=NEW.siphon_type, odorflap=NEW.odorflap, connec_y2=NEW.connec_y2, + placement_type=NEW.placement_type WHERE gully_id = OLD.gully_id; ELSE - UPDATE gully - SET code=NEW.code, top_elev=NEW.top_elev, ymax=NEW."ymax", sandbox=NEW.sandbox, matcat_id=NEW.matcat_id, gully_type=NEW.gully_type, gratecat_id=NEW.gratecat_id, units=NEW.units, - groove=NEW.groove, connec_arccat_id=NEW.connec_arccat_id, connec_length=NEW.connec_length, connec_depth=NEW.connec_depth, siphon=NEW.siphon, sector_id=NEW.sector_id, - "state"=NEW."state", state_type=NEW.state_type, annotation=NEW.annotation, "observ"=NEW."observ", "comment"=NEW."comment", dma_id=NEW.dma_id, soilcat_id=NEW.soilcat_id, - function_type=NEW.function_type, category_type=NEW.category_type, fluid_type=NEW.fluid_type, location_type=NEW.location_type, workcat_id=NEW.workcat_id, + UPDATE gully + SET code=NEW.code, top_elev=NEW.top_elev, ymax=NEW."ymax", sandbox=NEW.sandbox, matcat_id=NEW.matcat_id, gully_type=NEW.gully_type, gratecat_id=NEW.gratecat_id, units=NEW.units, + groove=NEW.groove, connec_arccat_id=NEW.connec_arccat_id, connec_length=NEW.connec_length, connec_depth=NEW.connec_depth, siphon=NEW.siphon, sector_id=NEW.sector_id, + "state"=NEW."state", state_type=NEW.state_type, annotation=NEW.annotation, "observ"=NEW."observ", "comment"=NEW."comment", dma_id=NEW.dma_id, soilcat_id=NEW.soilcat_id, + function_type=NEW.function_type, category_type=NEW.category_type, fluid_type=NEW.fluid_type, location_type=NEW.location_type, workcat_id=NEW.workcat_id, workcat_id_end=NEW.workcat_id_end, workcat_id_plan=NEW.workcat_id_plan, buildercat_id=NEW.buildercat_id, builtdate=NEW.builtdate, enddate=NEW.enddate, ownercat_id=NEW.ownercat_id, postcode=NEW.postcode, district_id=NEW.district_id, streetaxis2_id=v_streetaxis2, postnumber2=NEW.postnumber2, postcomplement=NEW.postcomplement, postcomplement2=NEW.postcomplement2, descript=NEW.descript, rotation=NEW.rotation, link=NEW.link, verified=NEW.verified, undelete=NEW.undelete, pjoint_id=NEW.pjoint_id, pjoint_type = NEW.pjoint_type, - label_x=NEW.label_x, label_y=NEW.label_y,label_rotation=NEW.label_rotation, publish=NEW.publish, inventory=NEW.inventory, muni_id=NEW.muni_id, streetaxis_id=v_streetaxis, + label_x=NEW.label_x, label_y=NEW.label_y,label_rotation=NEW.label_rotation, publish=NEW.publish, inventory=NEW.inventory, muni_id=NEW.muni_id, streetaxis_id=v_streetaxis, postnumber=NEW.postnumber, expl_id=NEW.expl_id, uncertain=NEW.uncertain, num_value=NEW.num_value, lastupdate=now(), lastupdate_user=current_user, - asset_id=NEW.asset_id, gratecat2_id = NEW.gratecat2_id, epa_type=NEW.epa_type, units_placement=NEW.units_placement, groove_height=NEW.groove_height, - groove_length=NEW.groove_length, drainzone_id=NEW.drainzone_id, expl_id2=NEW.expl_id2, adate=NEW.adate, adescript=NEW.adescript, siphon_type=NEW.siphon_type, odorflap=NEW.odorflap, connec_y2=NEW.connec_y2 + asset_id=NEW.asset_id, gratecat2_id = NEW.gratecat2_id, epa_type=NEW.epa_type, units_placement=NEW.units_placement, groove_height=NEW.groove_height, + groove_length=NEW.groove_length, drainzone_id=NEW.drainzone_id, expl_id2=NEW.expl_id2, adate=NEW.adate, adescript=NEW.adescript, siphon_type=NEW.siphon_type, odorflap=NEW.odorflap, connec_y2=NEW.connec_y2, + placement_type=NEW.placement_type WHERE gully_id = OLD.gully_id; END IF; - + -- childtable update IF v_customfeature IS NOT NULL THEN FOR v_addfields IN SELECT * FROM sys_addfields @@ -951,7 +955,7 @@ BEGIN END IF; RETURN NEW; - + ELSIF TG_OP = 'DELETE' THEN @@ -964,7 +968,7 @@ BEGIN -- force plan_psector_force_delete SELECT value INTO v_force_delete FROM config_param_user WHERE parameter = 'plan_psector_force_delete' and cur_user = current_user; UPDATE config_param_user SET value = 'true' WHERE parameter = 'plan_psector_force_delete' and cur_user = current_user; - + DELETE FROM gully WHERE gully_id = OLD.gully_id; -- restore plan_psector_force_delete @@ -986,7 +990,7 @@ BEGIN END LOOP; RETURN NULL; - + END IF; END; diff --git a/ud/ftrg/ud_gw_trg_edit_node.sql b/ud/ftrg/ud_gw_trg_edit_node.sql index 6832f15130..c34dfbf2c3 100644 --- a/ud/ftrg/ud_gw_trg_edit_node.sql +++ b/ud/ftrg/ud_gw_trg_edit_node.sql @@ -10,7 +10,7 @@ This version of Giswater is provided by Giswater Association CREATE OR REPLACE FUNCTION SCHEMA_NAME.gw_trg_edit_node() RETURNS trigger AS $BODY$ -DECLARE +DECLARE v_inp_table varchar; v_man_table varchar; v_new_v_man_table varchar; @@ -31,7 +31,7 @@ v_streetaxis text; v_streetaxis2 text; v_matfromcat boolean = false; v_sys_type text; -v_doublegeometry boolean; +v_doublegeometry boolean; v_length float; v_width float; v_rotation float; @@ -39,9 +39,9 @@ v_unitsfactor float; v_linelocatepoint float; v_thegeom public.geometry; v_the_geom_pol public.geometry; -p21x float; +p21x float; p02x float; -p21y float; +p21y float; p02y float; p22x float; p22y float; @@ -89,7 +89,7 @@ BEGIN v_type_v_man_table:=v_man_table; - -- get data from config table + -- get data from config table v_promixity_buffer = (SELECT "value" FROM config_param_system WHERE "parameter"='edit_feature_buffer_on_mapzone'); v_srid = (SELECT epsg FROM sys_version ORDER BY id DESC LIMIT 1); @@ -106,29 +106,29 @@ BEGIN v_auto_streetvalues_buffer := (SELECT (value::json->>'buffer')::integer FROM config_param_system WHERE parameter = 'edit_auto_streetvalues'); v_auto_streetvalues_field := (SELECT (value::json->>'field')::text FROM config_param_system WHERE parameter = 'edit_auto_streetvalues'); - + IF TG_OP = 'INSERT' OR TG_OP = 'UPDATE' THEN IF NEW.node_type IS NOT NULL THEN -- man2inp_values v_man_view = (SELECT child_layer FROM cat_feature WHERE id = NEW.node_type); v_input = concat('{"feature":{"type":"node", "childLayer":"',v_man_view,'", "id":"',NEW.node_id,'"}}'); - --check if feature is double geom + --check if feature is double geom EXECUTE 'SELECT json_extract_path_text(double_geom,''activated'')::boolean, json_extract_path_text(double_geom,''value'') FROM cat_feature_node WHERE id='||quote_literal(NEW.node_type)||'' INTO v_doublegeometry, v_doublegeom_buffer; END IF; - + -- check if streetname exists IF NEW.streetname IS NOT NULL AND ((NEW.streetname NOT IN (SELECT DISTINCT descript FROM v_ext_streetaxis)) OR (NEW.streetname2 NOT IN (SELECT DISTINCT descript FROM v_ext_streetaxis))) THEN EXECUTE 'SELECT gw_fct_getmessage($${"client":{"device":4, "infoType":1, "lang":"ES"},"feature":{}, "data":{"message":"3246", "function":"1220","debug_msg":null}}$$);'; END IF; - + -- transforming streetaxis name into id v_streetaxis = (SELECT id FROM v_ext_streetaxis WHERE (muni_id = NEW.muni_id OR muni_id IS NULL) AND descript = NEW.streetname LIMIT 1); v_streetaxis2 = (SELECT id FROM v_ext_streetaxis WHERE (muni_id = NEW.muni_id OR muni_id IS NULL) AND descript = NEW.streetname2 LIMIT 1); - + -- managing matcat IF (SELECT matcat_id FROM cat_node WHERE id = NEW.nodecat_id) IS NOT NULL THEN v_matfromcat = true; @@ -139,7 +139,7 @@ BEGIN IF (TG_OP = 'INSERT' OR TG_OP = 'UPDATE') AND v_doublegeometry AND v_man_table = 'man_netgully' THEN v_unitsfactor = v_doublegeom_buffer; - + --set rotation field WITH index_query AS( SELECT ST_Distance(the_geom, NEW.the_geom) as distance, the_geom FROM arc WHERE state=1 ORDER BY the_geom <-> NEW.the_geom LIMIT 10) @@ -164,7 +164,7 @@ BEGIN v_length = v_doublegeom_buffer*100; v_width = v_doublegeom_buffer*100; END IF; - + -- transform grate dimensions v_unitsfactor = 0.01*v_unitsfactor ; -- using 0.01 to convert from cms of catalog to meters of the map v_length = v_length*v_unitsfactor; @@ -186,17 +186,17 @@ BEGIN p02y = v_y + dx*sin(v_rotation)+dy*cos(v_rotation); p21x = v_x - dx*cos(v_rotation)+dy*sin(v_rotation); - p21y = v_y - dx*sin(v_rotation)-dy*cos(v_rotation); + p21y = v_y - dx*sin(v_rotation)-dy*cos(v_rotation); p22x = v_x + dx*cos(v_rotation)+dy*sin(v_rotation); p22y = v_y + dx*sin(v_rotation)-dy*cos(v_rotation); - + -- generating the geometry EXECUTE 'SELECT ST_Multi(ST_makePolygon(St_SetSrid(ST_GeomFromText(''LINESTRING(' || p21x ||' '|| p21y || ',' || p22x ||' '|| p22y || ',' || p02x || ' ' || p02y || ','|| p01x ||' '|| p01y || ',' || p21x ||' '|| p21y || ')''),'||v_srid||')))' INTO v_the_geom_pol; END IF; - + -- Control insertions ID IF TG_OP = 'INSERT' THEN @@ -204,14 +204,14 @@ BEGIN IF NEW.state = 2 THEN INSERT INTO selector_psector (psector_id, cur_user) VALUES (v_psector, current_user) ON CONFLICT DO NOTHING; END IF; - + -- Node ID IF NEW.node_id != (SELECT last_value::text FROM urn_id_seq) OR NEW.node_id IS NULL THEN NEW.node_id:= (SELECT nextval('urn_id_seq')); END IF; - + v_input = concat('{"feature":{"type":"node", "childLayer":"',v_man_view,'", "id":"',NEW.node_id,'"}}'); - + -- get sys type for parent table IF v_man_table = 'parent' THEN v_sys_type := (SELECT type FROM cat_feature_node JOIN cat_node ON cat_node.node_type=cat_feature_node.id WHERE cat_node.id = NEW.nodecat_id); @@ -223,7 +223,7 @@ BEGIN EXECUTE 'SELECT gw_fct_getmessage($${"client":{"device":4, "infoType":1, "lang":"ES"},"feature":{}, "data":{"message":"1004", "function":"1220","debug_msg":null}}$$);'; END IF; - + IF v_customfeature IS NOT NULL THEN NEW.node_type:=v_customfeature; END IF; @@ -232,7 +232,7 @@ BEGIN IF NEW.node_type IS NULL THEN NEW.node_type:= (SELECT c.id FROM cat_feature_node c JOIN cat_node s ON c.id = s.node_type WHERE s.id=NEW.nodecat_id); END IF; - + -- get it from vdefault IF NEW.node_type IS NULL AND v_man_table='parent' THEN NEW.node_type:= (SELECT "value" FROM config_param_user WHERE "parameter"='edit_nodetype_vdefault' AND "cur_user"="current_user"() LIMIT 1); @@ -245,148 +245,148 @@ BEGIN -- Epa type IF (NEW.epa_type IS NULL) THEN - NEW.epa_type:= (SELECT epa_default FROM cat_feature_node WHERE id=NEW.node_type LIMIT 1)::text; + NEW.epa_type:= (SELECT epa_default FROM cat_feature_node WHERE id=NEW.node_type LIMIT 1)::text; END IF; -- Node catalog IF (NEW.nodecat_id IS NULL) THEN IF ((SELECT COUNT(*) FROM cat_node WHERE active IS TRUE) = 0) THEN EXECUTE 'SELECT gw_fct_getmessage($${"client":{"device":4, "infoType":1, "lang":"ES"},"feature":{}, - "data":{"message":"1006", "function":"1220","debug_msg":null}}$$);'; - END IF; + "data":{"message":"1006", "function":"1220","debug_msg":null}}$$);'; + END IF; NEW.nodecat_id:= (SELECT "value" FROM config_param_user WHERE "parameter"='edit_nodecat_vdefault' AND "cur_user"="current_user"() LIMIT 1); END IF; - + -- Exploitation IF (NEW.expl_id IS NULL) THEN - + -- control error without any mapzones defined on the table of mapzone IF ((SELECT COUNT(*) FROM exploitation WHERE active IS TRUE) = 0) THEN EXECUTE 'SELECT gw_fct_getmessage($${"client":{"device":4, "infoType":1, "lang":"ES"},"feature":{}, "data":{"message":"1110", "function":"1220","debug_msg":null}}$$);'; END IF; - + -- getting value default IF (NEW.expl_id IS NULL) THEN NEW.expl_id := (SELECT "value" FROM config_param_user WHERE "parameter"='edit_exploitation_vdefault' AND "cur_user"="current_user"() LIMIT 1); END IF; - + -- getting value from geometry of mapzone IF (NEW.expl_id IS NULL) THEN SELECT count(*) INTO v_count FROM exploitation WHERE ST_DWithin(NEW.the_geom, exploitation.the_geom,0.001) AND active IS TRUE; IF v_count = 1 THEN NEW.expl_id = (SELECT expl_id FROM exploitation WHERE ST_DWithin(NEW.the_geom, exploitation.the_geom,0.001) AND active IS TRUE LIMIT 1); ELSE - NEW.expl_id =(SELECT expl_id FROM v_edit_arc WHERE ST_DWithin(NEW.the_geom, v_edit_arc.the_geom, v_promixity_buffer) + NEW.expl_id =(SELECT expl_id FROM v_edit_arc WHERE ST_DWithin(NEW.the_geom, v_edit_arc.the_geom, v_promixity_buffer) order by ST_Distance (NEW.the_geom, v_edit_arc.the_geom) LIMIT 1); - END IF; + END IF; END IF; - + -- control error when no value IF (NEW.expl_id IS NULL) THEN EXECUTE 'SELECT gw_fct_getmessage($${"client":{"device":4, "infoType":1, "lang":"ES"},"feature":{}, "data":{"message":"2012", "function":"1220","debug_msg":"'||NEW.node_id::text||'"}}$$);'; - END IF; + END IF; END IF; - + -- Sector IF (NEW.sector_id IS NULL) THEN - + -- control error without any mapzones defined on the table of mapzone IF ((SELECT COUNT(*) FROM sector WHERE active IS TRUE ) = 0) THEN EXECUTE 'SELECT gw_fct_getmessage($${"client":{"device":4, "infoType":1, "lang":"ES"},"feature":{}, "data":{"message":"1008", "function":"1220","debug_msg":null}}$$);'; END IF; - + -- getting value default IF (NEW.sector_id IS NULL) THEN NEW.sector_id := (SELECT "value" FROM config_param_user WHERE "parameter"='edit_sector_vdefault' AND "cur_user"="current_user"() LIMIT 1); END IF; - + -- getting value from geometry of mapzone IF (NEW.sector_id IS NULL) THEN SELECT count(*) INTO v_count FROM sector WHERE ST_DWithin(NEW.the_geom, sector.the_geom,0.001) AND active IS TRUE; IF v_count = 1 THEN NEW.sector_id = (SELECT sector_id FROM sector WHERE ST_DWithin(NEW.the_geom, sector.the_geom,0.001) AND active IS TRUE LIMIT 1); ELSE - NEW.sector_id =(SELECT sector_id FROM v_edit_arc WHERE ST_DWithin(NEW.the_geom, v_edit_arc.the_geom, v_promixity_buffer) + NEW.sector_id =(SELECT sector_id FROM v_edit_arc WHERE ST_DWithin(NEW.the_geom, v_edit_arc.the_geom, v_promixity_buffer) order by ST_Distance (NEW.the_geom, v_edit_arc.the_geom) LIMIT 1); - END IF; + END IF; END IF; - + -- control error when no value IF (NEW.sector_id IS NULL) THEN NEW.sector_id = 0; - END IF; + END IF; END IF; - + -- Dma IF (NEW.dma_id IS NULL) THEN - + -- control error without any mapzones defined on the table of mapzone IF ((SELECT COUNT(*) FROM dma WHERE active IS TRUE ) = 0) THEN EXECUTE 'SELECT gw_fct_getmessage($${"client":{"device":4, "infoType":1, "lang":"ES"},"feature":{}, "data":{"message":"1012", "function":"1220","debug_msg":null}}$$);'; END IF; - + -- getting value default IF (NEW.dma_id IS NULL) THEN NEW.dma_id := (SELECT "value" FROM config_param_user WHERE "parameter"='edit_dma_vdefault' AND "cur_user"="current_user"() LIMIT 1); END IF; - + -- getting value from geometry of mapzone IF (NEW.dma_id IS NULL) THEN SELECT count(*) INTO v_count FROM dma WHERE ST_DWithin(NEW.the_geom, dma.the_geom,0.001) AND active IS TRUE ; IF v_count = 1 THEN NEW.dma_id = (SELECT dma_id FROM dma WHERE ST_DWithin(NEW.the_geom, dma.the_geom,0.001) AND active IS TRUE LIMIT 1); ELSE - NEW.dma_id =(SELECT dma_id FROM v_edit_arc WHERE ST_DWithin(NEW.the_geom, v_edit_arc.the_geom, v_promixity_buffer) + NEW.dma_id =(SELECT dma_id FROM v_edit_arc WHERE ST_DWithin(NEW.the_geom, v_edit_arc.the_geom, v_promixity_buffer) order by ST_Distance (NEW.the_geom, v_edit_arc.the_geom) LIMIT 1); - END IF; + END IF; END IF; - + -- control error when no value IF (NEW.dma_id IS NULL) THEN NEW.dma_id = 0; - END IF; + END IF; END IF; - - -- Municipality + + -- Municipality IF (NEW.muni_id IS NULL) THEN - + -- getting value default IF (NEW.muni_id IS NULL) THEN NEW.muni_id := (SELECT "value" FROM config_param_user WHERE "parameter"='edit_municipality_vdefault' AND "cur_user"="current_user"() LIMIT 1); END IF; - + -- getting value from geometry of mapzone IF (NEW.muni_id IS NULL) THEN SELECT count(*) INTO v_count FROM ext_municipality WHERE ST_DWithin(NEW.the_geom, ext_municipality.the_geom,0.001) AND active IS TRUE ; IF v_count = 1 THEN - NEW.muni_id = (SELECT muni_id FROM ext_municipality WHERE ST_DWithin(NEW.the_geom, ext_municipality.the_geom,0.001) + NEW.muni_id = (SELECT muni_id FROM ext_municipality WHERE ST_DWithin(NEW.the_geom, ext_municipality.the_geom,0.001) AND active IS TRUE LIMIT 1); ELSE - NEW.muni_id =(SELECT muni_id FROM v_edit_arc WHERE ST_DWithin(NEW.the_geom, v_edit_arc.the_geom, v_promixity_buffer) + NEW.muni_id =(SELECT muni_id FROM v_edit_arc WHERE ST_DWithin(NEW.the_geom, v_edit_arc.the_geom, v_promixity_buffer) order by ST_Distance (NEW.the_geom, v_edit_arc.the_geom) LIMIT 1); - END IF; - END IF; + END IF; + END IF; END IF; - - -- District + + -- District IF (NEW.district_id IS NULL) THEN - + -- getting value from geometry of mapzone IF (NEW.district_id IS NULL) THEN SELECT count(*) INTO v_count FROM ext_district WHERE ST_DWithin(NEW.the_geom, ext_district.the_geom,0.001); IF v_count = 1 THEN NEW.district_id = (SELECT district_id FROM ext_district WHERE ST_DWithin(NEW.the_geom, ext_district.the_geom,0.001) LIMIT 1); ELSIF v_count > 1 THEN - NEW.district_id =(SELECT district_id FROM v_edit_arc WHERE ST_DWithin(NEW.the_geom, v_edit_arc.the_geom, v_promixity_buffer) + NEW.district_id =(SELECT district_id FROM v_edit_arc WHERE ST_DWithin(NEW.the_geom, v_edit_arc.the_geom, v_promixity_buffer) order by ST_Distance (NEW.the_geom, v_edit_arc.the_geom) LIMIT 1); - END IF; - END IF; + END IF; + END IF; END IF; - + -- Verified IF (NEW.verified IS NULL) THEN NEW.verified := (SELECT "value" FROM config_param_user WHERE "parameter"='edit_verified_vdefault' AND "cur_user"="current_user"() LIMIT 1); @@ -396,7 +396,7 @@ BEGIN IF (NEW.state IS NULL) THEN NEW.state := (SELECT "value" FROM config_param_user WHERE "parameter"='edit_state_vdefault' AND "cur_user"="current_user"() LIMIT 1); END IF; - + -- State_type IF (NEW.state=0) THEN IF (NEW.state_type IS NULL) THEN @@ -423,57 +423,57 @@ BEGIN EXECUTE 'SELECT gw_fct_getmessage($${"client":{"device":4, "infoType":1, "lang":"ES"},"feature":{}, "data":{"message":"3036", "function":"1220","debug_msg":"'||v_sql::text||'"}}$$);'; END IF; - + --Inventory IF NEW.inventory IS NULL THEN NEW.inventory := (SELECT "value" FROM config_param_system WHERE "parameter"='edit_inventory_sysvdefault'); END IF; - + --Publish IF NEW.publish IS NULL THEN NEW.publish := (SELECT "value" FROM config_param_system WHERE "parameter"='edit_publish_sysvdefault'); - END IF; - + END IF; + --Uncertain IF NEW.uncertain IS NULL THEN NEW.uncertain := (SELECT "value" FROM config_param_system WHERE "parameter"='edit_uncertain_sysvdefault'); END IF; - + -- Code SELECT code_autofill, cat_feature.id, addparam::json->>'code_prefix' INTO v_code_autofill_bool, v_featurecat, v_code_prefix FROM cat_feature WHERE id=NEW.node_type; - + IF v_featurecat IS NOT NULL THEN -- use specific sequence for code when its name matches featurecat_code_seq EXECUTE 'SELECT concat('||quote_literal(lower(v_featurecat))||',''_code_seq'');' INTO v_seq_name; EXECUTE 'SELECT relname FROM pg_catalog.pg_class WHERE relname='||quote_literal(v_seq_name)||';' INTO v_sql; - + IF v_sql IS NOT NULL AND NEW.code IS NULL THEN EXECUTE 'SELECT nextval('||quote_literal(v_seq_name)||');' INTO v_seq_code; NEW.code=concat(v_code_prefix,v_seq_code); END IF; - + --Copy id to code field - IF (v_code_autofill_bool IS TRUE) AND NEW.code IS NULL THEN + IF (v_code_autofill_bool IS TRUE) AND NEW.code IS NULL THEN NEW.code=NEW.node_id; - END IF; - END IF; + END IF; + END IF; -- Workcat_id IF (NEW.workcat_id IS NULL) THEN NEW.workcat_id := (SELECT "value" FROM config_param_user WHERE "parameter"='edit_workcat_vdefault' AND "cur_user"="current_user"() LIMIT 1); END IF; - + --Workcat_id_plan IF (NEW.workcat_id_plan IS NULL AND NEW.state = 2) THEN NEW.workcat_id_plan := (SELECT "value" FROM config_param_user WHERE "parameter"='edit_workcat_id_plan' AND "cur_user"="current_user"() LIMIT 1); END IF; - + -- Ownercat_id IF (NEW.ownercat_id IS NULL) THEN NEW.ownercat_id := (SELECT "value" FROM config_param_user WHERE "parameter"='edit_ownercat_vdefault' AND "cur_user"="current_user"() LIMIT 1); END IF; - + -- Soilcat_id IF (NEW.soilcat_id IS NULL) THEN NEW.soilcat_id := (SELECT "value" FROM config_param_user WHERE "parameter"='edit_soilcat_vdefault' AND "cur_user"="current_user"() LIMIT 1); @@ -488,8 +488,8 @@ BEGIN END IF; --Address - IF (v_streetaxis IS NULL) THEN - IF (v_auto_streetvalues_status is true) THEN + IF (v_streetaxis IS NULL) THEN + IF (v_auto_streetvalues_status is true) THEN v_streetaxis := (select v_ext_streetaxis.id from v_ext_streetaxis join node on ST_DWithin(NEW.the_geom, v_ext_streetaxis.the_geom, v_auto_streetvalues_buffer) order by ST_Distance(NEW.the_geom, v_ext_streetaxis.the_geom) LIMIT 1); @@ -497,7 +497,7 @@ BEGIN END IF; --Postnumber/postcomplement - IF (v_auto_streetvalues_status) IS TRUE THEN + IF (v_auto_streetvalues_status) IS TRUE THEN IF (v_auto_streetvalues_field = 'postcomplement') THEN IF (NEW.postcomplement IS NULL) THEN NEW.postcomplement = (select ext_address.postnumber from ext_address @@ -510,7 +510,7 @@ BEGIN join node on ST_DWithin(NEW.the_geom, ext_address.the_geom, v_auto_streetvalues_buffer) order by ST_Distance(NEW.the_geom, ext_address.the_geom) LIMIT 1); END IF; - END IF; + END IF; END IF; -- LINK @@ -521,7 +521,7 @@ BEGIN ELSIF (SELECT (value::json->>'fid')::boolean FROM config_param_system WHERE parameter='edit_custom_link') IS TRUE THEN NEW.link=NEW.node_id; END IF; - + v_featurecat = NEW.node_type; --arc_id @@ -554,7 +554,7 @@ BEGIN IF NEW.category_type IS NULL THEN NEW.category_type = (SELECT value FROM config_param_user WHERE parameter = 'edit_node_category_vdefault' AND cur_user = current_user); - END IF; + END IF; --Function type IF NEW.function_type IS NULL AND (SELECT value FROM config_param_user WHERE parameter = 'edit_feature_function_vdefault' AND cur_user = current_user) = v_featurecat THEN @@ -571,12 +571,12 @@ BEGIN END IF; --elevation from raster - IF (SELECT json_extract_path_text(value::json,'activated')::boolean FROM config_param_system WHERE parameter='admin_raster_dem') IS TRUE + IF (SELECT json_extract_path_text(value::json,'activated')::boolean FROM config_param_system WHERE parameter='admin_raster_dem') IS TRUE AND (NEW.top_elev IS NULL) AND (SELECT upper(value) FROM config_param_user WHERE parameter = 'edit_insert_elevation_from_dem' and cur_user = current_user) = 'TRUE' THEN NEW.top_elev = (SELECT ST_Value(rast,1,NEW.the_geom,true) FROM v_ext_raster_dem WHERE id = (SELECT id FROM v_ext_raster_dem WHERE st_dwithin (envelope, NEW.the_geom, 1) LIMIT 1)); - END IF; + END IF; -- feature insert IF v_matfromcat THEN @@ -584,93 +584,93 @@ BEGIN dma_id,soilcat_id, function_type, category_type,fluid_type,location_type,workcat_id, workcat_id_end, workcat_id_plan, buildercat_id, builtdate, enddate, ownercat_id, muni_id, streetaxis_id, postcode, district_id, streetaxis2_id,postnumber, postnumber2, postcomplement, postcomplement2, descript,rotation,link,verified, undelete,label_x,label_y,label_rotation,the_geom, expl_id, publish, inventory, uncertain, xyz_date, unconnected, num_value, lastupdate, lastupdate_user, - asset_id, drainzone_id, parent_id, arc_id, expl_id2, adate, adescript) - VALUES (NEW.node_id,NEW.code, NEW.top_elev,NEW.custom_top_elev, NEW.ymax, NEW. custom_ymax, NEW. elev, NEW. custom_elev, NEW.node_type,NEW.nodecat_id,NEW.epa_type,NEW.sector_id, + asset_id, drainzone_id, parent_id, arc_id, expl_id2, adate, adescript, placement_type) + VALUES (NEW.node_id,NEW.code, NEW.top_elev,NEW.custom_top_elev, NEW.ymax, NEW. custom_ymax, NEW. elev, NEW. custom_elev, NEW.node_type,NEW.nodecat_id,NEW.epa_type,NEW.sector_id, NEW.state, NEW.state_type, NEW.annotation,NEW.observ, NEW.comment,NEW.dma_id,NEW.soilcat_id, NEW. function_type, NEW.category_type,NEW.fluid_type,NEW.location_type, NEW.workcat_id, NEW.workcat_id_end, NEW.workcat_id_plan, NEW.buildercat_id,NEW.builtdate, NEW.enddate, NEW.ownercat_id, NEW.muni_id, v_streetaxis, NEW.postcode, NEW.district_id,v_streetaxis2,NEW.postnumber,NEW.postnumber2, NEW.postcomplement, NEW.postcomplement2, NEW.descript, NEW.rotation,NEW.link, NEW.verified, NEW.undelete, NEW.label_x,NEW.label_y,NEW.label_rotation,NEW.the_geom, NEW.expl_id, NEW.publish, NEW.inventory, NEW.uncertain, NEW.xyz_date, NEW.unconnected, NEW.num_value, NEW.lastupdate, NEW.lastupdate_user, - NEW.asset_id, NEW.drainzone_id, NEW.parent_id, NEW.arc_id, NEW.expl_id2, NEW.adate, NEW.adescript); + NEW.asset_id, NEW.drainzone_id, NEW.parent_id, NEW.arc_id, NEW.expl_id2, NEW.adate, NEW.adescript, NEW.placement_type); ELSE INSERT INTO node (node_id, code, top_elev, custom_top_elev, ymax, custom_ymax, elev, custom_elev, node_type,nodecat_id,epa_type,sector_id,"state", state_type, annotation,observ,"comment", dma_id,soilcat_id, function_type, category_type,fluid_type,location_type,workcat_id, workcat_id_end, workcat_id_plan, buildercat_id, builtdate, enddate, ownercat_id, muni_id, streetaxis_id, postcode, district_id, streetaxis2_id,postnumber, postnumber2, postcomplement, postcomplement2, descript,rotation,link,verified, undelete,label_x,label_y,label_rotation,the_geom, expl_id, publish, inventory, uncertain, xyz_date, unconnected, num_value, lastupdate, lastupdate_user, matcat_id, - asset_id, drainzone_id, parent_id, arc_id, expl_id2, adate, adescript) - VALUES (NEW.node_id,NEW.code, NEW.top_elev,NEW.custom_top_elev, NEW.ymax, NEW. custom_ymax, NEW. elev, NEW. custom_elev, NEW.node_type,NEW.nodecat_id,NEW.epa_type,NEW.sector_id, + asset_id, drainzone_id, parent_id, arc_id, expl_id2, adate, adescript, placement_type) + VALUES (NEW.node_id,NEW.code, NEW.top_elev,NEW.custom_top_elev, NEW.ymax, NEW. custom_ymax, NEW. elev, NEW. custom_elev, NEW.node_type,NEW.nodecat_id,NEW.epa_type,NEW.sector_id, NEW.state, NEW.state_type, NEW.annotation,NEW.observ, NEW.comment,NEW.dma_id,NEW.soilcat_id, NEW. function_type, NEW.category_type,NEW.fluid_type,NEW.location_type, NEW.workcat_id, NEW.workcat_id_end, NEW.workcat_id_plan, NEW.buildercat_id,NEW.builtdate, NEW.enddate, NEW.ownercat_id, NEW.muni_id, v_streetaxis, NEW.postcode, NEW.district_id, v_streetaxis2,NEW.postnumber,NEW.postnumber2, NEW.postcomplement, NEW.postcomplement2, NEW.descript, NEW.rotation,NEW.link, NEW.verified, NEW.undelete, NEW.label_x,NEW.label_y,NEW.label_rotation,NEW.the_geom, NEW.expl_id, NEW.publish, NEW.inventory, NEW.uncertain, NEW.xyz_date, NEW.unconnected, NEW.num_value, NEW.lastupdate, NEW.lastupdate_user,NEW.matcat_id, - NEW.asset_id, NEW.drainzone_id, NEW.parent_id, NEW.arc_id, NEW.expl_id2, NEW.adate, NEW.adescript); + NEW.asset_id, NEW.drainzone_id, NEW.parent_id, NEW.arc_id, NEW.expl_id2, NEW.adate, NEW.adescript, NEW.placement_type); END IF; - - --check if feature is double geom + + --check if feature is double geom SELECT system_id INTO v_system_id FROM cat_feature WHERE cat_feature.id=NEW.node_type; -- set and get id for polygon IF (v_doublegeometry IS TRUE) THEN - INSERT INTO polygon(sys_type, the_geom, featurecat_id, feature_id ) - VALUES (v_system_id, (SELECT ST_Multi(ST_Envelope(ST_Buffer(node.the_geom,v_doublegeom_buffer))) + INSERT INTO polygon(sys_type, the_geom, featurecat_id, feature_id ) + VALUES (v_system_id, (SELECT ST_Multi(ST_Envelope(ST_Buffer(node.the_geom,v_doublegeom_buffer))) from node where node_id=NEW.node_id), NEW.node_type, NEW.node_id); END IF; - + IF v_man_table='man_junction' THEN - + INSERT INTO man_junction (node_id) VALUES (NEW.node_id); - + ELSIF v_man_table='man_outfall' THEN INSERT INTO man_outfall (node_id, name) VALUES (NEW.node_id,NEW.name); - + ELSIF v_man_table='man_valve' THEN - INSERT INTO man_valve (node_id, name) VALUES (NEW.node_id,NEW.name); - + INSERT INTO man_valve (node_id, name) VALUES (NEW.node_id,NEW.name); + ELSIF v_man_table='man_storage' THEN - + INSERT INTO man_storage (node_id, length, width, custom_area, max_volume, util_volume, min_height, accessibility, name) VALUES(NEW.node_id, NEW.length, NEW.width,NEW.custom_area, NEW.max_volume, NEW.util_volume, NEW.min_height,NEW.accessibility, NEW.name); - + ELSIF v_man_table='man_netgully' THEN - INSERT INTO man_netgully (node_id, sander_depth, gratecat_id, units, groove, siphon, gratecat2_id, groove_length, groove_height, units_placement ) - VALUES(NEW.node_id, NEW.sander_depth, NEW.gratecat_id, NEW.units, + INSERT INTO man_netgully (node_id, sander_depth, gratecat_id, units, groove, siphon, gratecat2_id, groove_length, groove_height, units_placement ) + VALUES(NEW.node_id, NEW.sander_depth, NEW.gratecat_id, NEW.units, NEW.groove, NEW.siphon, NEW.gratecat2_id, NEW.groove_length, NEW.groove_height, NEW.units_placement); - + ELSIF v_man_table='man_chamber' THEN INSERT INTO man_chamber (node_id, length, width, sander_depth, max_volume, util_volume, inlet, bottom_channel, accessibility, name, bottom_mat, slope) - VALUES (NEW.node_id, NEW.length,NEW.width, NEW.sander_depth, NEW.max_volume, NEW.util_volume, + VALUES (NEW.node_id, NEW.length,NEW.width, NEW.sander_depth, NEW.max_volume, NEW.util_volume, NEW.inlet, NEW.bottom_channel, NEW.accessibility,NEW.name, NEW.bottom_mat, NEW.slope); - + ELSIF v_man_table='man_manhole' THEN - - INSERT INTO man_manhole (node_id,length, width, sander_depth, prot_surface, inlet, bottom_channel, accessibility, step_pp, step_fe, step_replace, cover, bottom_mat) - VALUES (NEW.node_id,NEW.length, NEW.width, NEW.sander_depth,NEW.prot_surface, NEW.inlet, NEW.bottom_channel, NEW.accessibility, NEW.step_pp, NEW.step_fe, - NEW.step_replace, NEW.cover, NEW.bottom_mat); - + + INSERT INTO man_manhole (node_id,length, width, sander_depth, prot_surface, inlet, bottom_channel, accessibility, step_pp, step_fe, step_replace, cover, bottom_mat) + VALUES (NEW.node_id,NEW.length, NEW.width, NEW.sander_depth,NEW.prot_surface, NEW.inlet, NEW.bottom_channel, NEW.accessibility, NEW.step_pp, NEW.step_fe, + NEW.step_replace, NEW.cover, NEW.bottom_mat); + ELSIF v_man_table='man_netinit' THEN - - INSERT INTO man_netinit (node_id,length, width, inlet, bottom_channel, accessibility, name) + + INSERT INTO man_netinit (node_id,length, width, inlet, bottom_channel, accessibility, name) VALUES (NEW.node_id, NEW.length,NEW.width,NEW.inlet, NEW.bottom_channel, NEW.accessibility, NEW.name); - + ELSIF v_man_table='man_wjump' THEN - - INSERT INTO man_wjump (node_id, length, width,sander_depth,prot_surface, accessibility, name) - VALUES (NEW.node_id, NEW.length,NEW.width, NEW.sander_depth,NEW.prot_surface,NEW.accessibility, NEW.name); + + INSERT INTO man_wjump (node_id, length, width,sander_depth,prot_surface, accessibility, name) + VALUES (NEW.node_id, NEW.length,NEW.width, NEW.sander_depth,NEW.prot_surface,NEW.accessibility, NEW.name); ELSIF v_man_table='man_wwtp' THEN - + INSERT INTO man_wwtp (node_id, name) VALUES (NEW.node_id, NEW.name); - + ELSIF v_man_table='man_netelement' THEN - - INSERT INTO man_netelement (node_id, serial_number) VALUES(NEW.node_id, NEW.serial_number); - + + INSERT INTO man_netelement (node_id, serial_number) VALUES(NEW.node_id, NEW.serial_number); + ELSIF v_man_table='parent' THEN v_man_table:= (SELECT man_table FROM cat_feature_node c JOIN sys_feature_cat s ON c.type = s.id WHERE c.id=NEW.node_type); @@ -707,9 +707,9 @@ BEGIN ELSIF (NEW.epa_type = 'OUTFALL') THEN INSERT INTO inp_outfall (node_id, outfall_type) VALUES (NEW.node_id, 'NORMAL'); ELSIF (NEW.epa_type = 'STORAGE') THEN - INSERT INTO inp_storage (node_id, storage_type) VALUES (NEW.node_id, 'TABULAR'); + INSERT INTO inp_storage (node_id, storage_type) VALUES (NEW.node_id, 'TABULAR'); ELSIF (NEW.epa_type = 'NETGULLY') THEN - INSERT INTO inp_netgully (node_id, y0, ysur, apond, outlet_type, method, weir_cd, orifice_cd, efficiency) + INSERT INTO inp_netgully (node_id, y0, ysur, apond, outlet_type, method, weir_cd, orifice_cd, efficiency) VALUES (NEW.node_id, 0, 0, 0, v_gully_outlet_type, v_gully_method, v_gully_weir_cd, v_gully_orifice_cd, v_gully_efficiency); END IF; @@ -719,38 +719,38 @@ BEGIN RETURN NEW; ELSIF TG_OP = 'UPDATE' THEN - + -- epa type - IF (NEW.epa_type != OLD.epa_type) THEN + IF (NEW.epa_type != OLD.epa_type) THEN IF (OLD.epa_type = 'JUNCTION') THEN - v_inp_table:= 'inp_junction'; + v_inp_table:= 'inp_junction'; ELSIF (OLD.epa_type = 'DIVIDER') THEN - v_inp_table:= 'inp_divider'; + v_inp_table:= 'inp_divider'; ELSIF (OLD.epa_type = 'OUTFALL') THEN - v_inp_table:= 'inp_outfall'; + v_inp_table:= 'inp_outfall'; ELSIF (OLD.epa_type = 'STORAGE') THEN - v_inp_table:= 'inp_storage'; + v_inp_table:= 'inp_storage'; ELSIF (OLD.epa_type = 'NETGULLY') THEN - v_inp_table:= 'inp_netgully'; + v_inp_table:= 'inp_netgully'; END IF; - + IF v_inp_table IS NOT NULL THEN v_sql:= 'DELETE FROM '||v_inp_table||' WHERE node_id = '||quote_literal(OLD.node_id); EXECUTE v_sql; END IF; - + v_inp_table := NULL; IF (NEW.epa_type = 'JUNCTION') THEN - v_inp_table:= 'inp_junction'; + v_inp_table:= 'inp_junction'; ELSIF (NEW.epa_type = 'DIVIDER') THEN - v_inp_table:= 'inp_divider'; + v_inp_table:= 'inp_divider'; ELSIF (NEW.epa_type = 'OUTFALL') THEN - v_inp_table:= 'inp_outfall'; + v_inp_table:= 'inp_outfall'; ELSIF (NEW.epa_type = 'STORAGE') THEN v_inp_table:= 'inp_storage'; ELSIF (NEW.epa_type = 'NETGULLY') THEN - v_inp_table:= 'inp_netgully'; + v_inp_table:= 'inp_netgully'; END IF; IF v_inp_table IS NOT NULL THEN v_sql:= 'INSERT INTO '||v_inp_table||' (node_id) VALUES ('||quote_literal(NEW.node_id)||') ON CONFLICT (node_id) DO NOTHING'; @@ -767,14 +767,14 @@ BEGIN END IF; -- node type - IF (NEW.node_type <> OLD.node_type) THEN + IF (NEW.node_type <> OLD.node_type) THEN v_new_v_man_table:= (SELECT man_table FROM cat_feature_node c JOIN sys_feature_cat s ON c.type = s.id WHERE c.id = NEW.node_type); v_old_v_man_table:= (SELECT man_table FROM cat_feature_node c JOIN sys_feature_cat s ON c.type = s.id WHERE c.id = OLD.node_type); IF v_new_v_man_table IS NOT NULL THEN v_sql:= 'DELETE FROM '||v_old_v_man_table||' WHERE node_id= '||quote_literal(OLD.node_id); EXECUTE v_sql; v_sql:= 'INSERT INTO '||v_new_v_man_table||' (node_id) VALUES ('||quote_literal(NEW.node_id)||')'; - EXECUTE v_sql; + EXECUTE v_sql; END IF; END IF; @@ -787,10 +787,10 @@ BEGIN = 'plan_psector_vdefault'::text AND config_param_user.cur_user::name = "current_user"() LIMIT 1), 1, true); END IF; IF NEW.state = 1 AND OLD.state=2 THEN - DELETE FROM plan_psector_x_node WHERE node_id=NEW.node_id; - END IF; + DELETE FROM plan_psector_x_node WHERE node_id=NEW.node_id; + END IF; END IF; - + -- State_type IF NEW.state=0 AND OLD.state=1 THEN IF (SELECT state FROM value_state_type WHERE id=NEW.state_type) != NEW.state THEN @@ -804,24 +804,24 @@ BEGIN END IF; END IF; END IF; - + --check relation state - state_type IF (NEW.state_type != OLD.state_type) AND NEW.state_type NOT IN (SELECT id FROM value_state_type WHERE state = NEW.state) THEN EXECUTE 'SELECT gw_fct_getmessage($${"client":{"device":4, "infoType":1, "lang":"ES"},"feature":{}, "data":{"message":"3036", "function":"1220","debug_msg":"'||NEW.state::text||'"}}$$);'; - END IF; + END IF; -- rotation IF NEW.rotation != OLD.rotation THEN UPDATE node SET rotation=NEW.rotation WHERE node_id = OLD.node_id; - END IF; - + END IF; + -- The geom IF st_equals( NEW.the_geom, OLD.the_geom) IS FALSE AND geometrytype(NEW.the_geom)='POINT' THEN UPDATE node SET the_geom=NEW.the_geom WHERE node_id = OLD.node_id; --update elevation from raster - IF (SELECT json_extract_path_text(value::json,'activated')::boolean FROM config_param_system WHERE parameter='admin_raster_dem') IS TRUE + IF (SELECT json_extract_path_text(value::json,'activated')::boolean FROM config_param_system WHERE parameter='admin_raster_dem') IS TRUE AND (NEW.top_elev = OLD.top_elev) AND (SELECT upper(value) FROM config_param_user WHERE parameter = 'edit_update_elevation_from_dem' and cur_user = current_user) = 'TRUE' THEN NEW.top_elev = (SELECT ST_Value(rast,1,NEW.the_geom,true) FROM v_ext_raster_dem WHERE id = @@ -829,18 +829,18 @@ BEGIN END IF; --update associated geometry of element (if exists) and trace_featuregeom is true - v_trace_featuregeom:= (SELECT trace_featuregeom FROM element JOIN element_x_node USING (element_id) + v_trace_featuregeom:= (SELECT trace_featuregeom FROM element JOIN element_x_node USING (element_id) WHERE node_id=NEW.node_id AND the_geom IS NOT NULL LIMIT 1); -- if trace_featuregeom is false, do nothing IF v_trace_featuregeom IS TRUE THEN - UPDATE v_edit_element SET the_geom = NEW.the_geom WHERE St_dwithin(OLD.the_geom, the_geom, 0.001) + UPDATE v_edit_element SET the_geom = NEW.the_geom WHERE St_dwithin(OLD.the_geom, the_geom, 0.001) AND element_id IN (SELECT element_id FROM element_x_node WHERE node_id = NEW.node_id); END IF; - + ELSIF st_equals( NEW.the_geom, OLD.the_geom) IS FALSE AND geometrytype(NEW.the_geom)='MULTIPOLYGON' THEN UPDATE polygon SET the_geom=NEW.the_geom WHERE pol_id = OLD.pol_id; END IF; - + --link_path SELECT link_path INTO v_link_path FROM cat_feature WHERE id=NEW.node_type; IF v_link_path IS NOT NULL THEN @@ -852,48 +852,48 @@ BEGIN END IF; -- Update of topocontrol fields only when one if it has changed in order to prevent to be triggered the topocontrol without changes - IF (NEW.top_elev <> OLD.top_elev) OR (NEW.custom_top_elev <> OLD.custom_top_elev) OR (NEW.ymax <> OLD.ymax) OR + IF (NEW.top_elev <> OLD.top_elev) OR (NEW.custom_top_elev <> OLD.custom_top_elev) OR (NEW.ymax <> OLD.ymax) OR (NEW.custom_ymax <> OLD.custom_ymax) OR (NEW.elev <> OLD.elev) OR (NEW.custom_elev <> OLD.custom_elev) OR (NEW.top_elev IS NULL AND OLD.top_elev IS NOT NULL) OR (NEW.top_elev IS NOT NULL AND OLD.top_elev IS NULL) OR (NEW.custom_top_elev IS NULL AND OLD.custom_top_elev IS NOT NULL) OR (NEW.custom_top_elev IS NOT NULL AND OLD.custom_top_elev IS NULL) OR (NEW.ymax IS NULL AND OLD.ymax IS NOT NULL) OR (NEW.ymax IS NOT NULL AND OLD.ymax IS NULL) OR (NEW.custom_ymax IS NULL AND OLD.custom_ymax IS NOT NULL) OR (NEW.custom_ymax IS NOT NULL AND OLD.custom_ymax IS NULL) OR (NEW.elev IS NULL AND OLD.elev IS NOT NULL) OR (NEW.elev IS NOT NULL AND OLD.elev IS NULL) OR - (NEW.custom_elev IS NULL AND OLD.custom_elev IS NOT NULL) OR (NEW.custom_elev IS NOT NULL AND OLD.custom_elev IS NULL) THEN + (NEW.custom_elev IS NULL AND OLD.custom_elev IS NOT NULL) OR (NEW.custom_elev IS NOT NULL AND OLD.custom_elev IS NULL) THEN UPDATE node SET top_elev=NEW.top_elev, custom_top_elev=NEW.custom_top_elev, ymax=NEW.ymax, custom_ymax=NEW.custom_ymax, elev=NEW.elev, custom_elev=NEW.custom_elev WHERE node_id = OLD.node_id; END IF; - + IF v_matfromcat THEN - UPDATE node - SET code=NEW.code, node_type=NEW.node_type, nodecat_id=NEW.nodecat_id, epa_type=NEW.epa_type, sector_id=NEW.sector_id, state_type=NEW.state_type, annotation=NEW.annotation, - "observ"=NEW.observ, "comment"=NEW.comment, dma_id=NEW.dma_id, soilcat_id=NEW.soilcat_id, function_type=NEW.function_type, category_type=NEW.category_type,fluid_type=NEW.fluid_type, + UPDATE node + SET code=NEW.code, node_type=NEW.node_type, nodecat_id=NEW.nodecat_id, epa_type=NEW.epa_type, sector_id=NEW.sector_id, state_type=NEW.state_type, annotation=NEW.annotation, + "observ"=NEW.observ, "comment"=NEW.comment, dma_id=NEW.dma_id, soilcat_id=NEW.soilcat_id, function_type=NEW.function_type, category_type=NEW.category_type,fluid_type=NEW.fluid_type, location_type=NEW.location_type, workcat_id=NEW.workcat_id, workcat_id_end=NEW.workcat_id_end, workcat_id_plan=NEW.workcat_id_plan, buildercat_id=NEW.buildercat_id, builtdate=NEW.builtdate, enddate=NEW.enddate, - ownercat_id=NEW.ownercat_id, postcomplement=NEW.postcomplement, postcomplement2=NEW.postcomplement2, muni_id=NEW.muni_id, + ownercat_id=NEW.ownercat_id, postcomplement=NEW.postcomplement, postcomplement2=NEW.postcomplement2, muni_id=NEW.muni_id, streetaxis_id=v_streetaxis, postcode=NEW.postcode, district_id=NEW.district_id, - streetaxis2_id=v_streetaxis2, postnumber=NEW.postnumber, postnumber2=NEW.postnumber2, descript=NEW.descript, link=NEW.link, verified=NEW.verified, undelete=NEW.undelete, + streetaxis2_id=v_streetaxis2, postnumber=NEW.postnumber, postnumber2=NEW.postnumber2, descript=NEW.descript, link=NEW.link, verified=NEW.verified, undelete=NEW.undelete, label_x=NEW.label_x, label_y=NEW.label_y, label_rotation=NEW.label_rotation, publish=NEW.publish, inventory=NEW.inventory, rotation=NEW.rotation, uncertain=NEW.uncertain, xyz_date=NEW.xyz_date, unconnected=NEW.unconnected, expl_id=NEW.expl_id, num_value=NEW.num_value, lastupdate=now(), lastupdate_user=current_user, - asset_id=NEW.asset_id, drainzone_id=NEW.drainzone_id, parent_id=NEW.parent_id, arc_id = NEW.arc_id, expl_id2=NEW.expl_id2, adate=NEW.adate, adescript=NEW.adescript + asset_id=NEW.asset_id, drainzone_id=NEW.drainzone_id, parent_id=NEW.parent_id, arc_id = NEW.arc_id, expl_id2=NEW.expl_id2, adate=NEW.adate, adescript=NEW.adescript, placement_type=NEW.placement_type WHERE node_id = OLD.node_id; ELSE - UPDATE node - SET code=NEW.code, node_type=NEW.node_type, nodecat_id=NEW.nodecat_id, epa_type=NEW.epa_type, sector_id=NEW.sector_id, state_type=NEW.state_type, annotation=NEW.annotation, - "observ"=NEW.observ, "comment"=NEW.comment, dma_id=NEW.dma_id, soilcat_id=NEW.soilcat_id, function_type=NEW.function_type, category_type=NEW.category_type,fluid_type=NEW.fluid_type, + UPDATE node + SET code=NEW.code, node_type=NEW.node_type, nodecat_id=NEW.nodecat_id, epa_type=NEW.epa_type, sector_id=NEW.sector_id, state_type=NEW.state_type, annotation=NEW.annotation, + "observ"=NEW.observ, "comment"=NEW.comment, dma_id=NEW.dma_id, soilcat_id=NEW.soilcat_id, function_type=NEW.function_type, category_type=NEW.category_type,fluid_type=NEW.fluid_type, location_type=NEW.location_type, workcat_id=NEW.workcat_id, workcat_id_end=NEW.workcat_id_end, workcat_id_plan=NEW.workcat_id_plan, buildercat_id=NEW.buildercat_id, builtdate=NEW.builtdate, enddate=NEW.enddate, - ownercat_id=NEW.ownercat_id, postcomplement=NEW.postcomplement, postcomplement2=NEW.postcomplement2, muni_id=NEW.muni_id, + ownercat_id=NEW.ownercat_id, postcomplement=NEW.postcomplement, postcomplement2=NEW.postcomplement2, muni_id=NEW.muni_id, streetaxis_id=v_streetaxis, postcode=NEW.postcode, district_id=NEW.district_id, - streetaxis2_id=v_streetaxis2, postnumber=NEW.postnumber, postnumber2=NEW.postnumber2, descript=NEW.descript, link=NEW.link, verified=NEW.verified, undelete=NEW.undelete, + streetaxis2_id=v_streetaxis2, postnumber=NEW.postnumber, postnumber2=NEW.postnumber2, descript=NEW.descript, link=NEW.link, verified=NEW.verified, undelete=NEW.undelete, label_x=NEW.label_x, label_y=NEW.label_y, label_rotation=NEW.label_rotation, publish=NEW.publish, inventory=NEW.inventory, rotation=NEW.rotation, uncertain=NEW.uncertain, xyz_date=NEW.xyz_date, unconnected=NEW.unconnected, expl_id=NEW.expl_id, num_value=NEW.num_value, lastupdate=now(), lastupdate_user=current_user, matcat_id = NEW.matcat_id, - asset_id=NEW.asset_id, drainzone_id=NEW.drainzone_id, parent_id=NEW.parent_id, arc_id = NEW.arc_id, expl_id2=NEW.expl_id2, adate=NEW.adate, adescript=NEW.adescript - WHERE node_id = OLD.node_id; + asset_id=NEW.asset_id, drainzone_id=NEW.drainzone_id, parent_id=NEW.parent_id, arc_id = NEW.arc_id, expl_id2=NEW.expl_id2, adate=NEW.adate, adescript=NEW.adescript, placement_type=NEW.placement_type + WHERE node_id = OLD.node_id; END IF; - - IF v_man_table ='man_junction' THEN + + IF v_man_table ='man_junction' THEN UPDATE man_junction SET node_id=NEW.node_id WHERE node_id=OLD.node_id; - + ELSIF v_man_table='man_netgully' THEN -- update geom polygon @@ -904,44 +904,44 @@ BEGIN UPDATE man_netgully SET sander_depth=NEW.sander_depth, gratecat_id=NEW.gratecat_id, units=NEW.units, groove=NEW.groove, siphon=NEW.siphon, gratecat2_id=NEW.gratecat2_id, groove_length=NEW.groove_length, groove_height=NEW.groove_height, units_placement=NEW.units_placement WHERE node_id=OLD.node_id; - + ELSIF v_man_table='man_outfall' THEN UPDATE man_outfall SET name=NEW.name WHERE node_id=OLD.node_id; - + ELSIF v_man_table='man_storage' THEN - UPDATE man_storage SET length=NEW.length, width=NEW.width, custom_area=NEW.custom_area, - max_volume=NEW.max_volume, util_volume=NEW.util_volume,min_height=NEW.min_height, + UPDATE man_storage SET length=NEW.length, width=NEW.width, custom_area=NEW.custom_area, + max_volume=NEW.max_volume, util_volume=NEW.util_volume,min_height=NEW.min_height, accessibility=NEW.accessibility, name=NEW.name WHERE node_id=OLD.node_id; - + ELSIF v_man_table='man_valve' THEN UPDATE man_valve SET name=NEW.name WHERE node_id=OLD.node_id; - + ELSIF v_man_table='man_chamber' THEN UPDATE man_chamber SET length=NEW.length, width=NEW.width, sander_depth=NEW.sander_depth, max_volume=NEW.max_volume, util_volume=NEW.util_volume, inlet=NEW.inlet, bottom_channel=NEW.bottom_channel, accessibility=NEW.accessibility, name=NEW.name, bottom_mat=NEW.bottom_mat, slope=NEW.slope WHERE node_id=OLD.node_id; - + ELSIF v_man_table='man_manhole' THEN - UPDATE man_manhole SET length=NEW.length, width=NEW.width, sander_depth=NEW.sander_depth, prot_surface=NEW.prot_surface, + UPDATE man_manhole SET length=NEW.length, width=NEW.width, sander_depth=NEW.sander_depth, prot_surface=NEW.prot_surface, inlet=NEW.inlet, bottom_channel=NEW.bottom_channel, accessibility=NEW.accessibility, step_pp=NEW.step_pp, step_fe=NEW.step_fe, step_replace=NEW.step_replace, cover=NEW.cover, bottom_mat=NEW.bottom_mat WHERE node_id=OLD.node_id; - + ELSIF v_man_table='man_netinit' THEN UPDATE man_netinit SET length=NEW.length, width=NEW.width, inlet=NEW.inlet, bottom_channel=NEW.bottom_channel, accessibility=NEW.accessibility, name=NEW.name WHERE node_id=OLD.node_id; - + ELSIF v_man_table='man_wjump' THEN UPDATE man_wjump SET length=NEW.length, width=NEW.width, sander_depth=NEW.sander_depth, prot_surface=NEW.prot_surface, accessibility=NEW.accessibility, name=NEW.name WHERE node_id=OLD.node_id; - + ELSIF v_man_table='man_wwtp' THEN UPDATE man_wwtp SET name=NEW.name WHERE node_id=OLD.node_id; - + ELSIF v_man_table ='man_netelement' THEN UPDATE man_netelement SET serial_number=NEW.serial_number WHERE node_id=OLD.node_id; @@ -979,10 +979,10 @@ BEGIN END IF; -- man2inp_values - PERFORM gw_fct_man2inp_values(v_input); + PERFORM gw_fct_man2inp_values(v_input); RETURN NEW; - + ELSIF TG_OP = 'DELETE' THEN EXECUTE 'SELECT gw_fct_getcheckdelete($${"client":{"device":4, "infoType":1, "lang":"ES"}, @@ -994,7 +994,7 @@ BEGIN -- force plan_psector_force_delete SELECT value INTO v_force_delete FROM config_param_user WHERE parameter = 'plan_psector_force_delete' and cur_user = current_user; UPDATE config_param_user SET value = 'true' WHERE parameter = 'plan_psector_force_delete' and cur_user = current_user; - + -- delete from note table DELETE FROM node WHERE node_id = OLD.node_id; @@ -1007,8 +1007,8 @@ BEGIN LOOP EXECUTE 'DELETE FROM man_node_'||lower(v_addfields.cat_feature_id)||' WHERE node_id = OLD.node_id'; END LOOP; - - RETURN NULL; + + RETURN NULL; END IF; END; $BODY$ diff --git a/updates/36/36012/changelog.txt b/updates/36/36012/changelog.txt index 7ea78e1af7..4b80131eea 100644 --- a/updates/36/36012/changelog.txt +++ b/updates/36/36012/changelog.txt @@ -3,4 +3,6 @@ - New function gw_fct_setpsectorcostremovedpipes (associated fid 523) - Separate `archived_*` tables into 3 tables (archived_rpt_inp_*, archived_rpt_*, archived_rpt_*_stats) - Remove duplicated vertex generated because of the fusion. Use st_removerepeatedpoints function for the new geom -- New view v_ext_municipality filtered by selected exploitations. Use it on search tool \ No newline at end of file +- New view v_ext_municipality filtered by selected exploitations. Use it on search tool +- Add new fields on inventory tables for UD: + - node, arc, connec, gully: placement_type \ No newline at end of file diff --git a/updates/36/36012/ud/ddl.sql b/updates/36/36012/ud/ddl.sql new file mode 100644 index 0000000000..089ae79779 --- /dev/null +++ b/updates/36/36012/ud/ddl.sql @@ -0,0 +1,20 @@ +/* +This file is part of Giswater 3 +The program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version. +This version of Giswater is provided by Giswater Association +*/ + + +SET search_path = SCHEMA_NAME, public, pg_catalog; + +-- 07/08/2024 +SELECT gw_fct_admin_manage_fields($${"data":{"action":"ADD","table":"arc", "column":"placement_type", "dataType":"varchar(50)"}}$$); +SELECT gw_fct_admin_manage_fields($${"data":{"action":"ADD","table":"node", "column":"placement_type", "dataType":"varchar(50)"}}$$); +SELECT gw_fct_admin_manage_fields($${"data":{"action":"ADD","table":"connec", "column":"placement_type", "dataType":"varchar(50)"}}$$); +SELECT gw_fct_admin_manage_fields($${"data":{"action":"ADD","table":"gully", "column":"placement_type", "dataType":"varchar(50)"}}$$); + +SELECT gw_fct_admin_manage_fields($${"data":{"action":"ADD", "table":"audit_psector_arc_traceability", "column":"placement_type", "dataType":"varchar(50)"}}$$); +SELECT gw_fct_admin_manage_fields($${"data":{"action":"ADD", "table":"audit_psector_node_traceability", "column":"placement_type", "dataType":"varchar(50)"}}$$); +SELECT gw_fct_admin_manage_fields($${"data":{"action":"ADD", "table":"audit_psector_connec_traceability", "column":"placement_type", "dataType":"varchar(50)"}}$$); +SELECT gw_fct_admin_manage_fields($${"data":{"action":"ADD", "table":"audit_psector_gully_traceability", "column":"placement_type", "dataType":"varchar(50)"}}$$); + diff --git a/updates/36/36012/ud/ddlview.sql b/updates/36/36012/ud/ddlview.sql index deab123a2a..0ee8a79f43 100644 --- a/updates/36/36012/ud/ddlview.sql +++ b/updates/36/36012/ud/ddlview.sql @@ -30,7 +30,7 @@ AS SELECT DISTINCT ON (rpt_cat_result.result_id) rpt_cat_result.result_id, WHERE t1.typevalue::text = 'inp_result_status'::text AND t2.typevalue::text = 'inp_options_networkmode'::text AND ((s.expl_id = ANY (rpt_cat_result.expl_id)) AND s.cur_user = CURRENT_USER OR rpt_cat_result.expl_id = ARRAY[NULL]::INTEGER[]); - +-- 07/08/2024 -- drop depedency views from gully ----------------------------------- DROP VIEW IF EXISTS vi_gully2node; @@ -160,7 +160,8 @@ AS SELECT gully.gully_id, gully.adate, gully.adescript, gully.siphon_type, - gully.odorflap + gully.odorflap, + gully.placement_type FROM gully LEFT JOIN cat_grate ON gully.gratecat_id::text = cat_grate.id::text LEFT JOIN dma ON gully.dma_id = dma.dma_id @@ -287,7 +288,8 @@ AS WITH s AS ( vu_gully.adate, vu_gully.adescript, vu_gully.siphon_type, - vu_gully.odorflap + vu_gully.odorflap, + vu_gully.placement_type FROM s, vu_gully JOIN v_state_gully USING (gully_id) @@ -2004,247 +2006,1051 @@ AS SELECT a.gully_id, JOIN node n USING (node_id); +-- recreate other views -/* -v_edit_inp_outfall -v_edit_inp_storage -v_edit_inp_netgully -ve_pol_chamber -ve_pol_netgully -v_edit_inp_divider -v_edit_man_netelement -*/ - -CREATE OR REPLACE VIEW v_edit_inp_outfall -AS SELECT v_edit_node.node_id, - v_edit_node.top_elev, - v_edit_node.custom_top_elev, - v_edit_node.ymax, - v_edit_node.custom_ymax, - v_edit_node.elev, - v_edit_node.custom_elev, - v_edit_node.sys_elev, - v_edit_node.nodecat_id, - v_edit_node.sector_id, - v_edit_node.macrosector_id, - v_edit_node.state, - v_edit_node.state_type, - v_edit_node.annotation, - v_edit_node.expl_id, - inp_outfall.outfall_type, - inp_outfall.stage, - inp_outfall.curve_id, - inp_outfall.timser_id, - inp_outfall.gate, - v_edit_node.the_geom - FROM v_sector_node - JOIN v_edit_node USING (node_id) - JOIN inp_outfall USING (node_id) - WHERE v_edit_node.is_operative IS TRUE; - -CREATE OR REPLACE VIEW v_edit_inp_storage -AS SELECT v_edit_node.node_id, - v_edit_node.top_elev, - v_edit_node.custom_top_elev, - v_edit_node.ymax, - v_edit_node.custom_ymax, - v_edit_node.elev, - v_edit_node.custom_elev, - v_edit_node.sys_elev, - v_edit_node.nodecat_id, - v_edit_node.sector_id, - v_edit_node.macrosector_id, - v_edit_node.state, - v_edit_node.state_type, - v_edit_node.annotation, - v_edit_node.expl_id, - inp_storage.storage_type, - inp_storage.curve_id, - inp_storage.a1, - inp_storage.a2, - inp_storage.a0, - inp_storage.fevap, - inp_storage.sh, - inp_storage.hc, - inp_storage.imd, - inp_storage.y0, - inp_storage.ysur, - inp_storage.apond, - v_edit_node.the_geom - FROM v_sector_node - JOIN v_edit_node USING (node_id) - JOIN inp_storage USING (node_id) - WHERE v_edit_node.is_operative IS TRUE; - -CREATE OR REPLACE VIEW v_edit_inp_outfall -AS SELECT v_edit_node.node_id, - v_edit_node.top_elev, - v_edit_node.custom_top_elev, - v_edit_node.ymax, - v_edit_node.custom_ymax, - v_edit_node.elev, - v_edit_node.custom_elev, - v_edit_node.sys_elev, - v_edit_node.nodecat_id, - v_edit_node.sector_id, - v_edit_node.macrosector_id, - v_edit_node.state, - v_edit_node.state_type, - v_edit_node.annotation, - v_edit_node.expl_id, - inp_outfall.outfall_type, - inp_outfall.stage, - inp_outfall.curve_id, - inp_outfall.timser_id, - inp_outfall.gate, - v_edit_node.the_geom - FROM v_sector_node - JOIN v_edit_node USING (node_id) - JOIN inp_outfall USING (node_id) - WHERE v_edit_node.is_operative IS TRUE; - -CREATE OR REPLACE VIEW v_edit_inp_storage -AS SELECT v_edit_node.node_id, - v_edit_node.top_elev, - v_edit_node.custom_top_elev, - v_edit_node.ymax, - v_edit_node.custom_ymax, - v_edit_node.elev, - v_edit_node.custom_elev, - v_edit_node.sys_elev, - v_edit_node.nodecat_id, - v_edit_node.sector_id, - v_edit_node.macrosector_id, - v_edit_node.state, - v_edit_node.state_type, - v_edit_node.annotation, - v_edit_node.expl_id, - inp_storage.storage_type, - inp_storage.curve_id, - inp_storage.a1, - inp_storage.a2, - inp_storage.a0, - inp_storage.fevap, - inp_storage.sh, - inp_storage.hc, - inp_storage.imd, - inp_storage.y0, - inp_storage.ysur, - inp_storage.apond, - v_edit_node.the_geom - FROM v_sector_node - JOIN v_edit_node USING (node_id) - JOIN inp_storage USING (node_id) - WHERE v_edit_node.is_operative IS TRUE; +CREATE OR REPLACE VIEW vu_node +AS WITH vu_node AS ( + SELECT node.node_id, + node.code, + node.top_elev, + node.custom_top_elev, + CASE + WHEN node.custom_top_elev IS NOT NULL THEN node.custom_top_elev + ELSE node.top_elev + END AS sys_top_elev, + node.ymax, + node.custom_ymax, + CASE + WHEN node.custom_ymax IS NOT NULL THEN node.custom_ymax + ELSE node.ymax + END AS sys_ymax, + node.elev, + node.custom_elev, + CASE + WHEN node.elev IS NOT NULL AND node.custom_elev IS NULL THEN node.elev + WHEN node.custom_elev IS NOT NULL THEN node.custom_elev + ELSE NULL::numeric(12,3) + END AS sys_elev, + node.node_type, + cat_feature.system_id AS sys_type, + node.nodecat_id, + CASE + WHEN node.matcat_id IS NULL THEN cat_node.matcat_id + ELSE node.matcat_id + END AS matcat_id, + node.epa_type, + node.expl_id, + exploitation.macroexpl_id, + node.sector_id, + sector.macrosector_id, + node.state, + node.state_type, + node.annotation, + node.observ, + node.comment, + node.dma_id, + dma.macrodma_id, + node.soilcat_id, + node.function_type, + node.category_type, + node.fluid_type, + node.location_type, + node.workcat_id, + node.workcat_id_end, + node.buildercat_id, + node.builtdate, + node.enddate, + node.ownercat_id, + node.muni_id, + node.postcode, + node.district_id, + c.descript::character varying(100) AS streetname, + node.postnumber, + node.postcomplement, + d.descript::character varying(100) AS streetname2, + node.postnumber2, + node.postcomplement2, + node.descript, + cat_node.svg, + node.rotation, + concat(cat_feature.link_path, node.link) AS link, + node.verified, + node.undelete, + cat_node.label, + node.label_x, + node.label_y, + node.label_rotation, + node.publish, + node.inventory, + node.uncertain, + node.xyz_date, + node.unconnected, + node.num_value, + date_trunc('second'::text, node.tstamp) AS tstamp, + node.insert_user, + date_trunc('second'::text, node.lastupdate) AS lastupdate, + node.lastupdate_user, + node.the_geom, + node.workcat_id_plan, + node.asset_id, + node.drainzone_id, + node.parent_id, + node.arc_id, + node.expl_id2, + vst.is_operative, + mu.region_id, + mu.province_id, + node.adate, + node.adescript, + node.placement_type + FROM node + LEFT JOIN cat_node ON node.nodecat_id::text = cat_node.id::text + LEFT JOIN cat_feature ON cat_feature.id::text = node.node_type::text + LEFT JOIN dma ON node.dma_id = dma.dma_id + LEFT JOIN sector ON node.sector_id = sector.sector_id + LEFT JOIN exploitation ON node.expl_id = exploitation.expl_id + LEFT JOIN v_ext_streetaxis c ON c.id::text = node.streetaxis_id::text + LEFT JOIN v_ext_streetaxis d ON d.id::text = node.streetaxis2_id::text + LEFT JOIN value_state_type vst ON vst.id = node.state_type + LEFT JOIN ext_municipality mu ON node.muni_id = mu.muni_id + ) + SELECT vu_node.node_id, + vu_node.code, + vu_node.top_elev, + vu_node.custom_top_elev, + vu_node.sys_top_elev, + vu_node.ymax, + vu_node.custom_ymax, + CASE + WHEN vu_node.sys_ymax IS NOT NULL THEN vu_node.sys_ymax + ELSE (vu_node.sys_top_elev - vu_node.sys_elev)::numeric(12,3) + END AS sys_ymax, + vu_node.elev, + vu_node.custom_elev, + CASE + WHEN vu_node.sys_elev IS NOT NULL THEN vu_node.sys_elev + ELSE (vu_node.sys_top_elev - vu_node.sys_ymax)::numeric(12,3) + END AS sys_elev, + vu_node.node_type, + vu_node.sys_type, + vu_node.nodecat_id, + vu_node.matcat_id, + vu_node.epa_type, + vu_node.expl_id, + vu_node.macroexpl_id, + vu_node.sector_id, + vu_node.macrosector_id, + vu_node.state, + vu_node.state_type, + vu_node.annotation, + vu_node.observ, + vu_node.comment, + vu_node.dma_id, + vu_node.macrodma_id, + vu_node.soilcat_id, + vu_node.function_type, + vu_node.category_type, + vu_node.fluid_type, + vu_node.location_type, + vu_node.workcat_id, + vu_node.workcat_id_end, + vu_node.buildercat_id, + vu_node.builtdate, + vu_node.enddate, + vu_node.ownercat_id, + vu_node.muni_id, + vu_node.postcode, + vu_node.district_id, + vu_node.streetname, + vu_node.postnumber, + vu_node.postcomplement, + vu_node.streetname2, + vu_node.postnumber2, + vu_node.postcomplement2, + vu_node.descript, + vu_node.svg, + vu_node.rotation, + vu_node.link, + vu_node.verified, + vu_node.the_geom, + vu_node.undelete, + vu_node.label, + vu_node.label_x, + vu_node.label_y, + vu_node.label_rotation, + vu_node.publish, + vu_node.inventory, + vu_node.uncertain, + vu_node.xyz_date, + vu_node.unconnected, + vu_node.num_value, + vu_node.tstamp, + vu_node.insert_user, + vu_node.lastupdate, + vu_node.lastupdate_user, + vu_node.workcat_id_plan, + vu_node.asset_id, + vu_node.drainzone_id, + vu_node.parent_id, + vu_node.arc_id, + vu_node.expl_id2, + vu_node.is_operative, + vu_node.region_id, + vu_node.province_id, + vu_node.adate, + vu_node.adescript, + vu_node.placement_type + FROM vu_node; + +CREATE OR REPLACE VIEW vu_arc +AS SELECT arc.arc_id, + arc.code, + arc.node_1, + arc.nodetype_1, + arc.y1, + arc.custom_y1, + arc.elev1, + arc.custom_elev1, + CASE + WHEN arc.sys_elev1 IS NULL THEN arc.node_sys_elev_1 + ELSE arc.sys_elev1 + END AS sys_elev1, + CASE + WHEN + CASE + WHEN arc.custom_y1 IS NULL THEN arc.y1 + ELSE arc.custom_y1 + END IS NULL THEN arc.node_sys_top_elev_1 - arc.sys_elev1 + ELSE + CASE + WHEN arc.custom_y1 IS NULL THEN arc.y1 + ELSE arc.custom_y1 + END + END AS sys_y1, + arc.node_sys_top_elev_1 - + CASE + WHEN arc.sys_elev1 IS NULL THEN arc.node_sys_elev_1 + ELSE arc.sys_elev1 + END - cat_arc.geom1 AS r1, + CASE + WHEN arc.sys_elev1 IS NULL THEN arc.node_sys_elev_1 + ELSE arc.sys_elev1 + END - arc.node_sys_elev_1 AS z1, + arc.node_2, + arc.nodetype_2, + arc.y2, + arc.custom_y2, + arc.elev2, + arc.custom_elev2, + CASE + WHEN arc.sys_elev2 IS NULL THEN arc.node_sys_elev_2 + ELSE arc.sys_elev2 + END AS sys_elev2, + CASE + WHEN + CASE + WHEN arc.custom_y2 IS NULL THEN arc.y2 + ELSE arc.custom_y2 + END IS NULL THEN arc.node_sys_top_elev_2 - arc.sys_elev2 + ELSE + CASE + WHEN arc.custom_y2 IS NULL THEN arc.y2 + ELSE arc.custom_y2 + END + END AS sys_y2, + arc.node_sys_top_elev_2 - + CASE + WHEN arc.sys_elev2 IS NULL THEN arc.node_sys_elev_2 + ELSE arc.sys_elev2 + END - cat_arc.geom1 AS r2, + CASE + WHEN arc.sys_elev2 IS NULL THEN arc.node_sys_elev_2 + ELSE arc.sys_elev2 + END - arc.node_sys_elev_2 AS z2, + arc.sys_slope AS slope, + arc.arc_type, + cat_feature.system_id AS sys_type, + arc.arccat_id, + CASE + WHEN arc.matcat_id IS NULL THEN cat_arc.matcat_id + ELSE arc.matcat_id + END AS matcat_id, + cat_arc.shape AS cat_shape, + cat_arc.geom1 AS cat_geom1, + cat_arc.geom2 AS cat_geom2, + cat_arc.width, + arc.epa_type, + arc.expl_id, + e.macroexpl_id, + arc.sector_id, + s.macrosector_id, + arc.state, + arc.state_type, + arc.annotation, + st_length(arc.the_geom)::numeric(12,2) AS gis_length, + arc.custom_length, + arc.inverted_slope, + arc.observ, + arc.comment, + arc.dma_id, + m.macrodma_id, + arc.soilcat_id, + arc.function_type, + arc.category_type, + arc.fluid_type, + arc.location_type, + arc.workcat_id, + arc.workcat_id_end, + arc.builtdate, + arc.enddate, + arc.buildercat_id, + arc.ownercat_id, + arc.muni_id, + arc.postcode, + arc.district_id, + c.descript::character varying(100) AS streetname, + arc.postnumber, + arc.postcomplement, + d.descript::character varying(100) AS streetname2, + arc.postnumber2, + arc.postcomplement2, + arc.descript, + concat(cat_feature.link_path, arc.link) AS link, + arc.verified, + arc.undelete, + cat_arc.label, + arc.label_x, + arc.label_y, + arc.label_rotation, + arc.publish, + arc.inventory, + arc.uncertain, + arc.num_value, + date_trunc('second'::text, arc.tstamp) AS tstamp, + arc.insert_user, + date_trunc('second'::text, arc.lastupdate) AS lastupdate, + arc.lastupdate_user, + arc.the_geom, + arc.workcat_id_plan, + arc.asset_id, + arc.pavcat_id, + arc.drainzone_id, + cat_arc.area AS cat_area, + arc.parent_id, + arc.expl_id2, + vst.is_operative, + mu.region_id, + mu.province_id, + arc.adate, + arc.adescript, + cat_arc.visitability, + arc.placement_type + FROM arc + JOIN cat_arc ON arc.arccat_id::text = cat_arc.id::text + JOIN cat_feature ON arc.arc_type::text = cat_feature.id::text + JOIN sector s ON s.sector_id = arc.sector_id + JOIN exploitation e USING (expl_id) + JOIN dma m USING (dma_id) + LEFT JOIN v_ext_streetaxis c ON c.id::text = arc.streetaxis_id::text + LEFT JOIN v_ext_streetaxis d ON d.id::text = arc.streetaxis2_id::text + LEFT JOIN value_state_type vst ON vst.id = arc.state_type + LEFT JOIN ext_municipality mu ON arc.muni_id = mu.muni_id; + +CREATE OR REPLACE VIEW vu_connec +AS SELECT connec.connec_id, + connec.code, + connec.customer_code, + connec.top_elev, + connec.y1, + connec.y2, + connec.connecat_id, + connec.connec_type, + cat_feature.system_id AS sys_type, + connec.private_connecat_id, + CASE + WHEN connec.matcat_id IS NULL THEN cat_connec.matcat_id + ELSE connec.matcat_id + END AS matcat_id, + connec.expl_id, + exploitation.macroexpl_id, + connec.sector_id, + sector.macrosector_id, + connec.demand, + connec.state, + connec.state_type, + CASE + WHEN ((connec.y1 + connec.y2) / 2::numeric) IS NOT NULL THEN ((connec.y1 + connec.y2) / 2::numeric)::numeric(12,3) + ELSE connec.connec_depth + END AS connec_depth, + connec.connec_length, + connec.arc_id, + connec.annotation, + connec.observ, + connec.comment, + connec.dma_id, + dma.macrodma_id, + connec.soilcat_id, + connec.function_type, + connec.category_type, + connec.fluid_type, + connec.location_type, + connec.workcat_id, + connec.workcat_id_end, + connec.buildercat_id, + connec.builtdate, + connec.enddate, + connec.ownercat_id, + connec.muni_id, + connec.postcode, + connec.district_id, + c.descript::character varying(100) AS streetname, + connec.postnumber, + connec.postcomplement, + d.descript::character varying(100) AS streetname2, + connec.postnumber2, + connec.postcomplement2, + connec.descript, + cat_connec.svg, + connec.rotation, + concat(cat_feature.link_path, connec.link) AS link, + connec.verified, + connec.undelete, + cat_connec.label, + connec.label_x, + connec.label_y, + connec.label_rotation, + connec.accessibility, + connec.diagonal, + connec.publish, + connec.inventory, + connec.uncertain, + connec.num_value, + connec.pjoint_id, + connec.pjoint_type, + date_trunc('second'::text, connec.tstamp) AS tstamp, + connec.insert_user, + date_trunc('second'::text, connec.lastupdate) AS lastupdate, + connec.lastupdate_user, + connec.the_geom, + connec.workcat_id_plan, + connec.asset_id, + connec.drainzone_id, + connec.expl_id2, + vst.is_operative, + mu.region_id, + mu.province_id, + connec.adate, + connec.adescript, + connec.plot_code, + connec.placement_type + FROM connec + JOIN cat_connec ON connec.connecat_id::text = cat_connec.id::text + LEFT JOIN ext_streetaxis ON connec.streetaxis_id::text = ext_streetaxis.id::text + LEFT JOIN dma ON connec.dma_id = dma.dma_id + LEFT JOIN exploitation ON connec.expl_id = exploitation.expl_id + LEFT JOIN sector ON connec.sector_id = sector.sector_id + LEFT JOIN cat_feature ON connec.connec_type::text = cat_feature.id::text + LEFT JOIN v_ext_streetaxis c ON c.id::text = connec.streetaxis_id::text + LEFT JOIN v_ext_streetaxis d ON d.id::text = connec.streetaxis2_id::text + LEFT JOIN value_state_type vst ON vst.id = connec.state_type + LEFT JOIN ext_municipality mu ON connec.muni_id = mu.muni_id; -CREATE OR REPLACE VIEW v_edit_inp_netgully +CREATE OR REPLACE VIEW v_edit_node AS SELECT n.node_id, n.code, n.top_elev, n.custom_top_elev, + n.sys_top_elev, n.ymax, n.custom_ymax, + n.sys_ymax, n.elev, n.custom_elev, n.sys_elev, n.node_type, + n.sys_type, n.nodecat_id, - man_netgully.gratecat_id, - (cat_grate.width / 100::numeric)::numeric(12,3) AS grate_width, - (cat_grate.length / 100::numeric)::numeric(12,3) AS grate_length, + n.matcat_id, + n.epa_type, + n.expl_id, + n.macroexpl_id, n.sector_id, n.macrosector_id, - n.expl_id, n.state, n.state_type, - n.the_geom, - man_netgully.units, - man_netgully.units_placement, - man_netgully.groove, - man_netgully.groove_height, - man_netgully.groove_length, - cat_grate.a_param, - cat_grate.b_param, - CASE - WHEN man_netgully.units_placement::text = 'LENGTH-SIDE'::text THEN (COALESCE(man_netgully.units::integer, 1)::numeric * cat_grate.width / 100::numeric)::numeric(12,3) - WHEN man_netgully.units_placement::text = 'WIDTH-SIDE'::text THEN (COALESCE(man_netgully.units::integer, 1)::numeric * cat_grate.length / 100::numeric)::numeric(12,3) - ELSE (cat_grate.width / 100::numeric)::numeric(12,3) - END AS total_width, - CASE - WHEN man_netgully.units_placement::text = 'LENGTH-SIDE'::text THEN (COALESCE(man_netgully.units::integer, 1)::numeric * cat_grate.width / 100::numeric)::numeric(12,3) - WHEN man_netgully.units_placement::text = 'WIDTH-SIDE'::text THEN (COALESCE(man_netgully.units::integer, 1)::numeric * cat_grate.length / 100::numeric)::numeric(12,3) - ELSE (cat_grate.length / 100::numeric)::numeric(12,3) - END AS total_length, - n.ymax - COALESCE(man_netgully.sander_depth, 0::numeric) AS depth, n.annotation, - i.y0, - i.ysur, - i.apond, - i.outlet_type, - i.custom_width, - i.custom_length, - i.custom_depth, - i.method, - i.weir_cd, - i.orifice_cd, - i.custom_a_param, - i.custom_b_param, - i.efficiency - FROM v_sector_node - JOIN v_edit_node n USING (node_id) - JOIN inp_netgully i USING (node_id) - LEFT JOIN man_netgully USING (node_id) - LEFT JOIN cat_grate ON man_netgully.gratecat_id::text = cat_grate.id::text - WHERE n.is_operative IS TRUE; - -CREATE OR REPLACE VIEW v_edit_man_netelement -AS SELECT v_edit_node.node_id, - v_edit_node.code, - v_edit_node.top_elev, - v_edit_node.custom_top_elev, - v_edit_node.ymax, - v_edit_node.custom_ymax, - v_edit_node.elev, - v_edit_node.custom_elev, - CASE - WHEN v_edit_node.sys_elev IS NOT NULL THEN v_edit_node.sys_elev - ELSE (v_edit_node.sys_top_elev - v_edit_node.sys_ymax)::numeric(12,3) - END AS sys_elev, - v_edit_node.node_type, - v_edit_node.nodecat_id, - v_edit_node.epa_type, - v_edit_node.sector_id, - v_edit_node.macrosector_id, - v_edit_node.state, - v_edit_node.state_type, - v_edit_node.annotation, - v_edit_node.observ, - v_edit_node.comment, - v_edit_node.dma_id, - v_edit_node.soilcat_id, - v_edit_node.function_type, - v_edit_node.category_type, - v_edit_node.fluid_type, - v_edit_node.location_type, - v_edit_node.workcat_id, - v_edit_node.workcat_id_end, - v_edit_node.buildercat_id, - v_edit_node.builtdate, - v_edit_node.enddate, - v_edit_node.ownercat_id, - v_edit_node.muni_id, - v_edit_node.postcode, - v_edit_node.district_id, - v_edit_node.streetname, - v_edit_node.postnumber, - v_edit_node.postcomplement, - v_edit_node.streetname2, - v_edit_node.postnumber2, - v_edit_node.postcomplement2, - v_edit_node.descript, - v_edit_node.rotation, - v_edit_node.svg, - v_edit_node.link, + n.observ, + n.comment, + n.dma_id, + n.macrodma_id, + n.soilcat_id, + n.function_type, + n.category_type, + n.fluid_type, + n.location_type, + n.workcat_id, + n.workcat_id_end, + n.buildercat_id, + n.builtdate, + n.enddate, + n.ownercat_id, + n.muni_id, + n.postcode, + n.district_id, + n.streetname, + n.postnumber, + n.postcomplement, + n.streetname2, + n.postnumber2, + n.postcomplement2, + n.descript, + n.svg, + n.rotation, + n.link, + n.verified, + n.the_geom, + n.undelete, + n.label, + n.label_x, + n.label_y, + n.label_rotation, + n.publish, + n.inventory, + n.uncertain, + n.xyz_date, + n.unconnected, + n.num_value, + n.tstamp, + n.insert_user, + n.lastupdate, + n.lastupdate_user, + n.workcat_id_plan, + n.asset_id, + n.drainzone_id, + n.parent_id, + n.arc_id, + n.expl_id2, + n.is_operative, + n.region_id, + n.province_id, + n.adate, + n.adescript, + n.placement_type + FROM ( SELECT selector_expl.expl_id + FROM selector_expl + WHERE selector_expl.cur_user = CURRENT_USER) s, + vu_node n + JOIN v_state_node USING (node_id) + WHERE n.expl_id = s.expl_id OR n.expl_id2 = s.expl_id; + +CREATE OR REPLACE VIEW v_edit_arc +AS SELECT a.arc_id, + a.code, + a.node_1, + a.nodetype_1, + a.y1, + a.custom_y1, + a.elev1, + a.custom_elev1, + a.sys_elev1, + a.sys_y1, + a.r1, + a.z1, + a.node_2, + a.nodetype_2, + a.y2, + a.custom_y2, + a.elev2, + a.custom_elev2, + a.sys_elev2, + a.sys_y2, + a.r2, + a.z2, + a.slope, + a.arc_type, + a.sys_type, + a.arccat_id, + a.matcat_id, + a.cat_shape, + a.cat_geom1, + a.cat_geom2, + a.width, + a.epa_type, + a.expl_id, + a.macroexpl_id, + a.sector_id, + a.macrosector_id, + a.state, + a.state_type, + a.annotation, + a.gis_length, + a.custom_length, + a.inverted_slope, + a.observ, + a.comment, + a.dma_id, + a.macrodma_id, + a.soilcat_id, + a.function_type, + a.category_type, + a.fluid_type, + a.location_type, + a.workcat_id, + a.workcat_id_end, + a.builtdate, + a.enddate, + a.buildercat_id, + a.ownercat_id, + a.muni_id, + a.postcode, + a.district_id, + a.streetname, + a.postnumber, + a.postcomplement, + a.streetname2, + a.postnumber2, + a.postcomplement2, + a.descript, + a.link, + a.verified, + a.undelete, + a.label, + a.label_x, + a.label_y, + a.label_rotation, + a.publish, + a.inventory, + a.uncertain, + a.num_value, + a.tstamp, + a.insert_user, + a.lastupdate, + a.lastupdate_user, + a.the_geom, + a.workcat_id_plan, + a.asset_id, + a.pavcat_id, + a.drainzone_id, + a.cat_area, + a.parent_id, + a.expl_id2, + a.is_operative, + a.region_id, + a.province_id, + a.adate, + a.adescript, + a.visitability, + a.placement_type + FROM ( SELECT selector_expl.expl_id + FROM selector_expl + WHERE selector_expl.cur_user = CURRENT_USER) s, + vu_arc a + JOIN v_state_arc USING (arc_id) + WHERE a.expl_id = s.expl_id OR a.expl_id2 = s.expl_id; + +CREATE OR REPLACE VIEW v_edit_connec +AS WITH s AS ( + SELECT selector_expl.expl_id + FROM selector_expl + WHERE selector_expl.cur_user = CURRENT_USER + ) + SELECT vu_connec.connec_id, + vu_connec.code, + vu_connec.customer_code, + vu_connec.top_elev, + vu_connec.y1, + vu_connec.y2, + vu_connec.connecat_id, + vu_connec.connec_type, + vu_connec.sys_type, + vu_connec.private_connecat_id, + vu_connec.matcat_id, + vu_connec.expl_id, + vu_connec.macroexpl_id, + CASE + WHEN a.sector_id IS NULL THEN vu_connec.sector_id + ELSE a.sector_id + END AS sector_id, + CASE + WHEN a.macrosector_id IS NULL THEN vu_connec.macrosector_id + ELSE a.macrosector_id + END AS macrosector_id, + vu_connec.demand, + vu_connec.state, + vu_connec.state_type, + vu_connec.connec_depth, + vu_connec.connec_length, + v_state_connec.arc_id, + vu_connec.annotation, + vu_connec.observ, + vu_connec.comment, + CASE + WHEN a.dma_id IS NULL THEN vu_connec.dma_id + ELSE a.dma_id + END AS dma_id, + CASE + WHEN a.macrodma_id IS NULL THEN vu_connec.macrodma_id + ELSE a.macrodma_id + END AS macrodma_id, + vu_connec.soilcat_id, + vu_connec.function_type, + vu_connec.category_type, + vu_connec.fluid_type, + vu_connec.location_type, + vu_connec.workcat_id, + vu_connec.workcat_id_end, + vu_connec.buildercat_id, + vu_connec.builtdate, + vu_connec.enddate, + vu_connec.ownercat_id, + vu_connec.muni_id, + vu_connec.postcode, + vu_connec.district_id, + vu_connec.streetname, + vu_connec.postnumber, + vu_connec.postcomplement, + vu_connec.streetname2, + vu_connec.postnumber2, + vu_connec.postcomplement2, + vu_connec.descript, + vu_connec.svg, + vu_connec.rotation, + vu_connec.link, + vu_connec.verified, + vu_connec.undelete, + vu_connec.label, + vu_connec.label_x, + vu_connec.label_y, + vu_connec.label_rotation, + vu_connec.accessibility, + vu_connec.diagonal, + vu_connec.publish, + vu_connec.inventory, + vu_connec.uncertain, + vu_connec.num_value, + CASE + WHEN a.exit_id IS NULL THEN vu_connec.pjoint_id + ELSE a.exit_id + END AS pjoint_id, + CASE + WHEN a.exit_type IS NULL THEN vu_connec.pjoint_type + ELSE a.exit_type + END AS pjoint_type, + vu_connec.tstamp, + vu_connec.insert_user, + vu_connec.lastupdate, + vu_connec.lastupdate_user, + vu_connec.the_geom, + vu_connec.workcat_id_plan, + vu_connec.asset_id, + vu_connec.drainzone_id, + vu_connec.expl_id2, + vu_connec.is_operative, + vu_connec.region_id, + vu_connec.province_id, + vu_connec.adate, + vu_connec.adescript, + vu_connec.plot_code, + vu_connec.placement_type + FROM s, + vu_connec + JOIN v_state_connec USING (connec_id) + LEFT JOIN ( SELECT DISTINCT ON (vu_link.feature_id) vu_link.link_id, + vu_link.feature_type, + vu_link.feature_id, + vu_link.exit_type, + vu_link.exit_id, + vu_link.state, + vu_link.expl_id, + vu_link.sector_id, + vu_link.dma_id, + vu_link.exit_topelev, + vu_link.exit_elev, + vu_link.fluid_type, + vu_link.gis_length, + vu_link.the_geom, + vu_link.sector_name, + vu_link.macrosector_id, + vu_link.macrodma_id + FROM vu_link, + s s_1 + WHERE (vu_link.expl_id = s_1.expl_id OR vu_link.expl_id2 = s_1.expl_id) AND vu_link.state = 2) a ON a.feature_id::text = vu_connec.connec_id::text + WHERE vu_connec.expl_id = s.expl_id OR vu_connec.expl_id2 = s.expl_id; + +CREATE OR REPLACE VIEW v_edit_link +AS SELECT DISTINCT ON (vu_link.link_id) vu_link.link_id, + vu_link.feature_type, + vu_link.feature_id, + vu_link.exit_type, + vu_link.exit_id, + vu_link.state, + vu_link.expl_id, + vu_link.sector_id, + vu_link.dma_id, + vu_link.exit_topelev, + vu_link.exit_elev, + vu_link.fluid_type, + vu_link.gis_length, + vu_link.the_geom, + vu_link.sector_name, + vu_link.macrosector_id, + vu_link.macrodma_id, + vu_link.expl_id2, + vu_link.epa_type, + vu_link.is_operative, + vu_link.drainzone_id, + vu_link.drainzone_name, + vu_link.connecat_id, + vu_link.workcat_id, + vu_link.workcat_id_end, + vu_link.builtdate, + vu_link.enddate, + vu_link.lastupdate, + vu_link.lastupdate_user + FROM vu_link + JOIN v_state_link USING (link_id); + + +/* +v_edit_inp_outfall +v_edit_inp_storage +v_edit_inp_netgully +ve_pol_chamber +ve_pol_netgully +v_edit_inp_divider +v_edit_man_netelement +*/ + +CREATE OR REPLACE VIEW v_edit_inp_outfall +AS SELECT v_edit_node.node_id, + v_edit_node.top_elev, + v_edit_node.custom_top_elev, + v_edit_node.ymax, + v_edit_node.custom_ymax, + v_edit_node.elev, + v_edit_node.custom_elev, + v_edit_node.sys_elev, + v_edit_node.nodecat_id, + v_edit_node.sector_id, + v_edit_node.macrosector_id, + v_edit_node.state, + v_edit_node.state_type, + v_edit_node.annotation, + v_edit_node.expl_id, + inp_outfall.outfall_type, + inp_outfall.stage, + inp_outfall.curve_id, + inp_outfall.timser_id, + inp_outfall.gate, + v_edit_node.the_geom + FROM v_sector_node + JOIN v_edit_node USING (node_id) + JOIN inp_outfall USING (node_id) + WHERE v_edit_node.is_operative IS TRUE; + +CREATE OR REPLACE VIEW v_edit_inp_storage +AS SELECT v_edit_node.node_id, + v_edit_node.top_elev, + v_edit_node.custom_top_elev, + v_edit_node.ymax, + v_edit_node.custom_ymax, + v_edit_node.elev, + v_edit_node.custom_elev, + v_edit_node.sys_elev, + v_edit_node.nodecat_id, + v_edit_node.sector_id, + v_edit_node.macrosector_id, + v_edit_node.state, + v_edit_node.state_type, + v_edit_node.annotation, + v_edit_node.expl_id, + inp_storage.storage_type, + inp_storage.curve_id, + inp_storage.a1, + inp_storage.a2, + inp_storage.a0, + inp_storage.fevap, + inp_storage.sh, + inp_storage.hc, + inp_storage.imd, + inp_storage.y0, + inp_storage.ysur, + inp_storage.apond, + v_edit_node.the_geom + FROM v_sector_node + JOIN v_edit_node USING (node_id) + JOIN inp_storage USING (node_id) + WHERE v_edit_node.is_operative IS TRUE; + +CREATE OR REPLACE VIEW v_edit_inp_outfall +AS SELECT v_edit_node.node_id, + v_edit_node.top_elev, + v_edit_node.custom_top_elev, + v_edit_node.ymax, + v_edit_node.custom_ymax, + v_edit_node.elev, + v_edit_node.custom_elev, + v_edit_node.sys_elev, + v_edit_node.nodecat_id, + v_edit_node.sector_id, + v_edit_node.macrosector_id, + v_edit_node.state, + v_edit_node.state_type, + v_edit_node.annotation, + v_edit_node.expl_id, + inp_outfall.outfall_type, + inp_outfall.stage, + inp_outfall.curve_id, + inp_outfall.timser_id, + inp_outfall.gate, + v_edit_node.the_geom + FROM v_sector_node + JOIN v_edit_node USING (node_id) + JOIN inp_outfall USING (node_id) + WHERE v_edit_node.is_operative IS TRUE; + +CREATE OR REPLACE VIEW v_edit_inp_storage +AS SELECT v_edit_node.node_id, + v_edit_node.top_elev, + v_edit_node.custom_top_elev, + v_edit_node.ymax, + v_edit_node.custom_ymax, + v_edit_node.elev, + v_edit_node.custom_elev, + v_edit_node.sys_elev, + v_edit_node.nodecat_id, + v_edit_node.sector_id, + v_edit_node.macrosector_id, + v_edit_node.state, + v_edit_node.state_type, + v_edit_node.annotation, + v_edit_node.expl_id, + inp_storage.storage_type, + inp_storage.curve_id, + inp_storage.a1, + inp_storage.a2, + inp_storage.a0, + inp_storage.fevap, + inp_storage.sh, + inp_storage.hc, + inp_storage.imd, + inp_storage.y0, + inp_storage.ysur, + inp_storage.apond, + v_edit_node.the_geom + FROM v_sector_node + JOIN v_edit_node USING (node_id) + JOIN inp_storage USING (node_id) + WHERE v_edit_node.is_operative IS TRUE; + +CREATE OR REPLACE VIEW v_edit_inp_netgully +AS SELECT n.node_id, + n.code, + n.top_elev, + n.custom_top_elev, + n.ymax, + n.custom_ymax, + n.elev, + n.custom_elev, + n.sys_elev, + n.node_type, + n.nodecat_id, + man_netgully.gratecat_id, + (cat_grate.width / 100::numeric)::numeric(12,3) AS grate_width, + (cat_grate.length / 100::numeric)::numeric(12,3) AS grate_length, + n.sector_id, + n.macrosector_id, + n.expl_id, + n.state, + n.state_type, + n.the_geom, + man_netgully.units, + man_netgully.units_placement, + man_netgully.groove, + man_netgully.groove_height, + man_netgully.groove_length, + cat_grate.a_param, + cat_grate.b_param, + CASE + WHEN man_netgully.units_placement::text = 'LENGTH-SIDE'::text THEN (COALESCE(man_netgully.units::integer, 1)::numeric * cat_grate.width / 100::numeric)::numeric(12,3) + WHEN man_netgully.units_placement::text = 'WIDTH-SIDE'::text THEN (COALESCE(man_netgully.units::integer, 1)::numeric * cat_grate.length / 100::numeric)::numeric(12,3) + ELSE (cat_grate.width / 100::numeric)::numeric(12,3) + END AS total_width, + CASE + WHEN man_netgully.units_placement::text = 'LENGTH-SIDE'::text THEN (COALESCE(man_netgully.units::integer, 1)::numeric * cat_grate.width / 100::numeric)::numeric(12,3) + WHEN man_netgully.units_placement::text = 'WIDTH-SIDE'::text THEN (COALESCE(man_netgully.units::integer, 1)::numeric * cat_grate.length / 100::numeric)::numeric(12,3) + ELSE (cat_grate.length / 100::numeric)::numeric(12,3) + END AS total_length, + n.ymax - COALESCE(man_netgully.sander_depth, 0::numeric) AS depth, + n.annotation, + i.y0, + i.ysur, + i.apond, + i.outlet_type, + i.custom_width, + i.custom_length, + i.custom_depth, + i.method, + i.weir_cd, + i.orifice_cd, + i.custom_a_param, + i.custom_b_param, + i.efficiency + FROM v_sector_node + JOIN v_edit_node n USING (node_id) + JOIN inp_netgully i USING (node_id) + LEFT JOIN man_netgully USING (node_id) + LEFT JOIN cat_grate ON man_netgully.gratecat_id::text = cat_grate.id::text + WHERE n.is_operative IS TRUE; + +CREATE OR REPLACE VIEW v_edit_man_netelement +AS SELECT v_edit_node.node_id, + v_edit_node.code, + v_edit_node.top_elev, + v_edit_node.custom_top_elev, + v_edit_node.ymax, + v_edit_node.custom_ymax, + v_edit_node.elev, + v_edit_node.custom_elev, + CASE + WHEN v_edit_node.sys_elev IS NOT NULL THEN v_edit_node.sys_elev + ELSE (v_edit_node.sys_top_elev - v_edit_node.sys_ymax)::numeric(12,3) + END AS sys_elev, + v_edit_node.node_type, + v_edit_node.nodecat_id, + v_edit_node.epa_type, + v_edit_node.sector_id, + v_edit_node.macrosector_id, + v_edit_node.state, + v_edit_node.state_type, + v_edit_node.annotation, + v_edit_node.observ, + v_edit_node.comment, + v_edit_node.dma_id, + v_edit_node.soilcat_id, + v_edit_node.function_type, + v_edit_node.category_type, + v_edit_node.fluid_type, + v_edit_node.location_type, + v_edit_node.workcat_id, + v_edit_node.workcat_id_end, + v_edit_node.buildercat_id, + v_edit_node.builtdate, + v_edit_node.enddate, + v_edit_node.ownercat_id, + v_edit_node.muni_id, + v_edit_node.postcode, + v_edit_node.district_id, + v_edit_node.streetname, + v_edit_node.postnumber, + v_edit_node.postcomplement, + v_edit_node.streetname2, + v_edit_node.postnumber2, + v_edit_node.postcomplement2, + v_edit_node.descript, + v_edit_node.rotation, + v_edit_node.svg, + v_edit_node.link, v_edit_node.verified, v_edit_node.undelete, v_edit_node.label_x, @@ -2406,238 +3212,42 @@ AS SELECT inp_groundwater.subc_id, inp_subcatchment.snow_id, inp_subcatchment.nimp, inp_subcatchment.nperv, - inp_subcatchment.simp, - inp_subcatchment.sperv, - inp_subcatchment.zero, - inp_subcatchment.routeto, - inp_subcatchment.rted, - inp_subcatchment.maxrate, - inp_subcatchment.minrate, - inp_subcatchment.decay, - inp_subcatchment.drytime, - inp_subcatchment.maxinfil, - inp_subcatchment.suction, - inp_subcatchment.conduct, - inp_subcatchment.initdef, - inp_subcatchment.curveno, - inp_subcatchment.conduct_2, - inp_subcatchment.drytime_2, - inp_subcatchment.sector_id, - inp_subcatchment.hydrology_id, - inp_subcatchment.the_geom, - inp_subcatchment.descript - FROM inp_subcatchment - WHERE "left"(inp_subcatchment.outlet_id::text, 1) = '{'::text) a - JOIN v_edit_node ON v_edit_node.node_id::text = a.node_array) b ON v_edit_inp_subcatchment.subc_id::text = b.subc_id::text; - - -/* -v_edit_inp_conduit -v_ui_node_x_connection_downstream -v_edit_inp_orifice -v_edit_inp_outlet -v_edit_inp_pump -v_edit_inp_virtual -v_edit_inp_weir -*/ - -CREATE OR REPLACE VIEW v_edit_inp_conduit -AS SELECT v_edit_arc.arc_id, - v_edit_arc.node_1, - v_edit_arc.node_2, - v_edit_arc.y1, - v_edit_arc.custom_y1, - v_edit_arc.elev1, - v_edit_arc.custom_elev1, - v_edit_arc.sys_elev1, - v_edit_arc.y2, - v_edit_arc.custom_y2, - v_edit_arc.elev2, - v_edit_arc.custom_elev2, - v_edit_arc.sys_elev2, - v_edit_arc.arccat_id, - v_edit_arc.matcat_id, - v_edit_arc.cat_shape, - v_edit_arc.cat_geom1, - v_edit_arc.gis_length, - v_edit_arc.sector_id, - v_edit_arc.macrosector_id, - v_edit_arc.state, - v_edit_arc.state_type, - v_edit_arc.annotation, - v_edit_arc.inverted_slope, - v_edit_arc.custom_length, - v_edit_arc.expl_id, - inp_conduit.barrels, - inp_conduit.culvert, - inp_conduit.kentry, - inp_conduit.kexit, - inp_conduit.kavg, - inp_conduit.flap, - inp_conduit.q0, - inp_conduit.qmax, - inp_conduit.seepage, - inp_conduit.custom_n, - v_edit_arc.the_geom - FROM selector_sector, - v_edit_arc - JOIN inp_conduit USING (arc_id) - WHERE v_edit_arc.sector_id = selector_sector.sector_id AND selector_sector.cur_user = "current_user"()::text AND v_edit_arc.is_operative IS TRUE; - -CREATE OR REPLACE VIEW v_ui_node_x_connection_downstream -AS SELECT row_number() OVER (ORDER BY v_edit_arc.node_1) + 1000000 AS rid, - v_edit_arc.node_1 AS node_id, - v_edit_arc.arc_id AS feature_id, - v_edit_arc.code AS feature_code, - v_edit_arc.arc_type AS featurecat_id, - v_edit_arc.arccat_id, - v_edit_arc.y2 AS depth, - st_length2d(v_edit_arc.the_geom)::numeric(12,2) AS length, - node.node_id AS downstream_id, - node.code AS downstream_code, - node.node_type AS downstream_type, - v_edit_arc.y1 AS downstream_depth, - v_edit_arc.sys_type, - st_x(st_lineinterpolatepoint(v_edit_arc.the_geom, 0.5::double precision)) AS x, - st_y(st_lineinterpolatepoint(v_edit_arc.the_geom, 0.5::double precision)) AS y, - cat_arc.descript, - value_state.name AS state, - 'v_edit_arc'::text AS sys_table_id - FROM v_edit_arc - JOIN node ON v_edit_arc.node_2::text = node.node_id::text - LEFT JOIN cat_arc ON v_edit_arc.arccat_id::text = cat_arc.id::text - JOIN value_state ON v_edit_arc.state = value_state.id; - -CREATE OR REPLACE VIEW v_edit_inp_orifice -AS SELECT v_edit_arc.arc_id, - v_edit_arc.node_1, - v_edit_arc.node_2, - v_edit_arc.y1, - v_edit_arc.custom_y1, - v_edit_arc.elev1, - v_edit_arc.custom_elev1, - v_edit_arc.sys_elev1, - v_edit_arc.y2, - v_edit_arc.custom_y2, - v_edit_arc.elev2, - v_edit_arc.custom_elev2, - v_edit_arc.sys_elev2, - v_edit_arc.arccat_id, - v_edit_arc.gis_length, - v_edit_arc.sector_id, - v_edit_arc.macrosector_id, - v_edit_arc.state, - v_edit_arc.state_type, - v_edit_arc.annotation, - v_edit_arc.inverted_slope, - v_edit_arc.custom_length, - v_edit_arc.expl_id, - inp_orifice.ori_type, - inp_orifice.offsetval, - inp_orifice.cd, - inp_orifice.orate, - inp_orifice.flap, - inp_orifice.shape, - inp_orifice.geom1, - inp_orifice.geom2, - inp_orifice.geom3, - inp_orifice.geom4, - v_edit_arc.the_geom, - inp_orifice.close_time - FROM selector_sector, - v_edit_arc - JOIN inp_orifice USING (arc_id) - WHERE v_edit_arc.sector_id = selector_sector.sector_id AND selector_sector.cur_user = "current_user"()::text AND v_edit_arc.is_operative IS TRUE; - -CREATE OR REPLACE VIEW v_edit_inp_outlet -AS SELECT v_edit_arc.arc_id, - v_edit_arc.node_1, - v_edit_arc.node_2, - v_edit_arc.y1, - v_edit_arc.custom_y1, - v_edit_arc.elev1, - v_edit_arc.custom_elev1, - v_edit_arc.sys_elev1, - v_edit_arc.y2, - v_edit_arc.custom_y2, - v_edit_arc.elev2, - v_edit_arc.custom_elev2, - v_edit_arc.sys_elev2, - v_edit_arc.arccat_id, - v_edit_arc.gis_length, - v_edit_arc.sector_id, - v_edit_arc.macrosector_id, - v_edit_arc.state, - v_edit_arc.state_type, - v_edit_arc.annotation, - v_edit_arc.inverted_slope, - v_edit_arc.custom_length, - v_edit_arc.expl_id, - inp_outlet.outlet_type, - inp_outlet.offsetval, - inp_outlet.curve_id, - inp_outlet.cd1, - inp_outlet.cd2, - inp_outlet.flap, - v_edit_arc.the_geom - FROM selector_sector, - v_edit_arc - JOIN inp_outlet USING (arc_id) - WHERE v_edit_arc.sector_id = selector_sector.sector_id AND selector_sector.cur_user = "current_user"()::text AND v_edit_arc.is_operative IS TRUE; + inp_subcatchment.simp, + inp_subcatchment.sperv, + inp_subcatchment.zero, + inp_subcatchment.routeto, + inp_subcatchment.rted, + inp_subcatchment.maxrate, + inp_subcatchment.minrate, + inp_subcatchment.decay, + inp_subcatchment.drytime, + inp_subcatchment.maxinfil, + inp_subcatchment.suction, + inp_subcatchment.conduct, + inp_subcatchment.initdef, + inp_subcatchment.curveno, + inp_subcatchment.conduct_2, + inp_subcatchment.drytime_2, + inp_subcatchment.sector_id, + inp_subcatchment.hydrology_id, + inp_subcatchment.the_geom, + inp_subcatchment.descript + FROM inp_subcatchment + WHERE "left"(inp_subcatchment.outlet_id::text, 1) = '{'::text) a + JOIN v_edit_node ON v_edit_node.node_id::text = a.node_array) b ON v_edit_inp_subcatchment.subc_id::text = b.subc_id::text; -CREATE OR REPLACE VIEW v_edit_inp_pump -AS SELECT v_edit_arc.arc_id, - v_edit_arc.node_1, - v_edit_arc.node_2, - v_edit_arc.y1, - v_edit_arc.custom_y1, - v_edit_arc.elev1, - v_edit_arc.custom_elev1, - v_edit_arc.sys_elev1, - v_edit_arc.y2, - v_edit_arc.custom_y2, - v_edit_arc.elev2, - v_edit_arc.custom_elev2, - v_edit_arc.sys_elev2, - v_edit_arc.arccat_id, - v_edit_arc.gis_length, - v_edit_arc.sector_id, - v_edit_arc.macrosector_id, - v_edit_arc.state, - v_edit_arc.state_type, - v_edit_arc.annotation, - v_edit_arc.inverted_slope, - v_edit_arc.custom_length, - v_edit_arc.expl_id, - inp_pump.curve_id, - inp_pump.status, - inp_pump.startup, - inp_pump.shutoff, - v_edit_arc.the_geom - FROM selector_sector, - v_edit_arc - JOIN inp_pump USING (arc_id) - WHERE v_edit_arc.sector_id = selector_sector.sector_id AND selector_sector.cur_user = "current_user"()::text AND v_edit_arc.is_operative IS TRUE; -CREATE OR REPLACE VIEW v_edit_inp_virtual -AS SELECT v_edit_arc.arc_id, - v_edit_arc.node_1, - v_edit_arc.node_2, - v_edit_arc.gis_length, - v_edit_arc.sector_id, - v_edit_arc.macrosector_id, - v_edit_arc.state, - v_edit_arc.state_type, - v_edit_arc.expl_id, - inp_virtual.fusion_node, - inp_virtual.add_length, - v_edit_arc.the_geom - FROM selector_sector, - v_edit_arc - JOIN inp_virtual USING (arc_id) - WHERE v_edit_arc.sector_id = selector_sector.sector_id AND selector_sector.cur_user = "current_user"()::text AND v_edit_arc.is_operative IS TRUE; +/* +v_edit_inp_conduit +v_ui_node_x_connection_downstream +v_edit_inp_orifice +v_edit_inp_outlet +v_edit_inp_pump +v_edit_inp_virtual +v_edit_inp_weir +*/ - CREATE OR REPLACE VIEW v_edit_inp_weir +CREATE OR REPLACE VIEW v_edit_inp_conduit AS SELECT v_edit_arc.arc_id, v_edit_arc.node_1, v_edit_arc.node_2, @@ -2652,6 +3262,9 @@ AS SELECT v_edit_arc.arc_id, v_edit_arc.custom_elev2, v_edit_arc.sys_elev2, v_edit_arc.arccat_id, + v_edit_arc.matcat_id, + v_edit_arc.cat_shape, + v_edit_arc.cat_geom1, v_edit_arc.gis_length, v_edit_arc.sector_id, v_edit_arc.macrosector_id, @@ -2661,592 +3274,411 @@ AS SELECT v_edit_arc.arc_id, v_edit_arc.inverted_slope, v_edit_arc.custom_length, v_edit_arc.expl_id, - inp_weir.weir_type, - inp_weir.offsetval, - inp_weir.cd, - inp_weir.ec, - inp_weir.cd2, - inp_weir.flap, - inp_weir.geom1, - inp_weir.geom2, - inp_weir.geom3, - inp_weir.geom4, - inp_weir.surcharge, - v_edit_arc.the_geom, - inp_weir.road_width, - inp_weir.road_surf, - inp_weir.coef_curve + inp_conduit.barrels, + inp_conduit.culvert, + inp_conduit.kentry, + inp_conduit.kexit, + inp_conduit.kavg, + inp_conduit.flap, + inp_conduit.q0, + inp_conduit.qmax, + inp_conduit.seepage, + inp_conduit.custom_n, + v_edit_arc.the_geom FROM selector_sector, v_edit_arc - JOIN inp_weir USING (arc_id) + JOIN inp_conduit USING (arc_id) WHERE v_edit_arc.sector_id = selector_sector.sector_id AND selector_sector.cur_user = "current_user"()::text AND v_edit_arc.is_operative IS TRUE; -/* - -v_rtc_period_hydrometer - -*/ - -CREATE OR REPLACE VIEW v_rtc_period_hydrometer -AS SELECT ext_rtc_hydrometer.id AS hydrometer_id, - v_edit_connec.connec_id, - NULL::character varying(16) AS pjoint_id, - temp_arc.node_1, - temp_arc.node_2, - ext_cat_period.id AS period_id, - ext_cat_period.period_seconds, - c.dma_id, - c.effc::numeric(5,4) AS effc, - c.minc, - c.maxc, - CASE - WHEN ext_rtc_hydrometer_x_data.custom_sum IS NOT NULL THEN ext_rtc_hydrometer_x_data.custom_sum - ELSE ext_rtc_hydrometer_x_data.sum - END AS m3_total_period, - CASE - WHEN ext_rtc_hydrometer_x_data.custom_sum IS NOT NULL THEN ext_rtc_hydrometer_x_data.custom_sum * 1000::double precision / ext_cat_period.period_seconds::double precision - ELSE ext_rtc_hydrometer_x_data.sum * 1000::double precision / ext_cat_period.period_seconds::double precision - END AS lps_avg, - ext_rtc_hydrometer_x_data.pattern_id - FROM ext_rtc_hydrometer - JOIN ext_rtc_hydrometer_x_data ON ext_rtc_hydrometer_x_data.hydrometer_id::bigint = ext_rtc_hydrometer.id::bigint - JOIN ext_cat_period ON ext_rtc_hydrometer_x_data.cat_period_id::text = ext_cat_period.id::text - JOIN rtc_hydrometer_x_connec ON rtc_hydrometer_x_connec.hydrometer_id::bigint = ext_rtc_hydrometer.id::bigint - JOIN v_edit_connec ON v_edit_connec.connec_id::text = rtc_hydrometer_x_connec.connec_id::text - JOIN temp_arc ON v_edit_connec.arc_id::text = temp_arc.arc_id::text - JOIN ext_rtc_dma_period c ON c.cat_period_id::text = ext_cat_period.id::text AND c.dma_id::integer = v_edit_connec.dma_id - WHERE ext_cat_period.id::text = (( SELECT config_param_user.value - FROM config_param_user - WHERE config_param_user.cur_user::name = "current_user"() AND config_param_user.parameter::text = 'inp_options_rtc_period_id'::text)) -UNION - SELECT ext_rtc_hydrometer.id AS hydrometer_id, - v_edit_connec.connec_id, - temp_node.node_id AS pjoint_id, - NULL::character varying AS node_1, - NULL::character varying AS node_2, - ext_cat_period.id AS period_id, - ext_cat_period.period_seconds, - c.dma_id, - c.effc::numeric(5,4) AS effc, - c.minc, - c.maxc, - CASE - WHEN ext_rtc_hydrometer_x_data.custom_sum IS NOT NULL THEN ext_rtc_hydrometer_x_data.custom_sum - ELSE ext_rtc_hydrometer_x_data.sum - END AS m3_total_period, - CASE - WHEN ext_rtc_hydrometer_x_data.custom_sum IS NOT NULL THEN ext_rtc_hydrometer_x_data.custom_sum * 1000::double precision / ext_cat_period.period_seconds::double precision - ELSE ext_rtc_hydrometer_x_data.sum * 1000::double precision / ext_cat_period.period_seconds::double precision - END AS lps_avg, - ext_rtc_hydrometer_x_data.pattern_id - FROM ext_rtc_hydrometer - JOIN ext_rtc_hydrometer_x_data ON ext_rtc_hydrometer_x_data.hydrometer_id::bigint = ext_rtc_hydrometer.id::bigint - JOIN ext_cat_period ON ext_rtc_hydrometer_x_data.cat_period_id::text = ext_cat_period.id::text - JOIN rtc_hydrometer_x_connec ON rtc_hydrometer_x_connec.hydrometer_id::bigint = ext_rtc_hydrometer.id::bigint - LEFT JOIN v_edit_connec ON v_edit_connec.connec_id::text = rtc_hydrometer_x_connec.connec_id::text - JOIN temp_node ON concat('VN', v_edit_connec.pjoint_id) = temp_node.node_id::text - JOIN ext_rtc_dma_period c ON c.cat_period_id::text = ext_cat_period.id::text AND v_edit_connec.dma_id::text = c.dma_id::text - WHERE v_edit_connec.pjoint_type::text = 'VNODE'::text AND ext_cat_period.id::text = (( SELECT config_param_user.value - FROM config_param_user - WHERE config_param_user.cur_user::name = "current_user"() AND config_param_user.parameter::text = 'inp_options_rtc_period_id'::text)) -UNION - SELECT ext_rtc_hydrometer.id AS hydrometer_id, - v_edit_connec.connec_id, - temp_node.node_id AS pjoint_id, - NULL::character varying AS node_1, - NULL::character varying AS node_2, - ext_cat_period.id AS period_id, - ext_cat_period.period_seconds, - c.dma_id, - c.effc::numeric(5,4) AS effc, - c.minc, - c.maxc, - CASE - WHEN ext_rtc_hydrometer_x_data.custom_sum IS NOT NULL THEN ext_rtc_hydrometer_x_data.custom_sum - ELSE ext_rtc_hydrometer_x_data.sum - END AS m3_total_period, - CASE - WHEN ext_rtc_hydrometer_x_data.custom_sum IS NOT NULL THEN ext_rtc_hydrometer_x_data.custom_sum * 1000::double precision / ext_cat_period.period_seconds::double precision - ELSE ext_rtc_hydrometer_x_data.sum * 1000::double precision / ext_cat_period.period_seconds::double precision - END AS lps_avg, - ext_rtc_hydrometer_x_data.pattern_id - FROM ext_rtc_hydrometer - JOIN ext_rtc_hydrometer_x_data ON ext_rtc_hydrometer_x_data.hydrometer_id::bigint = ext_rtc_hydrometer.id::bigint - JOIN ext_cat_period ON ext_rtc_hydrometer_x_data.cat_period_id::text = ext_cat_period.id::text - JOIN rtc_hydrometer_x_connec ON rtc_hydrometer_x_connec.hydrometer_id::bigint = ext_rtc_hydrometer.id::bigint - LEFT JOIN v_edit_connec ON v_edit_connec.connec_id::text = rtc_hydrometer_x_connec.connec_id::text - JOIN temp_node ON v_edit_connec.pjoint_id::text = temp_node.node_id::text - JOIN ext_rtc_dma_period c ON c.cat_period_id::text = ext_cat_period.id::text AND v_edit_connec.dma_id::text = c.dma_id::text - WHERE v_edit_connec.pjoint_type::text = 'NODE'::text AND ext_cat_period.id::text = (( SELECT config_param_user.value - FROM config_param_user - WHERE config_param_user.cur_user::name = "current_user"() AND config_param_user.parameter::text = 'inp_options_rtc_period_id'::text)); - - - - - - - - -/* - -ve_pol_connec - -*/ - -CREATE OR REPLACE VIEW ve_pol_connec -AS SELECT polygon.pol_id, - polygon.feature_id, - polygon.featurecat_id, - polygon.state, - polygon.sys_type, - polygon.the_geom, - polygon.trace_featuregeom - FROM polygon - JOIN v_edit_connec ON polygon.feature_id::text = v_edit_connec.connec_id::text; - -/* v_plan_ + v_edit - -v_plan_node - -v_edit_node -v_edit_arc -v_edit_connec -v_edit_gully +CREATE OR REPLACE VIEW v_ui_node_x_connection_downstream +AS SELECT row_number() OVER (ORDER BY v_edit_arc.node_1) + 1000000 AS rid, + v_edit_arc.node_1 AS node_id, + v_edit_arc.arc_id AS feature_id, + v_edit_arc.code AS feature_code, + v_edit_arc.arc_type AS featurecat_id, + v_edit_arc.arccat_id, + v_edit_arc.y2 AS depth, + st_length2d(v_edit_arc.the_geom)::numeric(12,2) AS length, + node.node_id AS downstream_id, + node.code AS downstream_code, + node.node_type AS downstream_type, + v_edit_arc.y1 AS downstream_depth, + v_edit_arc.sys_type, + st_x(st_lineinterpolatepoint(v_edit_arc.the_geom, 0.5::double precision)) AS x, + st_y(st_lineinterpolatepoint(v_edit_arc.the_geom, 0.5::double precision)) AS y, + cat_arc.descript, + value_state.name AS state, + 'v_edit_arc'::text AS sys_table_id + FROM v_edit_arc + JOIN node ON v_edit_arc.node_2::text = node.node_id::text + LEFT JOIN cat_arc ON v_edit_arc.arccat_id::text = cat_arc.id::text + JOIN value_state ON v_edit_arc.state = value_state.id; -*/ +CREATE OR REPLACE VIEW v_edit_inp_orifice +AS SELECT v_edit_arc.arc_id, + v_edit_arc.node_1, + v_edit_arc.node_2, + v_edit_arc.y1, + v_edit_arc.custom_y1, + v_edit_arc.elev1, + v_edit_arc.custom_elev1, + v_edit_arc.sys_elev1, + v_edit_arc.y2, + v_edit_arc.custom_y2, + v_edit_arc.elev2, + v_edit_arc.custom_elev2, + v_edit_arc.sys_elev2, + v_edit_arc.arccat_id, + v_edit_arc.gis_length, + v_edit_arc.sector_id, + v_edit_arc.macrosector_id, + v_edit_arc.state, + v_edit_arc.state_type, + v_edit_arc.annotation, + v_edit_arc.inverted_slope, + v_edit_arc.custom_length, + v_edit_arc.expl_id, + inp_orifice.ori_type, + inp_orifice.offsetval, + inp_orifice.cd, + inp_orifice.orate, + inp_orifice.flap, + inp_orifice.shape, + inp_orifice.geom1, + inp_orifice.geom2, + inp_orifice.geom3, + inp_orifice.geom4, + v_edit_arc.the_geom, + inp_orifice.close_time + FROM selector_sector, + v_edit_arc + JOIN inp_orifice USING (arc_id) + WHERE v_edit_arc.sector_id = selector_sector.sector_id AND selector_sector.cur_user = "current_user"()::text AND v_edit_arc.is_operative IS TRUE; -CREATE OR REPLACE VIEW v_plan_node -AS SELECT a.node_id, - a.nodecat_id, - a.node_type, - a.top_elev, - a.elev, - a.epa_type, - a.state, - a.sector_id, - a.expl_id, - a.annotation, - a.cost_unit, - a.descript, - a.cost, - a.measurement, - a.budget, - a.the_geom - FROM ( SELECT v_edit_node.node_id, - v_edit_node.nodecat_id, - v_edit_node.sys_type AS node_type, - v_edit_node.top_elev, - v_edit_node.elev, - v_edit_node.epa_type, - v_edit_node.state, - v_edit_node.sector_id, - v_edit_node.expl_id, - v_edit_node.annotation, - v_price_x_catnode.cost_unit, - v_price_compost.descript, - v_price_compost.price AS cost, - CASE - WHEN v_price_x_catnode.cost_unit::text = 'u'::text THEN 1::numeric - WHEN v_price_x_catnode.cost_unit::text = 'm3'::text THEN - CASE - WHEN v_edit_node.sys_type::text = 'STORAGE'::text THEN man_storage.max_volume - WHEN v_edit_node.sys_type::text = 'CHAMBER'::text THEN man_chamber.max_volume - ELSE NULL::numeric - END - WHEN v_price_x_catnode.cost_unit::text = 'm'::text THEN - CASE - WHEN v_edit_node.ymax = 0::numeric THEN v_price_x_catnode.estimated_y - WHEN v_edit_node.ymax IS NULL THEN v_price_x_catnode.estimated_y - ELSE v_edit_node.ymax - END - ELSE NULL::numeric - END::numeric(12,2) AS measurement, - CASE - WHEN v_price_x_catnode.cost_unit::text = 'u'::text THEN v_price_x_catnode.cost - WHEN v_price_x_catnode.cost_unit::text = 'm3'::text THEN - CASE - WHEN v_edit_node.sys_type::text = 'STORAGE'::text THEN man_storage.max_volume * v_price_x_catnode.cost - WHEN v_edit_node.sys_type::text = 'CHAMBER'::text THEN man_chamber.max_volume * v_price_x_catnode.cost - ELSE NULL::numeric - END - WHEN v_price_x_catnode.cost_unit::text = 'm'::text THEN - CASE - WHEN v_edit_node.ymax = 0::numeric THEN v_price_x_catnode.estimated_y * v_price_x_catnode.cost - WHEN v_edit_node.ymax IS NULL THEN v_price_x_catnode.estimated_y * v_price_x_catnode.cost - ELSE v_edit_node.ymax * v_price_x_catnode.cost - END - ELSE NULL::numeric - END::numeric(12,2) AS budget, - v_edit_node.the_geom - FROM v_edit_node - LEFT JOIN v_price_x_catnode ON v_edit_node.nodecat_id::text = v_price_x_catnode.id::text - LEFT JOIN man_chamber ON man_chamber.node_id::text = v_edit_node.node_id::text - LEFT JOIN man_storage ON man_storage.node_id::text = v_edit_node.node_id::text - LEFT JOIN cat_node ON cat_node.id::text = v_edit_node.nodecat_id::text - LEFT JOIN v_price_compost ON v_price_compost.id::text = cat_node.cost::text) a; +CREATE OR REPLACE VIEW v_edit_inp_outlet +AS SELECT v_edit_arc.arc_id, + v_edit_arc.node_1, + v_edit_arc.node_2, + v_edit_arc.y1, + v_edit_arc.custom_y1, + v_edit_arc.elev1, + v_edit_arc.custom_elev1, + v_edit_arc.sys_elev1, + v_edit_arc.y2, + v_edit_arc.custom_y2, + v_edit_arc.elev2, + v_edit_arc.custom_elev2, + v_edit_arc.sys_elev2, + v_edit_arc.arccat_id, + v_edit_arc.gis_length, + v_edit_arc.sector_id, + v_edit_arc.macrosector_id, + v_edit_arc.state, + v_edit_arc.state_type, + v_edit_arc.annotation, + v_edit_arc.inverted_slope, + v_edit_arc.custom_length, + v_edit_arc.expl_id, + inp_outlet.outlet_type, + inp_outlet.offsetval, + inp_outlet.curve_id, + inp_outlet.cd1, + inp_outlet.cd2, + inp_outlet.flap, + v_edit_arc.the_geom + FROM selector_sector, + v_edit_arc + JOIN inp_outlet USING (arc_id) + WHERE v_edit_arc.sector_id = selector_sector.sector_id AND selector_sector.cur_user = "current_user"()::text AND v_edit_arc.is_operative IS TRUE; -CREATE OR REPLACE VIEW v_edit_node -AS SELECT n.node_id, - n.code, - n.top_elev, - n.custom_top_elev, - n.sys_top_elev, - n.ymax, - n.custom_ymax, - n.sys_ymax, - n.elev, - n.custom_elev, - n.sys_elev, - n.node_type, - n.sys_type, - n.nodecat_id, - n.matcat_id, - n.epa_type, - n.expl_id, - n.macroexpl_id, - n.sector_id, - n.macrosector_id, - n.state, - n.state_type, - n.annotation, - n.observ, - n.comment, - n.dma_id, - n.macrodma_id, - n.soilcat_id, - n.function_type, - n.category_type, - n.fluid_type, - n.location_type, - n.workcat_id, - n.workcat_id_end, - n.buildercat_id, - n.builtdate, - n.enddate, - n.ownercat_id, - n.muni_id, - n.postcode, - n.district_id, - n.streetname, - n.postnumber, - n.postcomplement, - n.streetname2, - n.postnumber2, - n.postcomplement2, - n.descript, - n.svg, - n.rotation, - n.link, - n.verified, - n.the_geom, - n.undelete, - n.label, - n.label_x, - n.label_y, - n.label_rotation, - n.publish, - n.inventory, - n.uncertain, - n.xyz_date, - n.unconnected, - n.num_value, - n.tstamp, - n.insert_user, - n.lastupdate, - n.lastupdate_user, - n.workcat_id_plan, - n.asset_id, - n.drainzone_id, - n.parent_id, - n.arc_id, - n.expl_id2, - n.is_operative, - n.region_id, - n.province_id, - n.adate, - n.adescript - FROM ( SELECT selector_expl.expl_id - FROM selector_expl - WHERE selector_expl.cur_user = CURRENT_USER) s, - vu_node n - JOIN v_state_node USING (node_id) - WHERE n.expl_id = s.expl_id OR n.expl_id2 = s.expl_id; +CREATE OR REPLACE VIEW v_edit_inp_pump +AS SELECT v_edit_arc.arc_id, + v_edit_arc.node_1, + v_edit_arc.node_2, + v_edit_arc.y1, + v_edit_arc.custom_y1, + v_edit_arc.elev1, + v_edit_arc.custom_elev1, + v_edit_arc.sys_elev1, + v_edit_arc.y2, + v_edit_arc.custom_y2, + v_edit_arc.elev2, + v_edit_arc.custom_elev2, + v_edit_arc.sys_elev2, + v_edit_arc.arccat_id, + v_edit_arc.gis_length, + v_edit_arc.sector_id, + v_edit_arc.macrosector_id, + v_edit_arc.state, + v_edit_arc.state_type, + v_edit_arc.annotation, + v_edit_arc.inverted_slope, + v_edit_arc.custom_length, + v_edit_arc.expl_id, + inp_pump.curve_id, + inp_pump.status, + inp_pump.startup, + inp_pump.shutoff, + v_edit_arc.the_geom + FROM selector_sector, + v_edit_arc + JOIN inp_pump USING (arc_id) + WHERE v_edit_arc.sector_id = selector_sector.sector_id AND selector_sector.cur_user = "current_user"()::text AND v_edit_arc.is_operative IS TRUE; -CREATE OR REPLACE VIEW v_edit_arc -AS SELECT a.arc_id, - a.code, - a.node_1, - a.nodetype_1, - a.y1, - a.custom_y1, - a.elev1, - a.custom_elev1, - a.sys_elev1, - a.sys_y1, - a.r1, - a.z1, - a.node_2, - a.nodetype_2, - a.y2, - a.custom_y2, - a.elev2, - a.custom_elev2, - a.sys_elev2, - a.sys_y2, - a.r2, - a.z2, - a.slope, - a.arc_type, - a.sys_type, - a.arccat_id, - a.matcat_id, - a.cat_shape, - a.cat_geom1, - a.cat_geom2, - a.width, - a.epa_type, - a.expl_id, - a.macroexpl_id, - a.sector_id, - a.macrosector_id, - a.state, - a.state_type, - a.annotation, - a.gis_length, - a.custom_length, - a.inverted_slope, - a.observ, - a.comment, - a.dma_id, - a.macrodma_id, - a.soilcat_id, - a.function_type, - a.category_type, - a.fluid_type, - a.location_type, - a.workcat_id, - a.workcat_id_end, - a.builtdate, - a.enddate, - a.buildercat_id, - a.ownercat_id, - a.muni_id, - a.postcode, - a.district_id, - a.streetname, - a.postnumber, - a.postcomplement, - a.streetname2, - a.postnumber2, - a.postcomplement2, - a.descript, - a.link, - a.verified, - a.undelete, - a.label, - a.label_x, - a.label_y, - a.label_rotation, - a.publish, - a.inventory, - a.uncertain, - a.num_value, - a.tstamp, - a.insert_user, - a.lastupdate, - a.lastupdate_user, - a.the_geom, - a.workcat_id_plan, - a.asset_id, - a.pavcat_id, - a.drainzone_id, - a.cat_area, - a.parent_id, - a.expl_id2, - a.is_operative, - a.region_id, - a.province_id, - a.adate, - a.adescript, - a.visitability - FROM ( SELECT selector_expl.expl_id - FROM selector_expl - WHERE selector_expl.cur_user = CURRENT_USER) s, - vu_arc a - JOIN v_state_arc USING (arc_id) - WHERE a.expl_id = s.expl_id OR a.expl_id2 = s.expl_id; +CREATE OR REPLACE VIEW v_edit_inp_virtual +AS SELECT v_edit_arc.arc_id, + v_edit_arc.node_1, + v_edit_arc.node_2, + v_edit_arc.gis_length, + v_edit_arc.sector_id, + v_edit_arc.macrosector_id, + v_edit_arc.state, + v_edit_arc.state_type, + v_edit_arc.expl_id, + inp_virtual.fusion_node, + inp_virtual.add_length, + v_edit_arc.the_geom + FROM selector_sector, + v_edit_arc + JOIN inp_virtual USING (arc_id) + WHERE v_edit_arc.sector_id = selector_sector.sector_id AND selector_sector.cur_user = "current_user"()::text AND v_edit_arc.is_operative IS TRUE; -CREATE OR REPLACE VIEW v_edit_connec -AS WITH s AS ( - SELECT selector_expl.expl_id - FROM selector_expl - WHERE selector_expl.cur_user = CURRENT_USER - ) - SELECT vu_connec.connec_id, - vu_connec.code, - vu_connec.customer_code, - vu_connec.top_elev, - vu_connec.y1, - vu_connec.y2, - vu_connec.connecat_id, - vu_connec.connec_type, - vu_connec.sys_type, - vu_connec.private_connecat_id, - vu_connec.matcat_id, - vu_connec.expl_id, - vu_connec.macroexpl_id, + CREATE OR REPLACE VIEW v_edit_inp_weir +AS SELECT v_edit_arc.arc_id, + v_edit_arc.node_1, + v_edit_arc.node_2, + v_edit_arc.y1, + v_edit_arc.custom_y1, + v_edit_arc.elev1, + v_edit_arc.custom_elev1, + v_edit_arc.sys_elev1, + v_edit_arc.y2, + v_edit_arc.custom_y2, + v_edit_arc.elev2, + v_edit_arc.custom_elev2, + v_edit_arc.sys_elev2, + v_edit_arc.arccat_id, + v_edit_arc.gis_length, + v_edit_arc.sector_id, + v_edit_arc.macrosector_id, + v_edit_arc.state, + v_edit_arc.state_type, + v_edit_arc.annotation, + v_edit_arc.inverted_slope, + v_edit_arc.custom_length, + v_edit_arc.expl_id, + inp_weir.weir_type, + inp_weir.offsetval, + inp_weir.cd, + inp_weir.ec, + inp_weir.cd2, + inp_weir.flap, + inp_weir.geom1, + inp_weir.geom2, + inp_weir.geom3, + inp_weir.geom4, + inp_weir.surcharge, + v_edit_arc.the_geom, + inp_weir.road_width, + inp_weir.road_surf, + inp_weir.coef_curve + FROM selector_sector, + v_edit_arc + JOIN inp_weir USING (arc_id) + WHERE v_edit_arc.sector_id = selector_sector.sector_id AND selector_sector.cur_user = "current_user"()::text AND v_edit_arc.is_operative IS TRUE; + +/* + +v_rtc_period_hydrometer + +*/ + +CREATE OR REPLACE VIEW v_rtc_period_hydrometer +AS SELECT ext_rtc_hydrometer.id AS hydrometer_id, + v_edit_connec.connec_id, + NULL::character varying(16) AS pjoint_id, + temp_arc.node_1, + temp_arc.node_2, + ext_cat_period.id AS period_id, + ext_cat_period.period_seconds, + c.dma_id, + c.effc::numeric(5,4) AS effc, + c.minc, + c.maxc, CASE - WHEN a.sector_id IS NULL THEN vu_connec.sector_id - ELSE a.sector_id - END AS sector_id, + WHEN ext_rtc_hydrometer_x_data.custom_sum IS NOT NULL THEN ext_rtc_hydrometer_x_data.custom_sum + ELSE ext_rtc_hydrometer_x_data.sum + END AS m3_total_period, CASE - WHEN a.macrosector_id IS NULL THEN vu_connec.macrosector_id - ELSE a.macrosector_id - END AS macrosector_id, - vu_connec.demand, - vu_connec.state, - vu_connec.state_type, - vu_connec.connec_depth, - vu_connec.connec_length, - v_state_connec.arc_id, - vu_connec.annotation, - vu_connec.observ, - vu_connec.comment, + WHEN ext_rtc_hydrometer_x_data.custom_sum IS NOT NULL THEN ext_rtc_hydrometer_x_data.custom_sum * 1000::double precision / ext_cat_period.period_seconds::double precision + ELSE ext_rtc_hydrometer_x_data.sum * 1000::double precision / ext_cat_period.period_seconds::double precision + END AS lps_avg, + ext_rtc_hydrometer_x_data.pattern_id + FROM ext_rtc_hydrometer + JOIN ext_rtc_hydrometer_x_data ON ext_rtc_hydrometer_x_data.hydrometer_id::bigint = ext_rtc_hydrometer.id::bigint + JOIN ext_cat_period ON ext_rtc_hydrometer_x_data.cat_period_id::text = ext_cat_period.id::text + JOIN rtc_hydrometer_x_connec ON rtc_hydrometer_x_connec.hydrometer_id::bigint = ext_rtc_hydrometer.id::bigint + JOIN v_edit_connec ON v_edit_connec.connec_id::text = rtc_hydrometer_x_connec.connec_id::text + JOIN temp_arc ON v_edit_connec.arc_id::text = temp_arc.arc_id::text + JOIN ext_rtc_dma_period c ON c.cat_period_id::text = ext_cat_period.id::text AND c.dma_id::integer = v_edit_connec.dma_id + WHERE ext_cat_period.id::text = (( SELECT config_param_user.value + FROM config_param_user + WHERE config_param_user.cur_user::name = "current_user"() AND config_param_user.parameter::text = 'inp_options_rtc_period_id'::text)) +UNION + SELECT ext_rtc_hydrometer.id AS hydrometer_id, + v_edit_connec.connec_id, + temp_node.node_id AS pjoint_id, + NULL::character varying AS node_1, + NULL::character varying AS node_2, + ext_cat_period.id AS period_id, + ext_cat_period.period_seconds, + c.dma_id, + c.effc::numeric(5,4) AS effc, + c.minc, + c.maxc, CASE - WHEN a.dma_id IS NULL THEN vu_connec.dma_id - ELSE a.dma_id - END AS dma_id, + WHEN ext_rtc_hydrometer_x_data.custom_sum IS NOT NULL THEN ext_rtc_hydrometer_x_data.custom_sum + ELSE ext_rtc_hydrometer_x_data.sum + END AS m3_total_period, CASE - WHEN a.macrodma_id IS NULL THEN vu_connec.macrodma_id - ELSE a.macrodma_id - END AS macrodma_id, - vu_connec.soilcat_id, - vu_connec.function_type, - vu_connec.category_type, - vu_connec.fluid_type, - vu_connec.location_type, - vu_connec.workcat_id, - vu_connec.workcat_id_end, - vu_connec.buildercat_id, - vu_connec.builtdate, - vu_connec.enddate, - vu_connec.ownercat_id, - vu_connec.muni_id, - vu_connec.postcode, - vu_connec.district_id, - vu_connec.streetname, - vu_connec.postnumber, - vu_connec.postcomplement, - vu_connec.streetname2, - vu_connec.postnumber2, - vu_connec.postcomplement2, - vu_connec.descript, - vu_connec.svg, - vu_connec.rotation, - vu_connec.link, - vu_connec.verified, - vu_connec.undelete, - vu_connec.label, - vu_connec.label_x, - vu_connec.label_y, - vu_connec.label_rotation, - vu_connec.accessibility, - vu_connec.diagonal, - vu_connec.publish, - vu_connec.inventory, - vu_connec.uncertain, - vu_connec.num_value, + WHEN ext_rtc_hydrometer_x_data.custom_sum IS NOT NULL THEN ext_rtc_hydrometer_x_data.custom_sum * 1000::double precision / ext_cat_period.period_seconds::double precision + ELSE ext_rtc_hydrometer_x_data.sum * 1000::double precision / ext_cat_period.period_seconds::double precision + END AS lps_avg, + ext_rtc_hydrometer_x_data.pattern_id + FROM ext_rtc_hydrometer + JOIN ext_rtc_hydrometer_x_data ON ext_rtc_hydrometer_x_data.hydrometer_id::bigint = ext_rtc_hydrometer.id::bigint + JOIN ext_cat_period ON ext_rtc_hydrometer_x_data.cat_period_id::text = ext_cat_period.id::text + JOIN rtc_hydrometer_x_connec ON rtc_hydrometer_x_connec.hydrometer_id::bigint = ext_rtc_hydrometer.id::bigint + LEFT JOIN v_edit_connec ON v_edit_connec.connec_id::text = rtc_hydrometer_x_connec.connec_id::text + JOIN temp_node ON concat('VN', v_edit_connec.pjoint_id) = temp_node.node_id::text + JOIN ext_rtc_dma_period c ON c.cat_period_id::text = ext_cat_period.id::text AND v_edit_connec.dma_id::text = c.dma_id::text + WHERE v_edit_connec.pjoint_type::text = 'VNODE'::text AND ext_cat_period.id::text = (( SELECT config_param_user.value + FROM config_param_user + WHERE config_param_user.cur_user::name = "current_user"() AND config_param_user.parameter::text = 'inp_options_rtc_period_id'::text)) +UNION + SELECT ext_rtc_hydrometer.id AS hydrometer_id, + v_edit_connec.connec_id, + temp_node.node_id AS pjoint_id, + NULL::character varying AS node_1, + NULL::character varying AS node_2, + ext_cat_period.id AS period_id, + ext_cat_period.period_seconds, + c.dma_id, + c.effc::numeric(5,4) AS effc, + c.minc, + c.maxc, CASE - WHEN a.exit_id IS NULL THEN vu_connec.pjoint_id - ELSE a.exit_id - END AS pjoint_id, + WHEN ext_rtc_hydrometer_x_data.custom_sum IS NOT NULL THEN ext_rtc_hydrometer_x_data.custom_sum + ELSE ext_rtc_hydrometer_x_data.sum + END AS m3_total_period, CASE - WHEN a.exit_type IS NULL THEN vu_connec.pjoint_type - ELSE a.exit_type - END AS pjoint_type, - vu_connec.tstamp, - vu_connec.insert_user, - vu_connec.lastupdate, - vu_connec.lastupdate_user, - vu_connec.the_geom, - vu_connec.workcat_id_plan, - vu_connec.asset_id, - vu_connec.drainzone_id, - vu_connec.expl_id2, - vu_connec.is_operative, - vu_connec.region_id, - vu_connec.province_id, - vu_connec.adate, - vu_connec.adescript, - vu_connec.plot_code - FROM s, - vu_connec - JOIN v_state_connec USING (connec_id) - LEFT JOIN ( SELECT DISTINCT ON (vu_link.feature_id) vu_link.link_id, - vu_link.feature_type, - vu_link.feature_id, - vu_link.exit_type, - vu_link.exit_id, - vu_link.state, - vu_link.expl_id, - vu_link.sector_id, - vu_link.dma_id, - vu_link.exit_topelev, - vu_link.exit_elev, - vu_link.fluid_type, - vu_link.gis_length, - vu_link.the_geom, - vu_link.sector_name, - vu_link.macrosector_id, - vu_link.macrodma_id - FROM vu_link, - s s_1 - WHERE (vu_link.expl_id = s_1.expl_id OR vu_link.expl_id2 = s_1.expl_id) AND vu_link.state = 2) a ON a.feature_id::text = vu_connec.connec_id::text - WHERE vu_connec.expl_id = s.expl_id OR vu_connec.expl_id2 = s.expl_id; - - - + WHEN ext_rtc_hydrometer_x_data.custom_sum IS NOT NULL THEN ext_rtc_hydrometer_x_data.custom_sum * 1000::double precision / ext_cat_period.period_seconds::double precision + ELSE ext_rtc_hydrometer_x_data.sum * 1000::double precision / ext_cat_period.period_seconds::double precision + END AS lps_avg, + ext_rtc_hydrometer_x_data.pattern_id + FROM ext_rtc_hydrometer + JOIN ext_rtc_hydrometer_x_data ON ext_rtc_hydrometer_x_data.hydrometer_id::bigint = ext_rtc_hydrometer.id::bigint + JOIN ext_cat_period ON ext_rtc_hydrometer_x_data.cat_period_id::text = ext_cat_period.id::text + JOIN rtc_hydrometer_x_connec ON rtc_hydrometer_x_connec.hydrometer_id::bigint = ext_rtc_hydrometer.id::bigint + LEFT JOIN v_edit_connec ON v_edit_connec.connec_id::text = rtc_hydrometer_x_connec.connec_id::text + JOIN temp_node ON v_edit_connec.pjoint_id::text = temp_node.node_id::text + JOIN ext_rtc_dma_period c ON c.cat_period_id::text = ext_cat_period.id::text AND v_edit_connec.dma_id::text = c.dma_id::text + WHERE v_edit_connec.pjoint_type::text = 'NODE'::text AND ext_cat_period.id::text = (( SELECT config_param_user.value + FROM config_param_user + WHERE config_param_user.cur_user::name = "current_user"() AND config_param_user.parameter::text = 'inp_options_rtc_period_id'::text)); +/* +ve_pol_connec +*/ +CREATE OR REPLACE VIEW ve_pol_connec +AS SELECT polygon.pol_id, + polygon.feature_id, + polygon.featurecat_id, + polygon.state, + polygon.sys_type, + polygon.the_geom, + polygon.trace_featuregeom + FROM polygon + JOIN v_edit_connec ON polygon.feature_id::text = v_edit_connec.connec_id::text; +/* +v_plan_node +*/ -CREATE OR REPLACE VIEW v_edit_link -AS SELECT DISTINCT ON (vu_link.link_id) vu_link.link_id, - vu_link.feature_type, - vu_link.feature_id, - vu_link.exit_type, - vu_link.exit_id, - vu_link.state, - vu_link.expl_id, - vu_link.sector_id, - vu_link.dma_id, - vu_link.exit_topelev, - vu_link.exit_elev, - vu_link.fluid_type, - vu_link.gis_length, - vu_link.the_geom, - vu_link.sector_name, - vu_link.macrosector_id, - vu_link.macrodma_id, - vu_link.expl_id2, - vu_link.epa_type, - vu_link.is_operative, - vu_link.drainzone_id, - vu_link.drainzone_name, - vu_link.connecat_id, - vu_link.workcat_id, - vu_link.workcat_id_end, - vu_link.builtdate, - vu_link.enddate, - vu_link.lastupdate, - vu_link.lastupdate_user - FROM vu_link - JOIN v_state_link USING (link_id); +CREATE OR REPLACE VIEW v_plan_node +AS SELECT a.node_id, + a.nodecat_id, + a.node_type, + a.top_elev, + a.elev, + a.epa_type, + a.state, + a.sector_id, + a.expl_id, + a.annotation, + a.cost_unit, + a.descript, + a.cost, + a.measurement, + a.budget, + a.the_geom + FROM ( SELECT v_edit_node.node_id, + v_edit_node.nodecat_id, + v_edit_node.sys_type AS node_type, + v_edit_node.top_elev, + v_edit_node.elev, + v_edit_node.epa_type, + v_edit_node.state, + v_edit_node.sector_id, + v_edit_node.expl_id, + v_edit_node.annotation, + v_price_x_catnode.cost_unit, + v_price_compost.descript, + v_price_compost.price AS cost, + CASE + WHEN v_price_x_catnode.cost_unit::text = 'u'::text THEN 1::numeric + WHEN v_price_x_catnode.cost_unit::text = 'm3'::text THEN + CASE + WHEN v_edit_node.sys_type::text = 'STORAGE'::text THEN man_storage.max_volume + WHEN v_edit_node.sys_type::text = 'CHAMBER'::text THEN man_chamber.max_volume + ELSE NULL::numeric + END + WHEN v_price_x_catnode.cost_unit::text = 'm'::text THEN + CASE + WHEN v_edit_node.ymax = 0::numeric THEN v_price_x_catnode.estimated_y + WHEN v_edit_node.ymax IS NULL THEN v_price_x_catnode.estimated_y + ELSE v_edit_node.ymax + END + ELSE NULL::numeric + END::numeric(12,2) AS measurement, + CASE + WHEN v_price_x_catnode.cost_unit::text = 'u'::text THEN v_price_x_catnode.cost + WHEN v_price_x_catnode.cost_unit::text = 'm3'::text THEN + CASE + WHEN v_edit_node.sys_type::text = 'STORAGE'::text THEN man_storage.max_volume * v_price_x_catnode.cost + WHEN v_edit_node.sys_type::text = 'CHAMBER'::text THEN man_chamber.max_volume * v_price_x_catnode.cost + ELSE NULL::numeric + END + WHEN v_price_x_catnode.cost_unit::text = 'm'::text THEN + CASE + WHEN v_edit_node.ymax = 0::numeric THEN v_price_x_catnode.estimated_y * v_price_x_catnode.cost + WHEN v_edit_node.ymax IS NULL THEN v_price_x_catnode.estimated_y * v_price_x_catnode.cost + ELSE v_edit_node.ymax * v_price_x_catnode.cost + END + ELSE NULL::numeric + END::numeric(12,2) AS budget, + v_edit_node.the_geom + FROM v_edit_node + LEFT JOIN v_price_x_catnode ON v_edit_node.nodecat_id::text = v_price_x_catnode.id::text + LEFT JOIN man_chamber ON man_chamber.node_id::text = v_edit_node.node_id::text + LEFT JOIN man_storage ON man_storage.node_id::text = v_edit_node.node_id::text + LEFT JOIN cat_node ON cat_node.id::text = v_edit_node.nodecat_id::text + LEFT JOIN v_price_compost ON v_price_compost.id::text = cat_node.cost::text) a; -- delete views definitibely diff --git a/updates/36/36012/ud/dml.sql b/updates/36/36012/ud/dml.sql index 4363cbf188..34fa0c9e56 100644 --- a/updates/36/36012/ud/dml.sql +++ b/updates/36/36012/ud/dml.sql @@ -87,3 +87,16 @@ UPDATE config_form_tabs UPDATE config_form_tabs SET "label"='Connections' WHERE tabname='tab_connections'; + + +-- 07/08/2024 +INSERT INTO config_form_fields(formname, formtype, tabname, columnname, layoutname, layoutorder, datatype, widgettype, +label, tooltip, placeholder, ismandatory, isparent, iseditable, isautoupdate, hidden) +WITH lyt as (SELECT distinct formname, max(layoutorder) as lytorder from config_form_fields +where layoutname ='lyt_data_2' and formname in ('v_edit_node','v_edit_arc','v_edit_connec','ve_node','ve_arc','ve_connec','v_edit_gully', 've_gully') group by formname) +SELECT c.formname, formtype, tabname, 'placement_type', 'lyt_data_2', lytorder+1, datatype, widgettype, 'Placement Type', 'Placement Type', NULL, false, false, true, false, false +FROM config_form_fields c join lyt using (formname) WHERE c.formname in ('v_edit_node','v_edit_arc','v_edit_connec','ve_node','ve_arc','ve_connec','v_edit_gully', 've_gully') +AND columnname='adate' +group by c.formname, formtype, tabname, layoutname, datatype, widgettype, label, tooltip, placeholder, ismandatory, isparent, +iseditable, isautoupdate, dv_querytext, dv_orderby_id, dv_isnullvalue, lytorder, hidden +ON CONFLICT (formname, formtype, columnname, tabname) DO NOTHING;