使用PostGIS将点转换为多边形

5

我想使用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

1
你应该在gis.stackexchange.com上提出这个问题。 - SeyedPooya Soofbaf
1个回答

14

构建多边形的更好方法是使用PostGIS几何构造器。这样,您就可以避免转换二进制→文本→二进制(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

好的!这个函数更好。谢谢。 - Ben

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接