Skip to content
GitLab
Menu
Projects
Groups
Snippets
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Sign in
Toggle navigation
Menu
Open sidebar
BMG PUBLIC RESOURCES
SIG-TOPO-BMG
Commits
cf3e7baa
Commit
cf3e7baa
authored
Oct 21, 2020
by
Alice Salsé
Browse files
✨
update lnode triggers when update pipe geom
parent
ae12db14
Changes
3
Hide whitespace changes
Inline
Side-by-side
sql/network/function_get_closest_pipe.sql
0 → 100644
View file @
cf3e7baa
\
encoding
UTF8
set
search_path
to
utils
,
public
;
CREATE
OR
REPLACE
FUNCTION
fnc_get_closest_pipe
(
IN
i_geom
geometry
,
IN
i_level
int
,
IN
i_pipe_regclass
regclass
,
OUT
o_pipe
jsonb
)
RETURNS
jsonb
AS
$
BODY
$
DECLARE
_distance
float
;
BEGIN
--==== Find closest pipe ====
--> get intersected pipe
EXECUTE
FORMAT
(
'SELECT to_jsonb(p.*)
FROM %1$s p
WHERE ST_Intersects(st_buffer(%2$L, %4$s), p.geom)
AND p.level = %3$s
ORDER BY ST_Distance(%2$L, p.geom)
LIMIT 1;'
,
i_pipe_regclass
,
i_geom
,
i_level
,
100
)
INTO
o_pipe
;
RETURN
;
END
;
$
BODY
$
LANGUAGE
plpgsql
STABLE
SECURITY
DEFINER
COST
100
;
sql/network/function_get_pipe.sql
View file @
cf3e7baa
...
...
@@ -10,7 +10,7 @@ RETURNS jsonb AS $BODY$
DECLARE
_distance
float
;
BEGIN
--==== Find
start & end nodes
====
--==== Find
intersected pipe
====
-- >>> Tolerance for snapping <<<
select
config
.
get_tolerance
(
'topo'
)
into
_distance
;
--> get intersected pipe
...
...
sql/network/function_trigger_pipe_after.sql
View file @
cf3e7baa
...
...
@@ -72,11 +72,36 @@ begin
SET pipe_id = coalesce((SELECT (tp->>
''
id
''
)::int FROM utils.fnc_get_pipe(p.geom,p.level,
''
%1$I.%3$I
''
) tp), pipe_id)
WHERE p.pipe_id = %4$s;'
,
TG_TABLE_SCHEMA
,
_part_table_name
,
TG_TABLE_NAME
,
new
.
id
);
IF
ST_NPoints
(
old
.
geom
)
=
ST_NPoints
(
new
.
geom
)
THEN
if
_part_table_name
=
'lnode'
and
TG_TABLE_NAME
=
'pipe'
then
EXECUTE
FORMAT
(
' WITH updt AS (
SELECT p.id,
CASE
WHEN lp.id is not null THEN p.pipe_id
ELSE (tp->>
''
id
''
)::int
END xpipeid,
CASE
WHEN lp.id is not null THEN ST_ClosestPoint(%3$L, lp.geom)
ELSE ST_ClosestPoint(ST_SetSRID(St_GeomFromGeoJSON((tp->>
''
geom
''
)), 2154), p.geom)
END xgeom
FROM %1$I.%2$I p
LEFT OUTER JOIN %1$I.lpipe lp ON lp.end_node=p.id
AND NOT ST_DWithin(ST_ClosestPoint(%3$L, lp.geom), ST_StartPoint(%3$L), %5$s)
AND NOT ST_DWithin(ST_ClosestPoint(%3$L, lp.geom), ST_EndPoint(%3$L), %5$s)
,utils.fnc_get_closest_pipe(p.geom,p.level,
''
%1$I.pipe
''
) tp
WHERE p.pipe_id = %4$s
)
UPDATE %1$I.%2$I p
SET pipe_id = xpipeid, geom = updt.xgeom
FROM updt
WHERE p.pipe_id = %4$s
AND updt.id=p.id;'
,
TG_TABLE_SCHEMA
,
_part_table_name
,
new
.
geom
,
new
.
id
,
_distance
);
ELSIF
ST_NPoints
(
old
.
geom
)
=
ST_NPoints
(
new
.
geom
)
THEN
-- update geom with interpolate to pipe segment
EXECUTE
FORMAT
(
' WITH dump_pipe as (
SELECT d.path[1]last_vtx, ST_MakeLine(LAG(d.geom,1) OVER (ORDER by d.path[1]),d.geom) segment
SELECT d.path[1]
last_vtx, ST_MakeLine(LAG(d.geom,1) OVER (ORDER by d.path[1]),d.geom) segment
FROM ST_DumpPoints(%3$L) d
)
UPDATE %1$I.%2$I p
...
...
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment