将MULTILINESTRING分解为PostGIS 1.5中的各个段


10

MULTILINESTRING在PostGIS中有一个由几个组成LINESTRING的。考虑每个LINESTRING有一组POINT

P 1,P 2,... P N

形成线段

L 1,L 2,... L N-1

其中L X是连接P X和P X + 1的线段。

使用PostGIS 1.5,如何MULTILINESTRING将每个线段分解为单独的线段LINESTRING

Answers:


11

我想到两个选择。如果您想要一个特定的,LINESTRING则可以使用ST_NumGeometries()ST_GeometryN()。另外,如果要所有子几何,请ST_Dump()

在实际阅读了问题之后,您需要从postgis-users列表中执行与帖子类似的操作

SELECT ST_AsText( ST_MakeLine(sp,ep) )
FROM
-- extract the endpoints for every 2-point line segment for each linestring
(SELECT
  ST_PointN(geom, generate_series(1, ST_NPoints(geom)-1)) as sp,
  ST_PointN(geom, generate_series(2, ST_NPoints(geom)  )) as ep
FROM
   -- extract the individual linestrings
  (SELECT (ST_Dump(ST_Boundary(geom))).geom
   FROM mypolygontable
   -- eliminate 0 length linestring 
    where st_x(st_startpoint(geom))<> st_x(st_endpoint(geom))
   ) AS linestrings
) AS segments;

我看了你的答案如何获得LINESTRING“从A S MULTILINESTRING。但是我想更深入一点,我想要单独的线段,这些线段在合并时形成的线段,在合并LINESTRING时又形成原始的线段MULTILINESTRING。那有意义吗?

1
啊! 是的,现在我喝咖啡了,我可以看到那是你写的……
MerseyViking

1
我不明白,因为我不喝咖啡;)

不过,您的添加工作正常,非常感谢!
By using our site, you acknowledge that you have read and understand our Cookie Policy and Privacy Policy.
Licensed under cc by-sa 3.0 with attribution required.