生成几何函数的结果并将其合并到 Postgis 中的一列中

Generate and merging results of geometry function into one column in Postgis

我需要根据线串创建 table 个点。

基本上我有一个线串 table (l_table),我会生成每行的开始、结束和质心。有必要将这 3 列合并为一个几何点 column.I 希望保持原始 "ID" 列与新几何点相关联。最后,还有一列来描述新的点几何:起点、终点或质心。

像这样:

 create table point_from_line as (
     select l.id, st_startpoint(l.geom), st_centroid(l.geom), st_endpoint(l.geom)
     case st_startpoint ... then 'start'
     case st_centroid ... then 'centroid'
     case st_endpoint ... then 'end'
     end as geom_origin
     from linestring_table  
     where l.id any condition... 

注意:geom列结果需要与linestring的原始id相关联,并且多一列来描述是起点,中心还是终点。

输入列: l.id, l.geom (线串);

输出列: l.id, p.geom ( st_start, st_centroid, st_endpoint), _p.geometry_origin_的统一结果(分类在:start,end, centroid for each row of p.geom)

有人可以帮我吗?

复杂而好的问题,我会尝试合作。 (哈哈)

几个小时后,我想我找到了解决问题的方向。 所以,我会一步步解释:

1 - 创建 3 个递归 cte:起点、中心、终点 + 各自的分类

  with Recursive cte as
     start point of linestring
     select l.id, st_startpoint(l.geom),
         case when
         l.geom is not null then 'start point'
         end as geom_origin
     where l.somecolumn = 'somefilter'...

2 - 重复上述查询修改质心和端点的参数

3 - 联合所有生成的 3 个 cte id 会重复,但这是有意的。

4 - 在子查询中分配 3 个 ctes 以生成唯一的 id 值,由 "gid"

调用

因此,最终查询如下所示:

select row_number() over () as gid, cte.id, cte.geom, cte.geom_origin
from (
  with Recursive cte as ( select...),
  cte_2 (select...),
  cte_3 (select...),
)

select * from cte
union all 
select * from cte_2
union all
select * from cte_3
);

如果有人知道另一种方法可以达到相同的结果,请分享,但现在,这解决了我的疑问。

此致