婷婷综合国产,91蜜桃婷婷狠狠久久综合9色 ,九九九九九精品,国产综合av

主頁 > 知識庫 > postgresql 計算兩點距離的2種方法小結(jié)

postgresql 計算兩點距離的2種方法小結(jié)

熱門標(biāo)簽:濟南外呼網(wǎng)絡(luò)電話線路 400電話申請客服 電話機器人怎么換人工座席 移動外呼系統(tǒng)模擬題 電銷機器人能補救房產(chǎn)中介嗎 地圖標(biāo)注要花多少錢 天津開發(fā)區(qū)地圖標(biāo)注app 廣州電銷機器人公司招聘 江蘇400電話辦理官方

postgresql計算兩點距離

下面兩種方法:

select 
ST_Distance(
 ST_SetSRID(ST_MakePoint(115.97166453999147,28.716493914230423),4326)::geography,
 ST_SetSRID(ST_MakePoint(106.00231199774656,29.719258550486572),4326)::geography
),
ST_Length(
 ST_MakeLine(
 ST_MakePoint(115.97166453999147,28.716493914230423),
 ST_MakePoint(106.00231199774656,29.719258550486572)
 )::geography
)

備注:

ST_GeomFromText('LINESTRING(115.97166453999147 28.716493914230423,106.00231199774656 29.719258550486572)')與
ST_MakeLine(
	ST_MakePoint(115.97166453999147,28.716493914230423),
	ST_MakePoint(106.00231199774656,29.719258550486572)
)等價
 
ST_GeomFromText('POINT(115.97166453999147 28.716493914230423)',4326)與
ST_SetSRID(ST_MakePoint(115.97166453999147,28.716493914230423),4326)等價
 
ST_SetSRID(ST_MakePoint(115.97166453999147,28.716493914230423),4326)::geography與
Geography(ST_SetSRID(ST_MakePoint(115.97166453999147,28.716493914230423),4326))、
ST_GeographyFromText('SRID=4326;POINT(115.97166453999147 28.716493914230423)')等價
(::geography是postgis中的轉(zhuǎn)換類型語法,把geometry轉(zhuǎn)成geography)

補充:postgresql計算兩點歐式距離(經(jīng)緯度地理位置)

我就廢話不多說了,大家還是直接看代碼吧~

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;

以上為個人經(jīng)驗,希望能給大家一個參考,也希望大家多多支持腳本之家。如有錯誤或未考慮完全的地方,望不吝賜教。

您可能感興趣的文章:
  • PostgreSQL 慢查詢SQL跟蹤操作
  • CentOS PostgreSQL 12 主從復(fù)制(主從切換)操作
  • PostgreSQL 查看表的主外鍵等約束關(guān)系詳解
  • PostgreSQL 修改視圖的操作
  • PostgreSQL 更新視圖腳本的注意事項說明
  • postgreSQL中的row_number() 與distinct用法說明
  • Postgresql 動態(tài)統(tǒng)計某一列的某一值出現(xiàn)的次數(shù)實例
  • 淺談pg_hint_plan定制執(zhí)行計劃

標(biāo)簽:榆林 杭州 辛集 溫州 濮陽 海西 昭通 寶雞

巨人網(wǎng)絡(luò)通訊聲明:本文標(biāo)題《postgresql 計算兩點距離的2種方法小結(jié)》,本文關(guān)鍵詞  postgresql,計算,兩點,距離,;如發(fā)現(xiàn)本文內(nèi)容存在版權(quán)問題,煩請?zhí)峁┫嚓P(guān)信息告之我們,我們將及時溝通與處理。本站內(nèi)容系統(tǒng)采集于網(wǎng)絡(luò),涉及言論、版權(quán)與本站無關(guān)。
  • 相關(guān)文章
  • 下面列出與本文章《postgresql 計算兩點距離的2種方法小結(jié)》相關(guān)的同類信息!
  • 本頁收集關(guān)于postgresql 計算兩點距離的2種方法小結(jié)的相關(guān)信息資訊供網(wǎng)民參考!
  • 推薦文章
    主站蜘蛛池模板: 安塞县| 民县| 江达县| 玛多县| 宜宾市| 即墨市| 连州市| 灌阳县| 乌兰浩特市| 乌海市| 来安县| 东兰县| 象山县| 郯城县| 太原市| 景泰县| 桓台县| 汝州市| 如皋市| 三穗县| 信宜市| 青铜峡市| 江都市| 夏河县| 穆棱市| 临桂县| 黔西| 治多县| 无锡市| 城步| 阿坝| 铅山县| 开远市| 东城区| 交口县| 米林县| 建阳市| 潜江市| 杭锦后旗| 焉耆| 沾化县|