gpt4 book ai didi

.net - SQL Server 2008 R2 地理距离?

转载 作者:行者123 更新时间:2023-12-02 13:18:40 25 4
gpt4 key购买 nike

我创建了一个包含以下列的表格:

Text:varchar(255)
Location:geography

它们包含荷兰的一些城市作为数据(从谷歌地图获取坐标):

Rotterdam - POINT (51.925637 4.493408 4326)
Utrecht - POINT (52.055868 5.103149 4326)
Nijmegen - POINT (51.801822 5.828247 4326)
Breda - POINT (51.542919 4.77356 4326)

我想知道数据库中所有城市与鹿特丹之间的距离,因此我执行以下查询:

Select 
Text, Location,
Location.STDistance(geography::Point(51.925638, 4.493408, 4326)) as Distance
from Messages

但结果是每个城市的距离接近 6800000。

这可能是什么原因造成的?

我能想到的唯一原因是我使用了错误的 SRID,但我不知道应该使用哪一个。

谢谢!

编辑:

只是为了玩玩这些数字,我得到了一些奇怪的结果:

Distance from Rotterdam to Rotterdam: 6828459.57 (A) (weird but true)
Distance from Rotterdam to Breda: 6779956.10 (B)
Distance from Rotterdam to Nijmegen: 6695336.38 (C)

现在有趣的地方是:

(A) - (B) = 48504 m = 48 km
(A) - (C) = 133123 m = 133 km

这些值大致是这些城市之间的距离。

最佳答案

尝试这样的结构。

DECLARE @a geography, @b geography
SET @a = geography::Point(51.925637, 4.493408,4326)
SET @b= geography::Point(51.542919, 4.77356,4326)
SELECT @a.STDistance(@b)

关于.net - SQL Server 2008 R2 地理距离?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6386577/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com