使用经度和经度制作凸包邮PostGIS

时间:2018-03-24 23:40:08

标签: postgresql postgis

我需要使用在表格中输入的点生成凸包的坐标。

这就是我创建表格的方式

CREATE TABLE map5(id VARCHAR (50) PRIMARY KEY,
              points geometry);

这就是我输入积分的方式

Insert into map5 (id,id2, points) VALUES ('LeaveyLibrary',
'1',ST_GeomFromText('POINT(-118.282866 34.021845)', 4326));
Insert into map5 (id, id2,points) VALUES ('TommyTrojan', 
'1',ST_GeomFromText('POINT(-118.2876357 34.0205621)', 4326));
Insert into map5 (id, id2,points) VALUES ('DohenyLibrary', 
'1',ST_GeomFromText('POINT(-118.2849868 34.0201529)', 4326));
Insert into map5 (id, id2,points) VALUES ('VKCLibrary', 
'1',ST_GeomFromText('POINT(-118.2843347 34.0205791)', 4326));

这就是我生成凸包的方法

SELECT st_astext(ST_ConvexHull(ST_Collect(points::geometry))) as points 
from map5 group by id;

然而它只返回点而不是多边形,我在这里做错了什么?谢谢。

1 个答案:

答案 0 :(得分:2)

要将ConcaveHull作为一个geom,您的查询必须如下:

Select ST_ConcaveHull(ST_Collect(d.geom),1) As geom
FROM points As d

在你的情况下:

Select st_astext(ST_ConcaveHull(ST_Collect(points::geometry),1)) As polygon
FROM map5

结果:

enter image description here