如何绘制与点簇区域相对应的多边形?

cdmah0mi  于 2021-07-29  发布在  Java
关注(0)|答案(1)|浏览(429)

给定以下数据集,我尝试创建一个覆盖点簇最小区域的多边形:

CREATE TABLE public.points ( 
  cat integer,
  geom geometry (point, 4326)
);

INSERT INTO points VALUES 
  (1,'SRID=4326;POINT(-35.3971 -8.1366)'),
  (1,'SRID=4326;POINT(-35.388 -8.1366)'),
  (1,'SRID=4326;POINT(-35.3907 -8.1302)'),
  (1,'SRID=4326;POINT(-35.3925 -8.1366)'),
  (1,'SRID=4326;POINT(-35.3896 -8.1418)'),
  (2,'SRID=4326;POINT(-35.3996 -8.1418)'),
  (2,'SRID=4326;POINT(-35.4056 -8.1418)'),
  (2,'SRID=4326;POINT(-35.4056 -8.1542)');

我试过用 ST_Envelope ,但顾名思义,它在集群周围形成了一个封套,因此比我们需要的面积要大得多。

SELECT ST_Envelope(geom) FROM (
  SELECT ST_Collect(geom) AS geom
  FROM points GROUP BY cat
) mypoints

如何缩小封套来创建一个多多少少只覆盖点和点之间的空间的多边形?

uz75evzq

uz75evzq1#

要创建这样的多边形,必须使用 ST_ConvexHull 或者 ST_ConcaveHull ,例如。

WITH j AS (
  SELECT ST_Collect(geom) AS geom
  FROM points GROUP BY cat
)
SELECT ST_ConvexHull(geom) FROM j 
UNION ALL SELECT geom FROM j;


注: UNION ALL SELECT geom FROM j 所有的点都只是为了说明。

相关问题