13

In PostGIS, what is the result of the && operation between two geometries? In my mind, && returns a boolean, but does return geometry this time. In the following example, the operation is between a LineString and a Polygon.

Firstly, I guess this is the relationship between inclusion and being included. Until I do the following example, I think this should be a relationship of type "intersection". Am I right?

select ST_geomfromtext('linestring(0.1 0.1,1.9 1.9)', 4326) && st_geomfromtext('POLYGON((0 0,0 1,1 1,1 0,0 0))', 4326)

The result is t which represents true.

Ben
  • 960
  • 8
  • 17
sh g
  • 173
  • 1
  • 6
  • 3
    Note that `&&` is also the "overlaps" operator for [arrays](https://www.postgresql.org/docs/current/functions-array.html) and [ranges](https://www.postgresql.org/docs/current/functions-range.html) and the `AND` operator for [full text search](https://www.postgresql.org/docs/current/functions-textsearch.html) –  Aug 02 '19 at 05:09

2 Answers2

14

It's an intersection operator &&

boolean &&( geometry A , geometry B );

boolean &&( geography A , geography B );

The && operator returns TRUE if the 2D bounding box of geometry A intersects the 2D bounding box of geometry B.

How one could find it using google:

  1. Search for "postgis operators"
  2. On the first page https://postgis.net/docs/reference.html search for &&
Community
  • 1
  • 1
zerkms
  • 249,484
  • 69
  • 436
  • 539
0

diff between && and st_intersect.
https://postgis.net/docs/ST_Intersects.html

If a geometry or geography shares any portion of space then they intersect. For geography -- tolerance is 0.00001 meters (so any points that are close are considered to intersect)

So it's possible that boolean &&( geometry A , geometry B ); return true, but st_intersects(geometry A, geometry B) return false. example: https://postgis.net/workshops/postgis-intro/indexing.html

But boolean st_intersects(geometry A, geometry B) will yield the same result as boolean &&( geometry A , geometry B );

jian
  • 4,119
  • 1
  • 17
  • 32