title | description | author | ms.author | ms.date | ms.service | ms.subservice | ms.topic | helpviewer_keywords | dev_langs | ||
---|---|---|---|---|---|---|---|---|---|---|---|
ShortestLineTo (geometry Data Type) |
ShortestLineTo (geometry Data Type) |
MladjoA |
mlandzic |
08/03/2017 |
sql |
t-sql |
reference |
|
|
[!INCLUDE SQL Server Azure SQL Database Azure SQL Managed Instance]
Returns a LineString instance with two points that represent the shortest distance between the two geometry instances. The length of the LineString instance returned is the distance between the two geometry instances.
.ShortestLineTo ( geometry_other )
geometry_other
The second geometry instance that the calling geometry instance is trying to determine the shortest distance to.
[!INCLUDEssNoVersion] return type: geometry
CLR return type: SqlGeometry
The method returns a LineString instance with endpoints lying on the borders of the two non-intersecting geometry instances being compared. The length of the LineString returned equals the shortest distance between the two geometry instances. An empty LineString instance is returned when the two geometry instances intersect each other.
This example finds the shortest distance between a CircularString
instance and a LineString
instance and returns the LineString
instance connecting the two points:
DECLARE @g1 geometry = 'CIRCULARSTRING(0 0, 1 2.1082, 3 6.3246, 0 7, -3 6.3246, -1 2.1082, 0 0)';
DECLARE @g2 geometry = 'LINESTRING(-4 7, 7 10, 3 7)';
SELECT @g1.ShortestLineTo(@g2).ToString();
This example returns an empty LineString
instance because the LineString
instance intersects the CircularString
instance:
DECLARE @g1 geometry = 'CIRCULARSTRING(0 0, 1 2.1082, 3 6.3246, 0 7, -3 6.3246, -1 2.1082, 0 0)';
DECLARE @g2 geometry = 'LINESTRING(0 5, 7 10, 3 7)';
SELECT @g1.ShortestLineTo(@g2).ToString();