【问题标题】:Find distance between cities in spatial table在空间表中查找城市之间的距离
【发布时间】:2021-12-22 20:12:39
【问题描述】:

我需要找出 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);

【问题讨论】:

标签: sql postgresql postgis spatial


【解决方案1】:

假设EPSG:26986已经有米为单位,只需将表与自身连接并使用ST_Area仅过滤面积大于1000平方米的记录。之后使用min()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;

【讨论】:

    猜你喜欢
    • 2011-03-25
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2010-09-06
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多