-1

I have a problem with pdist function in python. I have coordinates of points that I want to find the distance between them but it does not consider them as coordinates and find distance between two points rather than coordinate (it consider coordinates as decimal numbers rather than coordinates). I could not find anything so far of how to fix this problem. Any help is appreciated. In other words, should I do any transformation on my coordinates? Here is a sample code:

    p1=[39.1653, -86.5264]
    p2=[39.704166670000049, -86.399444439999826]
    X=[p1[0],p2[0]]
    Y=[p1[1],p2[1]]
    spdist.pdist(zip(X,Y), 'euclidean')

The result it gives me is 0.55361991 miles but when I put the coordinates in google map, it give me 42 miles.

Thanks

Fairy
  • 379
  • 1
  • 5
  • 17

1 Answers1

0

You can calculate distance from decimal coordinates if you know the formula that's involved. There's one for rectangular coordinate systems; another for spherical coordinate systems.

If the Python built in function takes in point parameters, why not wrap your decimal values as points before calling the function?

Community
  • 1
  • 1
duffymo
  • 305,152
  • 44
  • 369
  • 561
  • Thank you for the comment but I dont exactly get what you meant. I added some code to the question. Could you please dive me some hint on that? – Fairy Dec 06 '16 at 14:50
  • Those look like lat/lon values. Those aren't calculated in a Euclidean space; those are in a Spherical Earth coordinate system with a radius of 3,959 miles. – duffymo Dec 06 '16 at 14:52
  • In that case, should I do any transformation so I can use euclidean distance in python? – Fairy Dec 06 '16 at 14:58
  • No, rectangular and spherical coordinate systems are entirely different. You should see if that function takes a 'spherical' argument and perhaps a radius. You should dig into the docs for that function to understand better what it's doing rather than thrashing around. – duffymo Dec 06 '16 at 15:04
  • I undrestand. Thank you – Fairy Dec 06 '16 at 15:06