This topic has not yet been rated - Rate this topic

ShortestLineTo (geometry Data Type)

SQL Server 2012

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.

SQL Server 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.

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

Did you find this helpful?
(1500 characters remaining)

Community Additions

ADD
© 2013 Microsoft. All rights reserved.