1

我需要找出 shape_area 大于 1000m^2 的城市之间的最小距离。我正在使用 Postgresql 和 PostGis,我的表格如下所示:

CREATE TABLE "cities" (gid serial,
"city_id" int4,
"city" varchar(21),
"shape_area" numeric);

SELECT AddGeometryColumn('','cities','geom','26986','MULTIPOLYGON',2);
4

1 回答 1

2

假设EPSG:26986已经有米为单位,只需将表与自身连接并使用ST_Area仅过滤面积大于 1000 平方米的记录。之后min()与 a一起使用GROUP BY以获得最短距离:

SELECT t1.city, t2.city, min(ST_Distance(t1.geom,t2.geom))
FROM cities t1 
JOIN cities t2 ON 
  t1.gid <> t2.gid AND
  ST_Area(t1.geom) > 1000 AND
  ST_Area(t2.geom) > 1000
GROUP BY 1,2;
于 2021-11-10T09:14:44.623 回答