java点到原点距离_java-从经纬度坐标到欧氏距离(EuclideanDistance)完整代码
一、認識
來自網絡的圖片:
方案一:(來自網絡)
postgresql計算兩點歐式距離(經緯度地理位置)
create or replace function getdistance
(
lon1 numeric,
lat1 numeric,
lon2 numeric,
lat2 numeric
)
returns int
as
$body$
declare
v_distance numeric;
v_earth_radius numeric;
radLat1 numeric;
radLat2 numeric;
v_radlatdiff numeric;
v_radlngdiff numeric;
begin
--地球半徑
v_earth_radius:=6378137;
radLat1 := lat1 * pi()/180.0;
radLat2 := lat2 * pi()/180.0;
v_radlatdiff := radLat1 - radLat2;
v_radlngdiff := lon1 * pi()/180.0 - lon2 * pi()/180.0;
v_distance := 2 * asin(sqrt(power(sin(v_radlatdiff / 2), 2) + cos(radLat1) * cos(radLat2) * power(sin(v_radlngdiff/2),2)));
v_distance := round(v_distance * v_earth_radius);
return v_distance;
end;
$body$
language 'plpgsql' volatile;
create or replace function getdistance
(
i_lngbegin real,
i_latbegin real,
i_lngend real,
i_latend real
)
returns float
as
$body$
/*
*
* select getdistance_bygispoint(116.281524,39.957202,117.648673,38.42584) as distance;
* */
declare
v_distance real;
v_earth_radius real;
v_radlatbegin real;
v_radlatend real;
v_radlatdiff real;
v_radlngdiff real;
begin
--地球半徑
v_earth_radius:=6378.137;
v_radlatbegin := i_latbegin * pi()/180.0;
v_radlatend := i_latend * pi()/180.0;
v_radlatdiff := v_radlatbegin - v_radlatend;
v_radlngdiff := i_lngbegin * pi()/180.0 - i_lngend * pi()/180.0;
v_distance := 2 * asin(sqrt(power(sin(v_radlatdiff / 2), 2) + cos(v_radlatbegin) * cos(v_radlatend) * power(sin(v_radlngdiff/2),2)));
v_distance := v_distance * v_earth_radius*1000;
return v_distance;
end;
$body$
language 'plpgsql' volatile;
方案二:
總結
以上是生活随笔為你收集整理的java点到原点距离_java-从经纬度坐标到欧氏距离(EuclideanDistance)完整代码的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: java比较三个数的编程_Java小程序
- 下一篇: java内存池实现_Netty精粹之轻量