Commit c396131a authored by Alice Salsé's avatar Alice Salsé
Browse files

improve lnode trigger when update pipe geom

parent 17e1e186
...@@ -75,24 +75,34 @@ begin ...@@ -75,24 +75,34 @@ begin
if _part_table_name = 'lnode' and TG_TABLE_NAME = 'pipe' then if _part_table_name = 'lnode' and TG_TABLE_NAME = 'pipe' then
EXECUTE FORMAT( EXECUTE FORMAT(
' WITH updt AS ( ' WITH updt AS (
SELECT p.id, SELECT p.id,
CASE CASE
WHEN lp.id is not null THEN p.pipe_id WHEN tp is null or (tp->>''id'')::int = p.pipe_id THEN p.pipe_id
ELSE (tp->>''id'')::int ELSE(tp->>''id'')::int
END xpipeid, END upipeid,
CASE CASE
WHEN lp.id is not null THEN ST_ClosestPoint(%3$L, lp.geom) WHEN tp is null or (tp->>''id'')::int = p.pipe_id THEN
ELSE ST_ClosestPoint(ST_SetSRID(St_GeomFromGeoJSON((tp->>''geom'')), 2154), p.geom) CASE
END xgeom WHEN ST_DWithin(ST_ClosestPoint(%3$L, coalesce(lp.geom, p.geom)), ST_StartPoint(%3$L), %5$s)
THEN st_lineinterpolatepoint(%3$L::geometry, 0.1/st_length(%3$L))
WHEN ST_DWithin(ST_ClosestPoint(%3$L, coalesce(lp.geom, p.geom)), ST_EndPoint(%3$L), %5$s)
THEN st_lineinterpolatepoint(%3$L::geometry, 1-(0.1/st_length(%3$L)))
ELSE ST_ClosestPoint(%3$L, coalesce(lp.geom, p.geom)) END
ELSE
CASE
WHEN ST_DWithin(ST_ClosestPoint(ST_SetSRID(St_GeomFromGeoJSON((tp->>''geom'')), 2154), coalesce(lp.geom, p.geom)), ST_StartPoint(ST_SetSRID(St_GeomFromGeoJSON((tp->>''geom'')), 2154)), %5$s)
THEN st_lineinterpolatepoint(ST_SetSRID(St_GeomFromGeoJSON((tp->>''geom'')), 2154), 0.1/st_length(ST_SetSRID(St_GeomFromGeoJSON((tp->>''geom'')), 2154)))
WHEN ST_DWithin(ST_ClosestPoint(ST_SetSRID(St_GeomFromGeoJSON((tp->>''geom'')), 2154), coalesce(lp.geom, p.geom)), ST_EndPoint(ST_SetSRID(St_GeomFromGeoJSON((tp->>''geom'')), 2154)), %5$s)
THEN st_lineinterpolatepoint(ST_SetSRID(St_GeomFromGeoJSON((tp->>''geom'')), 2154), 1-(0.1/st_length(ST_SetSRID(St_GeomFromGeoJSON((tp->>''geom'')), 2154))))
ELSE ST_ClosestPoint(ST_SetSRID(St_GeomFromGeoJSON((tp->>''geom'')), 2154), coalesce(lp.geom, p.geom)) END
END ugeom
FROM %1$I.%2$I p FROM %1$I.%2$I p
LEFT OUTER JOIN %1$I.lpipe lp ON lp.end_node=p.id 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) ,utils.fnc_get_closest_pipe(coalesce(lp.geom, p.geom), p.level,''%1$I.pipe'') tp
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 WHERE p.pipe_id = %4$s
) )
UPDATE %1$I.%2$I p UPDATE %1$I.%2$I p
SET pipe_id = xpipeid, geom = updt.xgeom SET pipe_id = updt.upipeid, geom = updt.ugeom
FROM updt FROM updt
WHERE p.pipe_id = %4$s WHERE p.pipe_id = %4$s
AND updt.id=p.id;' AND updt.id=p.id;'
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment