通信人家园

 找回密码
 注册

只需一步,快速开始

短信验证,便捷登录

搜索

军衔等级:

  新兵

注册:2010-10-29
跳转到指定楼层
1#
发表于 2016-2-22 11:04:07 |只看该作者 |倒序浏览
ALTER   FUNCTION fnGetDistance7(@lon1 decimal(28, 15), @lat1 decimal(28, 15), @lon2 decimal(28, 15), @lat2 decimal(28, 15)) RETURNS decimal(28, 15)
  AS
BEGIN
  --距离(千米)
  DECLARE @a_2d decimal(28, 15),@e_2d decimal(28, 15),@h_2d Integer,@DEG_2_RAD decimal(28, 15),@RAD_2_DEG decimal(28, 15)  
  DECLARE @x_rads decimal(28, 15),@y_rads decimal(28, 15),@n_2ds decimal(28, 15),@x_2d decimal(28, 15),@y_2d decimal(28, 15),@z_2d decimal(28, 15),@x_radm decimal(28, 15),@y_radm decimal(28, 15),@n_2dm decimal(28, 15),@x_2d_mark decimal(28, 15),@y_2d_mark decimal(28, 15),@z_2d_mark decimal(28, 15)
  DECLARE @curdistance decimal(28, 15),@Distance decimal(28, 15)
  --DECLARE @ALL varchar(255)

  SET @a_2d = 6378.137
  SET @e_2d = 0.00669438
  SET @h_2d = 15
  SET @DEG_2_RAD = 0.01745329252
  SET @RAD_2_DEG = 57.2957795129

  
SET @x_rads = Abs(@lon1) * @DEG_2_RAD

SET @y_rads = Abs(@lat1) * @DEG_2_RAD



SET @n_2ds = @a_2d / Sqrt(1 - @e_2d * Sin(@y_rads) * Sin(@y_rads))



SET @x_2d = (@n_2ds + @h_2d) * Cos(@y_rads) * Cos(@x_rads)

SET @y_2d = (@n_2ds + @h_2d) * Cos(@y_rads) * Sin(@x_rads)

SET @z_2d = (@n_2ds * (1 - @e_2d) + @h_2d) * Sin(@y_rads)



SET @x_radm = Abs(@lon2) * @DEG_2_RAD

SET @y_radm = Abs(@lat2) * @DEG_2_RAD



SET @n_2dm = @a_2d / Sqrt(1 - @e_2d * Sin(@y_radm) * Sin(@y_radm))



SET @x_2d_mark = (@n_2dm + @h_2d) * Cos(@y_radm) * Cos(@x_radm)

SET @y_2d_mark = (@n_2dm + @h_2d) * Cos(@y_radm) * Sin(@x_radm)

SET @z_2d_mark = (@n_2dm * (1 - @e_2d) + @h_2d) * Sin(@y_radm)



SET @curdistance = (@x_2d_mark - @x_2d) * (@x_2d_mark - @x_2d) + (@y_2d_mark - @y_2d) * (@y_2d_mark - @y_2d) + (@z_2d_mark - @z_2d) * (@z_2d_mark - @z_2d)

SET @Distance = Sqrt(@curdistance)
  
--SET @ALL=CONVERT(varchar(255),@x_rads ) +'_'+CONVERT(varchar(255),@y_rads )+'_'+CONVERT(varchar(255),@n_2ds )+'_'+CONVERT(varchar(255),@x_2d )+'_'+CONVERT(varchar(255),@y_2d )+'_'+CONVERT(varchar(255),@z_2d )+'_'+CONVERT(varchar(255),@x_radm )+'_'+CONVERT(varchar(255),@y_radm )+'_'+CONVERT(varchar(255),@n_2dm )+'_'+CONVERT(varchar(255),@x_2d_mark )+'_'+CONVERT(varchar(255),@y_2d_mark )+'_'+CONVERT(varchar(255),@z_2d_mark )+'_'+CONVERT(varchar(255),@curdistance )+'_'+CONVERT(varchar(255),@Distance )

RETURN @Distance




END

--------------------------------
使用举例
select *,dbo.fnGetDistance7([经度], [纬度],[lon], [lat]) as ds from [ncgsm].[dbo].[4G工参],[ncgsm].[dbo].[2G工参] where dbo.fnGetDistance7([经度], [纬度],[lon], [lat])<2

举报本楼

您需要登录后才可以回帖 登录 | 注册 |

手机版|C114 ( 沪ICP备12002291号-1 )|联系我们 |网站地图  

GMT+8, 2024-11-26 19:27 , Processed in 0.228740 second(s), 15 queries , Gzip On.

Copyright © 1999-2023 C114 All Rights Reserved

Discuz Licensed

回顶部