Calculate distance between 2 points in Python

Hi,

I am wondering if there is a function or formulae that I can use to calculate point to point distance in Python that will have the same result shown on OneMap.

Thank you.

Hi infinititan,

You can try using this function
https://docs.scipy.org/doc/scipy/reference/spatial.distance.html

Thanks.

1 Like

Hi jinhong,

Thanks for the suggestion.

I tried using scipy’s pdist as follow with X being the Long/Lat of both points. The distance result is not similar to OneMap’s result. One map is about 2KM and my python result is 0.000315796. Is there some conversion that I need to do?

Y = pdist(X, ‘euclidean’)

Thank you.

Hi infinititan,

we are using Haversine formula.

But your formulae is using Euclidean distance.

You can refer to https://pypi.org/project/geopy/

Hope it can help.

Thanks.