scipy.spatial.distance: cityblock between lat/long points: What is the unit of the results?

52 views Asked by At
import pandas as pd
from scipy.spatial import distance
from scipy.spatial.distance import cityblock

# Sample dataset with latitude and longitude
patient = {
    'Patient': ['pt1'],
    'lat': [34.0522],
    'lon': [-118.2437]
}

patient = pd.DataFrame(patient)

hospital = {
    'hospital': ['h1'],
    'LATITUDE': [35.0522],
    'LONGITUDE': [-133.2437]
}

hospital = pd.DataFrame(hospital)

distance = cityblock((patient['lat'], patient['lon']), (hospital['LATITUDE'], hospital['LONGITUDE']))

I am calculating distance between latitude-longitude points and manhattan distance (cityblock).

But what is the unit of measurement in the results?

Edited to add a reproducible example.

2

There are 2 answers

1
Nick ODell On

There's no sensible unit you could attach to the result of this calculation.

An analogy: imagine you are measuring the perimeter of your rectangular house. On two of the sides, you measure it as 20 feet. On two other sides, you measure it as 10 meters. You add this up: 20 + 20 + 10 + 10 = 60. Now, which unit do you use for the result, feet or meters? The answer is that neither is correct: this is adding together units of distance of different length.

Similarly, a degree of latitude and longitude span different distances. A degree of latitude spans approximately 111 km. (In fact, that is how the meter was originally defined.) A degree of longitude is more complicated. At the equator, it is the same as latitude. As you move away from the equator, a degree of longitude spans less distance. More specifically, a degree of longitude spans 111 km * cos(latitude).

Imagine you have 2 patients, each a kilometer away from the hospital, one who lives exactly north of the hospital, and one who lives exactly east of the hospital. Assuming the hospital is at latitude 34 degrees, if you measure distance in degrees, this means that you will compute that the patient who is north is 18% closer than the patient who is east.

If you want a measure of distance between two lat/lon pairs which has a physical meaning, I would suggest you compute the haversine distance instead. You could use this package or this sklearn function to do this.

0
gboffi On

what is the unit of measurement in the results?

The results are wrong and their units are, to say the least, undefined.

To have a sensible results, you have to place your points on a map (search map projections, very good stuff also on SO).

As a final remark, not knowing if your example data comes from your real data, computing Manhattan distances when the scale is 100's of km seems pointless, and in general it's pointless even at urban scale, as M. distances change on a rotation of the reference system.