【问题标题】:Number of rows returned for each point PostGIS每个点返回的行数 PostGIS
【发布时间】:2021-04-01 05:13:30
【问题描述】:

我有两个点数据集。我想计算表 A 中每个位置 2 公里范围内的表 B 中的点数,并将其存储为整数列。

我使用下面的代码从 A 返回 B 2 公里范围内的每个点,但我不确定如何提取此结果中 A 出现的次数并将其存储到新列中。

select a.name, b.incident_zip 
from ny_air_bnb as a, nypubs as b 
where(st_transform(a.geom,2263) <-> st_transform(b.geom,2263) <= 2000)

【问题讨论】:

  • 请提供样本数据和期望的结果。 “a 的出现次数”是什么意思?

标签: sql postgresql gis postgis


【解决方案1】:

也许你只想要窗口函数:

select a.name, b.incident_zip, count(*) over (partition by a.name)
from ny_air_bnb a join
     nypubs as b 
     on (st_transform(a.geom,2263) <-> st_transform(b.geom,2263) <= 2000);

编辑:

如果你想把它存储在ny_air_bnb,你需要update

update ny_air_bnb a
    set col = (select count(*)
               from nypubs p
               where st_transform(a.geom, 2263) <-> st_transform(p.geom, 2263) <= 2000
              );

【讨论】:

  • 非常感谢,这几乎正是我所追求的!我只需要将结果计数变量添加到它自己的列中。再次感谢您!
  • @BenGuilfoyle 。 . .我不明白你的评论。计数 在单独的列中。
  • 我希望将“count”列附加到 ny_air_bnb 列
  • Count 显然是一个数值。请解释将其“附加”到列的含义。
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2020-06-25
  • 1970-01-01
  • 2018-06-09
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多