The && operator returns true if the bounding boxes of two spatial objects intersect, and false otherwise. It supports GeomGrid, H3Grid, and Geometry objects. Before comparing bounding boxes, GeomGrid and H3Grid objects are automatically converted to Geometry objects.
Syntax
bool &&(GeomGrid A, GeomGrid B);
bool &&(GeomGrid A, Geometry B);
bool &&(Geometry A, GeomGrid B);
bool &&(H3Grid A, H3Grid B);
bool &&(H3Grid A, Geometry B);
bool &&(Geometry A, H3Grid B);Parameters
| Parameter | Description |
|---|---|
A | A GeomGrid, H3Grid, or Geometry object |
B | A GeomGrid, H3Grid, or Geometry object |
Return value
Returns true if the bounding box of A intersects with the bounding box of B. Returns false otherwise.
Usage notes
By default,
GeomGridobjects are converted toGeometryin the 4490 coordinate system (CGCS2000) before the bounding box comparison.By default,
H3Gridobjects are converted toGeometryin the 4326 coordinate system (WGS84) before the bounding box comparison.
Examples
`&&(GeomGrid, GeomGrid)` — filter rows where bounding boxes intersect with a GeomGrid cell
SELECT COUNT(*) FROM geomgrid_gist_test WHERE 'G00'::GeomGrid && code;Output:
count
-------
5`&&(GeomGrid, Geometry)` — filter rows where a GeomGrid column intersects a polygon
SELECT COUNT(*) FROM geomgrid_gist_test WHERE code && 'SRID=4490;POLYGON((80 20,90 20,90 25,80 25,80 20))'::Geometry;Output:
count
-------
5`&&(H3Grid, H3Grid)` — filter rows where bounding boxes intersect with an H3 cell
SELECT COUNT(*) FROM h3grid_gist_test WHERE code && ST_H3FromLatLng(-17.5, -65.0, 1);Output:
count
-------
1`&&(Geometry, H3Grid)` — filter rows where a polygon intersects an H3Grid column
SELECT COUNT(*) FROM h3grid_gist_test WHERE 'SRID=4490;POLYGON((-70 -20,-60 -20,-60 -10,-70 -10,-70 -20))'::Geometry && code;Output:
count
-------
1