'what is the meaning of && in PostgreSQL?
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.
Solution 1:[1]
It's an intersection operator &&
boolean &&( geometry A , geometry B );
boolean &&( geography A , geography B );The
&&operator returnsTRUEif the 2D bounding box of geometryAintersects the 2D bounding box of geometryB.
How one could find it using google:
- Search for "postgis operators"
- On the first page https://postgis.net/docs/reference.html search for
&&
Solution 2:[2]
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 );
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | Community |
| Solution 2 | Mark |
