gpt4 book ai didi

sql - st_intersects 与 st_overlaps

转载 作者:行者123 更新时间:2023-12-02 04:16:02 25 4
gpt4 key购买 nike

这两个查询有什么区别:

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

If a geometry or geography shares any portion of space then they intersect. Overlaps, Touches, Within all imply spatial intersection. If any of the aforementioned returns true, then the geometries also spatially intersect.

http://postgis.net/docs/ST_Overlaps.html

Returns TRUE if the Geometries "spatially overlap". By that we mean they intersect, but one does not completely contain another.

区别在于:如果两个几何图形重叠 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

关于sql - st_intersects 与 st_overlaps,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10480320/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com