我想使用 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
最佳答案
从点构建多边形的更好方法是使用 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
关于postgresql - 使用 PostGIS 将点转换为多边形,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19046642/