Skip to main content

st_within function

Applies to: check marked yes Databricks SQL check marked yes Databricks Runtime 17.1 and above

Preview

This feature is in Public Preview.

Returns true if the first GEOMETRY is within the second GEOMETRY.

Syntax

st_within ( geo1, geo2 )

Arguments

  • geo1: The first GEOMETRY value.
  • geo2: The second GEOMETRY value.

Returns

A value of type BOOLEAN, true if the first geometry is within the second geometry.

The function returns NULL if any of the inputs is NULL.

Error conditions

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