STDistance (geometry Data Type)

THIS TOPIC APPLIES TO:yesSQL Server (starting with 2008)noAzure SQL DatabasenoAzure SQL Data Warehouse noParallel Data Warehouse

Returns the shortest distance between a point in a geometry instance and a point in another geometry instance.

||
|-|
|Applies to: SQL Server ( SQL Server 2008 through current version), Azure SQL Database.|

Syntax


.STDistance ( other_geometry )  

Arguments

other_geometry
Is another geometry instance from which to measure the distance between the instance on which STDistance() is invoked. If other_geometry is an empty set, STDistance() returns null.

Return Types

SQL Server return type: float

CLR return type: SqlDouble

Remarks

STDistance() always returns null if the spatial reference IDs (SRIDs) of the geometry instances do not match.

Examples

DECLARE @g geometry;  
DECLARE @h geometry;  
SET @g = geometry::STGeomFromText('POLYGON((0 0, 2 0, 2 2, 0 2, 0 0))', 0);  
SET @h = geometry::STGeomFromText('POINT(10 10)', 0);  
SELECT @g.STDistance(@h);  

See Also

Spatial Indexes Overview
OGC Methods on Geometry Instances