How to calculate the L2 (Euclidean) and L1 (cityblock, or we say Manhattan distance) distance based on longitude and latitude?

13 Ansichten (letzte 30 Tage)

I have several coordinate of points with longitude and latitude. For example, as follows:
22.7397142000000 113.488351100000
22.7669794000000 113.509290500000
22.7704230000000 113.507311200000
22.7669970000000 113.508321300000
22.7670235000000 113.508306300000
22.7696037000000 113.511283800000
22.7711551000000 113.508804100000
22.7711704000000 113.508833800000
22.7694847000000 113.512802400000
22.7693585000000 113.513163800000
22.7679902000000 113.518024500000
22.7691143000000 113.520290400000
22.7690086000000 113.520259300000
22.7689764000000 113.520256300000
22.7690396000000 113.520267700000
22.7692776000000 113.518461600000
22.7692416000000 113.518455000000
22.7684318000000 113.518207300000
22.7703652000000 113.514779800000
22.7708152000000 113.511255300000
22.7703001000000 113.515150400000
22.7712174000000 113.516411500000
22.7692346000000 113.516134300000
22.7715692000000 113.511309900000
22.7727208000000 113.510230300000
22.7727138000000 113.510273300000
22.7733021000000 113.508423100000
22.7729565000000 113.508392900000
22.7681272000000 113.515703800000
22.7715343000000 113.512768200000
22.7746171000000 113.508364000000
I want to calculate the L2 and L1 distance between each of them.
Q1: For L2, I use 'distance' in mapping toolbox, and deg2km to convert the value to km, I'm NOT sure whether it makes sense, or is there any other ways?
Q2: For L1, no idea if there is any command in MATLAB to do this step by step, waiting for guide and codes.

Akzeptierte Antwort

Bjorn Gustavsson
Bjorn Gustavsson am 20 Jun. 2022
Bearbeitet: Bjorn Gustavsson am 20 Jun. 2022
It seems to me that there is no obvious good definition of a Manhattan-distance on a spherical surface (even less so on a geoid), since you wouldn't get the same distance if you take the North-first-then-East distances and the East-first-then-North distances. Take for example the points [0,0] and [89,89] as an illustrating example. So to get some robustness into this you better take the average of the two:
function l1_ll = distManhattanLatLong(pos1,pos2)
posNf = [pos2(1),pos1(2)];
posEf = [pos1(1),pos2(2)];
lEf = deg2km(distance(pos1(1),pos1(2),posEf(1),posEf(2))) + ...
deg2km(distance(posEf(1),posEf(2),pos2(1),pos2(2)));
lNf = deg2km(distance(pos1(1),pos1(2),posNf(1),posNf(2))) + ...
deg2km(distance(posNf(1),posNf(2),pos2(1),pos2(2)));
l1_ll = (lEf+lNf)/2;
end
HTH
  6 Kommentare

Melden Sie sich an, um zu kommentieren.

Weitere Antworten (0)

Kategorien

Mehr zu Graphics Performance finden Sie in Help Center und File Exchange

Tags

Community Treasure Hunt

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

Start Hunting!

Translated by