是什么这两个查询之间的区别:
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 ;
当第一个查询给正确的输出,而第二个查询检索没有行的。 相交多边形还路重叠,对吗?
从PostGIS的的文件
http://postgis.net/docs/ST_Intersects.html
如果几何或地理股空间任何部分,然后它们相交。 重叠,倒是,在所有暗示的空间交集。 如果上述任何回报的话,那么也几何空间相交。
http://postgis.net/docs/ST_Overlaps.html
如果几何“空间重叠”,则返回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