1

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]
4

2 に答える 2

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, PreviousPoint, DistanceFromPrevious) AS  
( 
   SELECT 1,  @GeographyToConvert.STPointN(1), CAST(NULL AS GEOGRAPHY), CAST(0 AS Float)
   UNION ALL
   SELECT N + 1, @GeographyToConvert.STPointN(N + 1)
            , @GeographyToConvert.STPointN(N)
            , @GeographyToConvert.STPointN(N).STDistance(@GeographyToConvert.STPointN(N + 1))
   FROM GeographyPoints GP
   WHERE N < @GeographyToConvert.STNumPoints() 
)

SELECT N,Point.STBuffer(0.25) as point, Point.STAsText(), PreviousPoint, DistanceFromPrevious FROM GeographyPoints

ここに画像の説明を入力

于 2013-10-30T19:05:54.930 に答える
2

交換

SELECT N,Point.STBuffer(0.25) as point, Point.STAsText() FROM GeographyPoints

SELECT * INTO #GeographyPoints FROM GeographyPoints

DECLARE @N1 INT = 10
DECLARE @N2 INT = 11

SELECT (SELECT Point FROM #GeographyPoints WHERE N=@N1).STDistance(
            (SELECT Point FROM #GeographyPoints WHERE N=@N2))

DROP TABLE #GeographyPoints

必要に応じて @N1 と @N2 の値を変更するだけです

于 2013-10-30T19:23:10.357 に答える