ShortestLineTo (geometry)

ShortestLineTo (geometry)#

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 type#

geometry

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.

Example#

Call ShortestLineTo() on non-intersecting instances to find the shortest distance between a CircularString instance and a LineString instance and return 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();

See Also#