繁体   English   中英

避免在 PostgreSQL 和 PostGIS 中进行双重计算以提高性能

[英]Avoiding double calculation in PostgreSQL and PostGIS for improved performance

带有双重计算的 PostgreSQL / PostGIS 示例:

select a.gid, b.gid, st_area(st_intersection(a.geom, b.geom)) from a_polygons a, b_polygons b 
where st_intersects(a.geom, b.geom) and st_area(st_intersection(a.geom, b.geom)) > 10;

在这种情况下,是否有一些简单的方法可以避免对相同值进行双重(多次)计算?

我知道我可以像这样实现它:

with i_poly as (select a.gid a_gid, b.gid b_gid, st_area(st_intersection(a.geom, b.geom)) i_area  
from a_polygons a, b_polygons b where st_intersects(a.geom, b.geom))
select a_gid, b_gid, i_area from i_poly where i_area > 10;

有没有什么简单的方法可以在没有子查询等的情况下实现它? 像这样简单的事情:

 select i_area from a_polygons a, b_polygons b where st_area(st_intersection(a.geom, b.geom)) as i_area > 10;

将多边形计算移至from子句:

select a.gid, b.gid, a.area
from a_polygons a cross join
     b_polygons b cross join lateral
     (values (st_intersects(a.geom, b.geom)) i(intersect) cross join lateral
     (values (st_area(i.intersect))) a(area)
where i.intersect and a.area > 10;

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM