Skip to content

Latest commit

 

History

History
63 lines (46 loc) · 2.43 KB

shortestlineto-geometry-data-type.md

File metadata and controls

63 lines (46 loc) · 2.43 KB
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
ShortestLineTo method (geometry)
TSQL

ShortestLineTo (geometry Data Type)

[!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.

Syntax

  
.ShortestLineTo ( geometry_other )  

Arguments

geometry_other
The second geometry instance that the calling geometry instance is trying to determine the shortest distance to.

Return Types

[!INCLUDEssNoVersion] return type: geometry

CLR return type: SqlGeometry

Remarks

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.

Examples

A. Calling ShortestLineTo() on non-intersecting instances

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();

B. Calling ShortestLineTo() on intersecting instances

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();

See Also

ShortestLineTo (geography Data Type)