[英]Convert Points to Polygon using PostGIS
我想使用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的幾何構造函數 。 這樣,您就可以避免轉換二進制→文本→二進制( 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
b.y'))'應該由||改變 '))'
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.