我注意到运行这个子查询
SELECT ST_Area(ST_Union(ST_Transform(ST_Intersection((SELECT poly1.the_geom from poly1 WHERE poly1.polygon_type='P'),poly2.the_geom),3857)))
AS area_of_P FROM poly1, poly2
比运行此连接慢得多
选择 ST_AREA(ST_Union(ST_Transform(ST_Intersection(poly1.the_geom,poly2.the_geom),3857)))
AS area_of_poly
从聚2
在 st_intersects(poly1.the_geom,poly2.the_geom) 上左连接 poly1
其中 poly2.polygon_type='P'
但是,我需要扩展第二个加入版本以返回更多列,每个列都计算给定多边形类型的面积,即
SELECT ST_Area(ST_Union(ST_Transform(ST_Intersection((SELECT poly1.the_geom from poly1 WHERE poly1.polygon_type='P'),poly2.the_geom),3857))) AS area_of_P,
ST_Area(ST_Union(ST_Transform(ST_Intersection((SELECT poly1.the_geom from poly1 WHERE poly1.polygon_type='S'),poly2.the_geom),3857))) AS area_of_S
来自 poly1, poly2