-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathsicob_snap_line2line.sql
More file actions
48 lines (45 loc) · 1.29 KB
/
Copy pathsicob_snap_line2line.sql
File metadata and controls
48 lines (45 loc) · 1.29 KB
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
42
43
44
45
46
47
48
SET CLIENT_ENCODING TO 'utf8';
CREATE OR REPLACE FUNCTION public.sicob_snap_line2line(line_a geometry, line_b geometry, _tolerance double precision)
RETURNS geometry
LANGUAGE plpgsql
AS $function$
DECLARE
new_line geometry;
BEGIN
WITH
P2 AS (
SELECT (dp).path[1] As id,(dp).geom As the_geom
FROM (
SELECT ST_DumpPoints(line_b) as dp
) pts
),
ptsL2toL1 as (
SELECT points_to_project_onto_line.id,
ST_LineInterpolatePoint(
line_a,
ST_LineLocatePoint(
line_a,
points_to_project_onto_line.the_geom
)
) as the_geom
FROM P2 points_to_project_onto_line
),
cutlineL1 AS (
SELECT sicob_cutlineatpoints(line_a,
( SELECT st_union(the_geom) FROM ptsL2toL1 ), 0.00005
) as the_geom
),
snapL2toL1 AS (
SELECT ST_Snap(
(SELECT st_union(the_geom) FROM cutlineL1),
line_b,
_tolerance) as the_geom
)
SELECT st_union(the_geom) into new_line FROM snapL2toL1;
RETURN new_line;
EXCEPTION
WHEN others THEN
RAISE EXCEPTION 'geoSICOB (sicob_snap_line2line): % (%) | line_a: % | line_b: %', SQLERRM, SQLSTATE, st_astext(line_a), st_astext(line_b);
END;
$function$