Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

enable azimut editing through lines #173

Merged
merged 1 commit into from
Jan 30, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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