使用PostgreSQL/PostGIS,给定一个点位置,我需要从数据库表中提取最近的线串,并更新建立的几何图形,根据点位置添加给定点。 为此,可以使用 PostGIS 函数
ST_AddPoint
,但是,只要该函数需要将索引位置分配给我想要添加的新点,我就需要获取最近的两个节点的最大索引线串的一部分,但对我来说接缝并不那么容易。
经过几次尝试,这是找到的解决方案:
with dot as (select st_geomfromtext('POINT (X Y)', CRS) as pp)
select
condotta,
(bar.path[1]) as idx,
st_addpoint(condotta, dot.pp, (bar.path[1])) as new_condotta
from (select
foo.geom as condotta,
(ST_DumpSegments(foo.geom)).*
from (select geom
from acquedotto.rete_idrica ri, dot
order by pp<->geom asc limit 1) as foo) as bar, dot
order by dot.pp<->bar.geom asc
limit 1