加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 百科 > 正文

postgresql – 使用PostGIS将点转换为多边形

发布时间:2020-12-13 16:03:50 所属栏目:百科 来源:网络整理
导读:我想使用PostGIS创建一个多边形表.表’point’中的每一行都有三个点ID. 表’point_location’具有点的位置信息.我用Google搜索了这个问题,但未找到答案.以下代码有什么问题? select ST_GeomFromText('POLYGON((' || b.x || ' ' || b.y || ',' || c.x || ' '
我想使用PostGIS创建一个多边形表.表’point’中的每一行都有三个点ID.
表’point_location’具有点的位置信息.我用Google搜索了这个问题,但未找到答案.以下代码有什么问题?

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

解决方法

从点构造多边形的更好方法是使用 PostGIS’ geometry constructors.这样,您就可以避免转换二进制→文本→二进制( WKB → WKT → WKB),这种速度较慢,有损,并且容易出现文本格式分散,如缺失所示||.例如,尝试:

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

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读