我有一个查询,它采用 LINESTRING 并将其转换为 POINTS 结果集。
我想不通的是如何在这个结果集中找到 2 个特定行点之间的距离。
这是我到目前为止所拥有的:
DECLARE @GeographyToConvert geography
SET @GeographyToConvert = geography::STGeomFromText('LINESTRING (26.6434033 -81.7097817, 26.6435367 -81.709785, 26.6435783 -81.7098033, 26.6436067 -81.709825, 26.6435883 -81.709875, 26.64356 -81.7100417, 26.6434417 -81.710125, 26.6433167 -81.7101467, 26.643195 -81.7101033, 26.6431533 -81.7099517, 26.643175 -81.7097867, 26.643165 -81.7097917, 26.6431633 -81.7097367, 26.6431583 -81.7097083)',4326);
WITH GeographyPoints(N, Point) AS
(
SELECT 1, @GeographyToConvert.STPointN(1)
UNION ALL
SELECT N + 1, @GeographyToConvert.STPointN(N + 1)
FROM GeographyPoints GP
WHERE N < @GeographyToConvert.STNumPoints()
)
SELECT N,Point.STBuffer(0.25) as point, Point.STAsText() FROM GeographyPoints
例如,如何比较 N=10 和 N=11 之间的距离?
这是我正在尝试的,但它不起作用:
Declare @Point1 geography;
Declare @Point2 geography;
DECLARE @GeographyToConvert geography
--SET @GeometryToConvert = (select top 1 geotrack from dbo.SYNCTESTING2 where geotrack is not null);
SET @GeographyToConvert = geography::STGeomFromText('LINESTRING (26.6434033 -81.7097817, 26.6435367 -81.709785, 26.6435783 -81.7098033, 26.6436067 -81.709825, 26.6435883 -81.709875, 26.64356 -81.7100417, 26.6434417 -81.710125, 26.6433167 -81.7101467, 26.643195 -81.7101033, 26.6431533 -81.7099517, 26.643175 -81.7097867, 26.643165 -81.7097917, 26.6431633 -81.7097367, 26.6431583 -81.7097083)',4326);
WITH GeographyPoints(N, Point) AS
(
SELECT 1, @GeographyToConvert.STPointN(1)
UNION ALL
SELECT N + 1, @GeographyToConvert.STPointN(N + 1)
FROM GeographyPoints GP
WHERE N < @GeographyToConvert.STNumPoints()
)
SELECT N,Point.STBuffer(0.25) as point, Point.STAsText() FROM GeographyPoints
select @Point1 = Point FROM GeometryPoints where N = 10;
select @Point2 = Point FROM GeometryPoints where N = 11
select @Point1.STDistance(@Point2) as [Distance in Meters]