postgresql 如何使用 PostGIS 将多边形数据转换为线段

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/7595635/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-10-20 23:19:43  来源:igfitidea点击:

How to convert polygon data into line segments using PostGIS

sqlpostgresqlgispostgis

提问by gouse shaik

I have a polygon data table in PostgreSQL/PostGIS. Now I need to convert this Polygon data into its corresponding line segments. Can anybody tell me how to convert it using PostGIS queries.

我在 PostgreSQL/PostGIS 中有一个多边形数据表。现在我需要将此多边形数据转换为其相应的线段。谁能告诉我如何使用 PostGIS 查询转换它。

Thanks in Advance

提前致谢

回答by mloskot

Generally, converting polygon to line may be not straightforward because there is no one-to-one mappingand various elements of polygon map to different linestring (exterior ring, interior rings, etc.).

通常,将多边形转换为线可能并不简单,因为没有一对一映射,并且多边形的各种元素映射到不同的线串(外环、内环等)。

Considering that, you will need to split each of those separately following possible approach like this:

考虑到这一点,您需要按照如下可能的方法分别拆分每个部分:

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
       ) AS linestrings
    ) AS segments;

depending on what polygon data are stored in mypolygontable, you may want to dump not only the boundary (as above using ST_Boundary) but also other elements. The code above with more detailed overview is taken from the postgis-users list: Split a polygon to N linestrings

根据存储在 中的多边形数据mypolygontable,您可能不仅要转储边界(如上所述使用ST_Boundary),还要转储其他元素。上面有更详细概述的代码取自 postgis-users 列表:Split a polygon to N linestrings

There is also a generic approach to the problem explained in Exploding a linestring or polygon into individual vectors in PostGIS

在 PostGIS 中将线串或多边形分解为单个向量中解释的问题还有一个通用方法

回答by D_C

This is the first hit on google when you search this problem. I don't know if so much time has passed a function has been created since, but for future googlers ST_ExteriorRings(geom) worked great for me. http://postgis.net/docs/ST_ExteriorRing.html

这是您搜索此问题时在 google 上的第一次点击。我不知道从那以后创建的函数是否已经过去了很长时间,但对于未来的 googlers ST_ExteriorRings(geom) 对我来说非常有用。 http://postgis.net/docs/ST_ExteriorRing.html