这两个查询之间有什么区别:
select a.gid, sum(length(b.the_geom))
from polygons as a
, roads as b
where st_intersects(a.the_geom,b.the_geom)
group by a.gid ;
select a.gid, sum(length(b.the_geom))
from polygons as a
, roads as b
where st_overlaps(a.the_geom,b.the_geom)
group by a.gid ;
第一个查询提供正确的输出,而第二个查询根本不检索任何行。与多边形相交的道路也与它重叠,对吗?
答案 0 :(得分:12)
来自PostGIS的文档
http://postgis.net/docs/ST_Intersects.html
如果几何体或地理位置共享任何空间部分,则它们相交。重叠,触摸,在所有暗示空间交叉。如果有的话 上述返回为真,那么几何也在空间上 相交。
http://postgis.net/docs/ST_Overlaps.html
如果Geometries"在空间上重叠"则返回TRUE。我们的意思是 它们相交,但一个不完全包含另一个。
不同之处在于:如果两个几何重叠100%,则它们不再重叠。
这是一个POSTGIS示例:
SELECT ST_Overlaps(a,b) As a_overlap_b, ST_Intersects(a, b) As a_intersects_b, ST_Contains(b, a) As b_contains_a
FROM (SELECT
ST_Polygon(ST_GeomFromText('LINESTRING(1 1,3 1,3 3,1 1)'), 4326) As a,
ST_Polygon(ST_GeomFromText('LINESTRING(1 1,3 1,3 3,1 1)'), 4326) As b)
As foo;
-- INTERSECT is TRUE, OVERLAP is FALSE because B equals A
SELECT ST_Overlaps(a,b) As a_overlap_b, ST_Intersects(a, b) As a_intersects_b, ST_Contains(b, a) As b_contains_a
FROM (SELECT
ST_Polygon(ST_GeomFromText('LINESTRING(1 1,3 1,3 3,1 1)'), 4326) As a,
ST_Polygon(ST_GeomFromText('LINESTRING(1 1,4 1,4 4,1 1)'), 4326) As b)
As foo;
-- INTERSECT is TRUE, OVERLAP is FALSE because B contains A
SELECT ST_Overlaps(a,b) As a_overlap_b, ST_Intersects(a, b) As a_intersects_b, ST_Contains(b, a) As b_contains_a
FROM (SELECT
ST_Polygon(ST_GeomFromText('LINESTRING(0 0,2 0,2 2,0 0)'), 4326) As a,
ST_Polygon(ST_GeomFromText('LINESTRING(1 1,3 1,3 3,1 1)'), 4326) As b)
As foo;
-- INTERSECT is TRUE, OVERLAP is TRUE because not all of A intersects B and not all of B intersects A