【问题标题】:Convert Points to Polygon using PostGIS使用 PostGIS 将点转换为多边形
【发布时间】:2013-10-03 12:11:22
【问题描述】:

我想使用 PostGIS 创建一个多边形表。表'point'中的每一行都有三点ID. 表'point_location'有点的位置信息。我用谷歌搜索了这个问题,但没有找到答案。下面的代码有什么问题?

SELECT ST_GeomFromText('POLYGON((' || b.x || ' ' || b.y || ',' || c.x || ' ' || c.y || ',' || d.x || ' ' || d.y || ',' || b.x || ' ' || b.y'))',4326) 
AS polygon
FROM point a, point_location b, point_location c, point_location d
WHERE a.p1=b.point_id AND a.p2=c.point_id AND a.p3=d.point_id

【问题讨论】:

  • 你应该在 gis.stackexchange.com 上问这个问题

标签: postgresql gis postgis


【解决方案1】:

从点构造多边形的更好方法是使用PostGIS' geometry constructors。这样,您就避免了转换二进制 → 文本 → 二进制 (WKB → WKT → WKB) 的需要,这种转换速度较慢、有损并且容易出现文本格式干扰,正如缺少的 || 所证明的那样。例如,尝试:

SELECT ST_MakePolygon(ST_MakeLine(ARRAY[b, c, d, b]))
FROM point a, point_location b, point_location c, point_location d
WHERE a.p1=b.point_id and a.p2=c.point_id and a.p3=d.point_id

【讨论】:

  • 好!这个功能更好。谢谢。
猜你喜欢
  • 2014-04-29
  • 1970-01-01
  • 1970-01-01
  • 2011-11-27
  • 2020-01-20
  • 2018-08-19
  • 1970-01-01
  • 2012-11-13
  • 2013-04-21
相关资源
最近更新 更多