st_within
function
Applies to: Databricks SQL
Databricks Runtime 17.1 and above
Preview
This feature is in Public Preview.
nota
This feature is not available on Databricks SQL Classic warehouses. To learn more about Databricks SQL warehouses, see SQL warehouse types.
Returns true if the first GEOMETRY
value is within the second GEOMETRY
value.
Syntax
st_within ( geo1, geo2 )
Arguments
geo1
: The firstGEOMETRY
value.geo2
: The secondGEOMETRY
value.
Returns
A value of type BOOLEAN
, indicating whether the first GEOMETRY
value is within the second GEOMETRY
value.
The function does not support geometry collections.
For more details and the formal definition, see the Within predicate in the DE-9IM matrix definition.
The function returns NULL
if any of the inputs is NULL
.
Error conditions
- If any of the input geometries is a geometry collection, the function returns ST_INVALID_ARGUMENT.INVALID_TYPE.
- If the input geometries do not have the same SRID value, the function returns ST_DIFFERENT_SRID_VALUES.
Examples
SQL
-- Returns true when point is within polygon.
> SELECT st_within(st_geomfromtext('POINT(1 1)'),st_geomfromtext('POLYGON((0 0,10 0,0 10,0 0))'));
true
-- Returns false when point is on boundary.
> SELECT st_within(st_geomfromtext('POINT(5 0)'),st_geomfromtext('POLYGON((0 0,10 0,0 10,0 0))'));
false
-- Returns false when point is outside polygon.
> SELECT st_within(st_geomfromtext('POINT(5 6)'),st_geomfromtext('POLYGON((0 0,10 0,0 10,0 0))'));
false