title | titleSuffix | description | author | ms.author | ms.reviewer | ms.service | ms.subservice | ms.topic | ms.devlang | ms.date | ms.custom |
---|---|---|---|---|---|---|---|---|---|---|---|
ST_DISTANCE |
Azure Cosmos DB for NoSQL |
An Azure Cosmos DB for NoSQL system function that returns the distance between two GeoJSON Point, Polygon, MultiPolygon or LineStrings. |
jcodella |
jacodel |
sidandrews |
cosmos-db |
nosql |
reference |
nosql |
02/27/2024 |
query-reference |
[!INCLUDENoSQL]
Returns the distance between two GeoJSON Point, Polygon, MultiPolygon or LineString expressions.
Note
For more information, see Geospatial and GeoJSON location data.
ST_DISTANCE(<spatial_expr_1>, <spatial_expr_2>)
Description | |
---|---|
spatial_expr_1 |
Any valid GeoJSON Point, Polygon, MultiPolygon or LineString expression. |
spatial_expr_2 |
Any valid GeoJSON Point, Polygon, MultiPolygon or LineString expression. |
Returns a numeric expression that enumerates the distance between two expressions.
The following example assumes a container exists with two items.
:::code language="json" source="~/cosmos-db-nosql-query-samples/scripts/st-distance/seed.json" range="1-2,4-14,16-26" highlight="4-10,15-21":::
The example shows how to use the function as a filter to return items within a specified distance.
:::code language="nosql" source="~/cosmos-db-nosql-query-samples/scripts/st-distance/query.sql" highlight="3-6":::
:::code language="json" source="~/cosmos-db-nosql-query-samples/scripts/st-distance/result.json":::
- The result is expressed in meters for the default reference system.
- This function benefits from a geospatial index except in queries with aggregates.
- 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.