ST_DISTANCE (Azure Cosmos DB)

APPLIES TO: NoSQL

Returns the distance between the two GeoJSON Point, Polygon, MultiPolygon or LineString expressions. To learn more, see the Geospatial and GeoJSON location data article.

Syntax

ST_DISTANCE (<spatial_expr>, <spatial_expr>)  

Arguments

spatial_expr
Is any valid GeoJSON Point, Polygon, or LineString object expression.

Return types

Returns a numeric expression containing the distance. This is expressed in meters for the default reference system.

Examples

The following example shows how to return all family documents that are within 30 km of the specified location using the ST_DISTANCE built-in function.

SELECT f.id
FROM Families f
WHERE ST_DISTANCE(f.location, {'type': 'Point', 'coordinates':[31.9, -4.8]}) < 30000  

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