如何使用PostGIS将多边形数据转换为线段 [英] How to convert polygon data into line segments using PostGIS

查看:778
本文介绍了如何使用PostGIS将多边形数据转换为线段的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

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.

预先感谢

推荐答案

通常,将多边形转换为直线可能并不容易,因为

Generally, converting polygon to line may be not straightforward because there is no one-to-one mapping and 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;

取决于mypolygontable中存储的多边形数据,您可能不仅希望转储边界(如上使用ST_Boundary所述),还希望转储其他元素.上面具有更详细概述的代码来自postgis-users列表:将多边形分割成N个线串

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

查看全文

登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆