ALTERFUNCTION 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
掃碼關注5G通信官方公眾號,免費領取以下5G精品資料
1、回復“YD5GAI”免費領取《中國移動:5G網絡AI應用典型場景技術解決方案白皮書》
2、回復“5G6G”免費領取《5G_6G毫米波測試技術白皮書-2022_03-21》
3、回復“YD6G”免費領取《中國移動:6G至簡無線接入網白皮書》
4、回復“LTBPS”免費領取《《中國聯(lián)通5G終端白皮書》》
5、回復“ZGDX”免費領取《中國電信5G NTN技術白皮書》
6、回復“TXSB”免費領取《通信設備安裝工程施工工藝圖解》
7、回復“YDSL”免費領取《中國移動算力并網白皮書》
8、回復“5GX3”免費領取《 R16 23501-g60 5G的系統(tǒng)架構1》
|