经纬度转换 sql 自定义函数

数值转度分秒

Create function [dbo].[ConvertDigitalToDegrees](@digitaldegree numeric(18, 2))
returns varchar(50)
as 
begin
declare @num numeric(18, 2)=60
declare @result int=@digitaldegree
declare @tmp numeric(18, 2)=(@digitaldegree-@result)*@num
declare @minute int=@tmp
declare @second numeric(18, 2)=(@tmp-@minute)*@num
declare  @degrees  varchar(50)= ‘‘+cast(@result as  varchar) +°+cast(@minute as varchar)++ cast(@second  as varchar)+
  return @degrees
end

度分秒转数值

Create  function  [dbo].[DegreesToDigital](@degrees varchar(20))
returns  varchar(20)
as
begin
declare @num numeric(18,2)=60
declare @digitalDegree decimal(18,2)=0.0
declare @d int=charindex(°,@degrees)
if(@d<0)
begin
return @digitalDegree
end
declare @degree varchar(20)=left(@degrees,@d-1)
set @digitalDegree+=cast(@degree as decimal(18,2))
declare @m int=charindex(,@degrees)
if(@m<0)
begin
return @digitalDegree
end
declare @minute varchar(20)=substring(@degrees,@d+1,@m-@d-1)
set @digitalDegree+=(cast(@minute as decimal(18,2))/@num)
 declare @s int=charindex(,@degrees)
 if(@s<0)
 begin
 return @digitalDegree
 end
 declare @second varchar(20)=substring(@degrees,@m+1,@s-@m-1)
 set @digitalDegree+=(cast(@second as decimal(18,2))/(@num*@num))
 return @digitalDegree
end

 

经纬度转换 sql 自定义函数

上一篇:mysql查看常用参数Linux命令


下一篇:ubuntu部署TimescaleDB