diff --git a/datamodel/app/create_app.py b/datamodel/app/create_app.py index 34fbaffc..0a93bbf0 100755 --- a/datamodel/app/create_app.py +++ b/datamodel/app/create_app.py @@ -34,6 +34,8 @@ def create_views(srid: int, pg_service: str): run_sql("datamodel/app/create_schema.sql", pg_service, variables) run_sql("datamodel/app/vw_edited_support.sql", pg_service, variables) + run_sql("datamodel/app/vw_azimut_edit.sql", pg_service, variables) + vw_sign_symbol(pg_service=pg_service, srid=srid) diff --git a/datamodel/app/vw_azimut_edit.sql b/datamodel/app/vw_azimut_edit.sql new file mode 100644 index 00000000..3841a575 --- /dev/null +++ b/datamodel/app/vw_azimut_edit.sql @@ -0,0 +1,30 @@ + + +CREATE OR REPLACE VIEW signalo_app.vw_azimut_edit +AS +SELECT + az.id, + ST_MakeLine(su.geometry, ST_SetSRID(St_MakePoint(ST_X(su.geometry) + 10 * sin(radians(az.azimut)), ST_Y(su.geometry) + 10 *cos(radians(az.azimut))), 2056))::geometry(LineString, 2056) as geometry +FROM signalo_db.azimut az +INNER JOIN signalo_db.support su ON az.fk_support = su.id; + + +CREATE FUNCTION signalo_app.ft_azimut_edit() RETURNS trigger + LANGUAGE plpgsql + AS $$ + BEGIN + IF ST_Equals(ST_StartPoint(NEW.geometry), ST_StartPoint(OLD.geometry)) THEN + RAISE WARNING 'start point should remain unchanged'; + END IF; + + UPDATE signalo_db.azimut SET azimut = degrees(ST_Azimuth(ST_StartPoint(NEW.geometry), ST_EndPoint(NEW.geometry))) WHERE id = NEW.id; + + RETURN NEW; + END; + $$; + + +CREATE TRIGGER azimut_update + INSTEAD OF UPDATE ON signalo_app.vw_azimut_edit + FOR EACH ROW + EXECUTE FUNCTION signalo_app.ft_azimut_edit(); diff --git a/project/signalo.qgs b/project/signalo.qgs index 0b0da369..408e147f 100644 --- a/project/signalo.qgs +++ b/project/signalo.qgs @@ -1,5 +1,5 @@ - + Signalo - Demo @@ -21,6 +21,11 @@ + + + +