有没有办法 select SUM 有 ST_INTERSECTS 限制?
Is there a way to select SUM with a ST_INTERSECTS restriction?
我会尽力解释我的问题。我正在尝试使用此表达式 select 具有 ST_intersect 限制的列上的属性总和;
with inter as (
select
planet_osm_point.way pw,
(select sum (planet_osm_point.osm_id)
from planet_osm_polygon, planet_osm_point
where st_intersects (planet_osm_point.way, planet_osm_polygon.way)) as sum1
from planet_osm_point
)
select pw, sum1
from inter, planet_osm_point
group by pw, sum1
这 returns 我每个 planet_osm_point.way 的所有 osm_id 的总和相同。我只想对与多边形相交的 osm_id 求和,并按 planet_osm_point.way.
分组
有什么想法吗?
谢谢!
我相信一个简单的空间连接就足够了,例如
SELECT pol.way, sum(poi.osm_id)
FROM planet_osm_point poi, planet_osm_polygon pol
WHERE ST_Intersects(poi.way,pol.way)
GROUP BY pol.way
我会尽力解释我的问题。我正在尝试使用此表达式 select 具有 ST_intersect 限制的列上的属性总和;
with inter as (
select
planet_osm_point.way pw,
(select sum (planet_osm_point.osm_id)
from planet_osm_polygon, planet_osm_point
where st_intersects (planet_osm_point.way, planet_osm_polygon.way)) as sum1
from planet_osm_point
)
select pw, sum1
from inter, planet_osm_point
group by pw, sum1
这 returns 我每个 planet_osm_point.way 的所有 osm_id 的总和相同。我只想对与多边形相交的 osm_id 求和,并按 planet_osm_point.way.
分组有什么想法吗?
谢谢!
我相信一个简单的空间连接就足够了,例如
SELECT pol.way, sum(poi.osm_id)
FROM planet_osm_point poi, planet_osm_polygon pol
WHERE ST_Intersects(poi.way,pol.way)
GROUP BY pol.way