Skip to content

Commit

Permalink
enable azimut editing through lines
Browse files Browse the repository at this point in the history
fix #108
  • Loading branch information
3nids committed Jan 30, 2024
1 parent acd8072 commit 9388185
Show file tree
Hide file tree
Showing 3 changed files with 432 additions and 8 deletions.
2 changes: 2 additions & 0 deletions datamodel/app/create_app.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)


Expand Down
30 changes: 30 additions & 0 deletions datamodel/app/vw_azimut_edit.sql
Original file line number Diff line number Diff line change
@@ -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();
Loading

0 comments on commit 9388185

Please sign in to comment.