我需要基于线串创建一个点表。
基本上,我有一个线串表(l_table),我将生成每行的开始,结束,质心。有必要将这3列合并为一个几何点列。我希望保持原始的“ 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列结果需要与线串的原始ID相关联,并需要再添加一列来描述起始点,中心点或终点。
输入列: l.id,l.geom(线串);
输出列: l.id,p.geom(st_start,st_centroid,st_endpoint的统一结果),_ p.geometry_origin_(每种类型的分类:start,end,质心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
);
如果有人知道达成相同结果的另一种方法,请分享,但是目前,这已解决了我的疑问。
问候