forked from kartoza/parcel_plugin
-
Notifications
You must be signed in to change notification settings - Fork 0
/
portqgis2_db_changes.sql
41 lines (41 loc) · 1.77 KB
/
portqgis2_db_changes.sql
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
CREATE OR REPLACE FUNCTION beardistupdate(arg_plan_no character varying, arg_bearing double precision, arg_distance double precision, arg_beacon_from character varying, arg_beacon_to character varying, arg_location character varying, arg_name character varying, arg_index integer)
RETURNS void AS
$BODY$
DECLARE
the_id_beardist integer;
the_id_beacons integer;
the_x double precision;
the_y double precision;
the_geom_ geometry(Point, 26331);
BEGIN
SELECT i.id INTO the_id_beardist FROM (
SELECT bd.id, row_number() over(ORDER BY bd.id) -1 as index
FROM beardist bd
INNER JOIN beacons b ON bd.beacon_to = b.beacon
WHERE bd.plan_no = arg_plan_no
) AS i
WHERE i.index = arg_index;
SELECT gid INTO the_id_beacons FROM beacons b INNER JOIN beardist bd ON b.beacon = bd.beacon_to WHERE bd.id = the_id_beardist;
SELECT x INTO the_x FROM beacons WHERE beacon = arg_beacon_from;
SELECT y INTO the_y FROM beacons WHERE beacon = arg_beacon_from;
SELECT pointfrombearinganddistance(the_x, the_y, arg_bearing, arg_distance, 3, 26331) INTO the_geom_;
UPDATE beacons SET
beacon = arg_beacon_to,
y = st_y(the_geom_),
x = st_x(the_geom_),
"location" = arg_location,
"name" = arg_name
WHERE gid = the_id_beacons;
UPDATE beardist SET
plan_no = arg_plan_no,
bearing = arg_bearing,
distance = arg_distance,
beacon_from = arg_beacon_from,
beacon_to = arg_beacon_to
WHERE id = the_id_beardist;
END
$BODY$
LANGUAGE plpgsql VOLATILE
COST 100;
ALTER FUNCTION beardistupdate(character varying, double precision, double precision, character varying, character varying, character varying, character varying, integer)
OWNER TO robert;