Finding unique closest point corresponding to latitude and longitude vectors for a given point with shortest distance.

15 ビュー (過去 30 日間)
I have two large vectors for the pair of latitudes and longitudes (Lat, Lon). I want to find a unique single pair of latitude and longitude corresponding to the point ([lat_deg, lon_deg]) which has shortest distance.
I am using this:
P = ([lat_deg, lon_deg]);
PQ = [Lat, Lon];
[k,dist] = dsearchn(P,PQ);
But at the end of this I get the distances of all the points and vector k contains all ones. Please guide if this is the right function if yes how can I correct it? if not what is the right function.
Sample vectors are:
Lat Lon
39.2591200000000 -85.9394200000000
39.2591300000000 -85.9392000000000
39.2590800000000 -85.9406300000000
39.2593500000000 -85.9406200000000
39.1949800000000 -85.9633400000000
39.1954200000000 -85.9633500000000
39.1954200000000 -85.9633500000000
39.1963300000000 -85.9633600000000
39.1957400000000 -85.9678800000000
39.1959300000000 -85.9682400000000
P=39.2005981000000 -85.9045842000000

採用された回答

KALYAN ACHARJYA
KALYAN ACHARJYA 2022 年 10 月 25 日
#It can verify from plot too, pls modify as per requirments-
PQ=[39.2591200000000 -85.9394200000000
39.2591300000000 -85.9392000000000
39.2590800000000 -85.9406300000000
39.2593500000000 -85.9406200000000
39.1949800000000 -85.9633400000000
39.1954200000000 -85.9633500000000
39.1954200000000 -85.9633500000000]
lat=PQ(:,1);
long=PQ(:,2);
P=[39,-85];
[k,dist]=dsearchn(P,PQ);
plot(lat,long,'rx',39,-85,'bo','linewidth',2);
idx=find(min(dist)==dist);
disp('Minimum distance Point is ');
PQ(idx,:)
Hope it Helps!
  5 件のコメント
Muhammad Qaisar Fahim
Muhammad Qaisar Fahim 2022 年 10 月 26 日
@Bruno Luong Thanks for pointing out. Then what would be the right choice to use ?
KALYAN ACHARJYA
KALYAN ACHARJYA 2022 年 10 月 27 日
Yes, you can replace the D search function with actual Lat Long Distance measure procedure, rest are same, as mentioned

サインインしてコメントする。

その他の回答 (1 件)

Bruno Luong
Bruno Luong 2022 年 10 月 27 日
編集済み: Bruno Luong 2022 年 10 月 27 日
Use dsearchn on lon/lat is wrong.
The right procesure is
convert lat/lon to 3D coordinates (for both list P and PQ
use dnsearch on 3D coordinates
[k] = dsearchn(P3D,PQ3D)
Then compute the geodesic distance for all points PQ to P(k) by this formula
Take the min of the list of the distances.
  3 件のコメント
Muhammad Qaisar Fahim
Muhammad Qaisar Fahim 2022 年 10 月 27 日
Also my coordinates are already in WGS84 coordinates
Bruno Luong
Bruno Luong 2022 年 10 月 27 日
The wikipedia gives the formula of geodesic distance between
P1 with longitude/latitude in radian Lambda1, Phi1
P2 with longitude/latitude Lambda2, Phi2
as
d = r*dsigma
dsigma = acos(sin(Phi1)*sin(Phi2) + cos(Phi1)*cos(Phi2)*cos(Lambda1-Lambda2)
where r the radius of the earth, assumin a sphere approximation.

サインインしてコメントする。

カテゴリ

Help Center および File ExchangeGeometric Geodesy についてさらに検索

タグ

製品


リリース

R2022a

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by