STDistance
的返回值以度为单位,但我需要里程。另外,想象一下这种计算不是针对2个变量,而是针对具有1000行的表中的几何列。什么是最快的解决方案? SQL Server 2012,2014,2016是否内置了什么内容??
--Geometry
DECLARE @Point2m geometry = geometry::STGeomFromText('POINT(-80.23 26.2)', 4326),
@Point3m geometry = geometry::STGeomFromText('POINT(-80.229999999515712 26.193699999712408)', 4326)
SELECT @Point2m.STDistance(@Point3m) /* degrees */
GO
--Geography, for comparison
DECLARE @Point2g geography = geography::STGeomFromText('POINT(-80.23 26.2)', 4326),
@Point3g geography = geography::STGeomFromText('POINT(-80.229999999515712 26.193699999712408)', 4326)
SELECT @Point2g.STDistance(@Point3g) / 1609.344 /*meters to miles*/
GO
答案 0 :(得分:0)
这可以用作SP的模板:
宣告@geostart地理 宣布@geoend GEOGRAPHY
SELECT @geostart = SELECT @geoend =
选择CAST(@ geostart.STDistance(@geoend)/1609.344 AS DEC(8,1))AS [里程数]
如果要计算多个行(table_a)到另一个表(table_b)中特定地理值(键列值= 100)的英里距离,可以使用以下内容:
选择 ,'miles'= CAST(table_a_geo.STDistance(table_b_geo)/1609.344 AS DEC(8,1)) FROM table_a JOIN table_b ON table_b_id = 100