PostGIS交叉多个几何体

时间:2016-12-29 01:03:03

标签: postgis intersect

我有一个postgis多边形表(zipcode1)和两个点表(pm253,blockpop)。我想将多边形表与两个点表相交,并计算每个点表有多少点,总结一些其他属性来计算比率。我能够针对单个表格进行操作,如下所示:

SELECT zipcode1.gid, count(*) as totpm, sum(pm) as totsum, sum(pm)/count(*) as res 
FROM pm253, zipcode1 
WHERE st_intersects(st_buffer(zipcode1.geom, 100),pm253.geom) 
GROUP BY zipcode1.gid 

有什么建议吗?谢谢。

1 个答案:

答案 0 :(得分:0)

尝试结合;

SELECT 'zipcode1<->pm253' as tables, zipcode1.gid, count(*) as totpm, sum(pm) as totsum, sum(pm)/count(*) as res 
FROM pm253, zipcode1 
WHERE st_intersects(st_buffer(zipcode1.geom, 100),pm253.geom)  and zipcode1.geom&&pm253.geom -- to accelerate query
GROUP BY zipcode1.gid 

union

SELECT 'zipcode1<->blockpop' as tables, zipcode1.gid, count(*) as totpm, sum(pm) as totsum, sum(pm)/count(*) as res 
FROM blockpop, zipcode1 
WHERE st_intersects(st_buffer(zipcode1.geom, 100),blockpop.geom)  and zipcode1.geom && blockpop.geom -- to accelerate query
GROUP BY zipcode1.gid