signalo
.signalo_app
Tables
(current)
Columns
Constraints
Relationships
Orphan Tables
Anomalies
Routines
ft_azimut_insert()
Parameters
Name
Type
Mode
IN
Definition
DECLARE support_id uuid := NULL; BEGIN IF ST_NumPoints(NEW.geometry) != 2 THEN RAISE EXCEPTION 'The line should have only 2 vertices'; END IF; SELECT id FROM signalo_db.support s WHERE ST_Equals(s.geometry, ST_StartPoint(NEW.geometry)) INTO support_id; IF support_id IS NULL THEN INSERT INTO signalo_db.support (geometry) VALUES (ST_StartPoint(NEW.geometry)) RETURNING id INTO support_id; IF support_id IS NULL THEN RAISE EXCEPTION 'Could not create a support'; END IF; END IF; INSERT INTO signalo_db.azimut (fk_support, azimut) VALUES (support_id, degrees(ST_Azimuth(ST_StartPoint(NEW.geometry), ST_EndPoint(NEW.geometry)))); RETURN NEW; END;