ST_COVERS
Reference material for ST_COVERS function
The ST_COVERS
function determines if one GEOGRAPHY
object fully encompasses another. Specifically, it checks whether every point in the second GEOGRAPHY
object (geo2
) lies within or on the boundary of the first GEOGRAPHY
object (geo1
). If geo1
covers geo2
, the function returns TRUE
; otherwise, it returns FALSE
. This function is commonly used to assess spatial relationships, such as whether a larger geographic area completely includes a smaller one.
If either geo1
or geo2
is empty, ST_COVERS
will return FALSE
.
Before performing the coverage check, geo1
and geo2
are aligned through a snapping process, ensuring precise calculation. For more details on snapping, refer to the snapping documentation.
Comparison with ST_CONTAINS
ST_COVERS
is similar to ST_CONTAINS
, but there is a key distinction: ST_CONTAINS
returns FALSE
if all points in geo2
lie exactly on the boundary of geo1
, while ST_COVERS
will return TRUE
in this case. If this distinction is not important, use ST_COVERS
, which is more efficient to compute in Firebolt.
Syntax
Parameters
Parameter | Description | Supported input types |
---|---|---|
<geo1> | The object being checked to see if it fully covers the second object. | GEOGRAPHY |
<geo2> | The object being checked to see if it fully covers the first object. | GEOGRAPHY |
Return Type
ST_COVERS
returns a value of type BOOLEAN
.
Example
The following codes example creates a Polygon and a Point around Times Square in New York City from their WKT representations and checks if the Polygon covers the Point:
Returns
result (BOOLEAN) |
---|
t |
Example
The following example illustrates the difference between ST_CONTAINS
and ST_COVERS
. The Polygon POLYGON((0 0, 0 1, 1 1, 1 0, 0 0))
covers, but does not contain the LineString LINESTRING(0 0, 0 0.5)
because it only lies on the Polygon’s boundary and does not intersect the interior of the Polygon. The LineString LINESTRING(0 0, 0 0.5, 0.5 0.5)
only partially lies on the Polygon’s boundary but also intersects its interior, so it is covered and contained.
Returns
polygon (TEXT) | linestring (TEXT) | contains (BOOLEAN) | covers (BOOLEAN) |
---|---|---|---|
‘POLYGON((0 0, 0 1, 1 1, 1 0, 0 0))' | 'LINESTRING(0 0, 0 0.5)‘ | f | t |
’POLYGON((0 0, 0 1, 1 1, 1 0, 0 0))' | 'LINESTRING(0 0, 0 0.5, 0.5 0.5)‘ | t | t |