ShortestLineTo (geography Data Type)
Applies to:
SQL Server
Azure SQL Database
Azure SQL Managed Instance
Returns a LineString instance with two points that represent the shortest distance between the two geography instances. The length of the LineString instance returned is the distance between the two geography instances.
Syntax
.ShortestLineTo ( geography_other )
Note
To view Transact-SQL syntax for SQL Server 2014 (12.x) and earlier versions, see Previous versions documentation.
Arguments
geography_other
Specifies the second geography instance that the calling geography instance is trying to determine the shortest distance to.
Return Types
SQL Server return type: geography
CLR return type: SqlGeography
Remarks
The method returns a LineString instance with endpoints lying on the borders of the two non-intersecting geography instances being compared. The length of the LineString returned equals the shortest distance between the two geography instances. An empty LineString instance is returned when the two geography 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 geography = 'CIRCULARSTRING(-122.358 47.653, -122.348 47.649, -122.348 47.658, -122.358 47.658, -122.358 47.653)';
DECLARE @g2 geography = 'LINESTRING(-119.119263 46.183634, -119.273071 47.107523, -120.640869 47.569114, -122.200928 47.454094)';
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 geography = 'CIRCULARSTRING(-122.358 47.653, -122.348 47.649, -122.348 47.658, -122.358 47.658, -122.358 47.653)';
DECLARE @g2 geography = 'LINESTRING(-119.119263 46.183634, -119.273071 47.107523, -120.640869 47.569114, -122.348 47.649, -122.681 47.655)';
SELECT @g1.ShortestLineTo(@g2).ToString();
See Also
Extended Methods on Geography Instances
ShortestLineTo (geometry Data Type)
Phản hồi
https://aka.ms/ContentUserFeedback.
Sắp ra mắt: Trong năm 2024, chúng tôi sẽ dần gỡ bỏ Sự cố với GitHub dưới dạng cơ chế phản hồi cho nội dung và thay thế bằng hệ thống phản hồi mới. Để biết thêm thông tin, hãy xem:Gửi và xem ý kiến phản hồi dành cho