Pertanyaan st_intersects Vs st_overlaps


Apa perbedaan antara dua kueri ini:

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 ;

Di mana kueri pertama memberikan output yang benar sedangkan kueri kedua tidak mengambil baris sama sekali. Jalan yang memotong poligon juga tumpang tindih, kan?


5
2018-05-07 10:14


asal


Jawaban:


Dari dokumentasi PostGIS

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

Jika geometri atau geografi berbagi bagian ruang apa pun maka mereka berpotongan. Tumpang tindih, Sentuhan, Dalam semua menyiratkan persimpangan spasial. Jika ada   Pengembalian tersebut benar, maka geometri juga secara spasial   memotong.

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

Mengembalikan TRUE jika Geometri "secara spasial tumpang tindih". Maksud kami   mereka berpotongan, tetapi yang satu tidak sepenuhnya mengandung yang lain.

Perbedaannya adalah: Jika dua geometri tumpang tindih 100%, mereka tidak tumpang tindih lagi.

Berikut adalah contoh 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

9
2018-06-10 21:03