Ms SQL geography.STDistance returns wrong distance

白昼怎懂夜的黑 提交于 2020-01-15 12:04:18

问题


I'm trying to query any locations within a specified distance from another location. The query is not the problem, but the distance returned by geography.STDistance is.

It seems STDistance makes fairly accurate calculations on locations close to the equator, but I need this to work with locations in the nordic countries. Norway, Sweden, Finland and so on...

According to my calculations, made on locations in northern Sweden, the distance is wrong by a factor of around 2.38?! Expected result is 1070 meters and returned distance is 2537,28850694302 meters

My query looks like this:

DECLARE @g geography = geography::STGeomFromText('POINT(65.580254 22.179428)', 4326)

SELECT name, [pos].STSrid as srdi, [pos].STDistance(@g) as d
  FROM [GPSCHAT].[dbo].[USERS]

and the "other location" has coordinates (65,578541 22,202286) (stored with SRID 4326)

I'm guessing this has to do with the distance from the equator (close to the polar circle), but there has to be a way to calculate this more accurately based on the Latitude or am i wrong?


回答1:


It looks like you're creating your point using 'X, Y'.
When creating a point from text, use 'Y, X' instead.

Check out this MSDN Article for some more info.




回答2:


Why don't you make use of another spatial reference identifier which fits better the earth curvature around your position. SRID 4326 might not been measured as accurate as other local referential systems



来源:https://stackoverflow.com/questions/6493188/ms-sql-geography-stdistance-returns-wrong-distance

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!