ST_WITHIN (Azure Cosmos DB)

APPLIES TO: SQL API

Returns a Boolean expression indicating whether the GeoJSON object (Point, Polygon, MultiPolygon, or LineString) specified in the first argument is within the GeoJSON (Point, Polygon, MultiPolygon, or LineString) in the second argument.

Syntax

ST_WITHIN (<spatial_expr>, <spatial_expr>)  

Arguments

spatial_expr
Is a GeoJSON Point, Polygon, or LineString object expression.

Return types

Returns a Boolean value.

Examples

The following example shows how to find all family documents within a polygon using ST_WITHIN.

SELECT f.id
FROM Families f
WHERE ST_WITHIN(f.location, {  
    'type':'Polygon',
    'coordinates': [[[31.8, -5], [32, -5], [32, -4.7], [31.8, -4.7], [31.8, -5]]]  
})  

Here is the result set.

[{ "id": "WakefieldFamily" }]  

Remarks

This system function will benefit from a geospatial index except in queries with aggregates.

Note

The GeoJSON specification requires that points within a Polygon be specified in counter-clockwise order. A Polygon specified in clockwise order represents the inverse of the region within it.

Next steps