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

조회 수: 13 (최근 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
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
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 CenterFile Exchange에서 Geometric Geodesy에 대해 자세히 알아보기

태그

제품


릴리스

R2022a

Community Treasure Hunt

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

Start Hunting!

Translated by