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

24 次查看(过去 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 个评论

请先登录,再进行评论。

更多回答(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 个评论
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.

请先登录,再进行评论。

标签

产品


版本

R2022a

Community Treasure Hunt

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

Start Hunting!

Translated by