geopy.distance vincenty - pairs of coordinates

3873
15
Jump to solution
11-02-2017 05:07 AM
Nicole_Ueberschär
Esri Regular Contributor

Hi folks, 

I managed to calculate the distance between two points (from two different feature classes) using the vincenty module from geopy.distance. 

For quite some time I struggled to find out why I got wrong distances. (even to realize it took me some time)

In the end I figured that the vincenty module requires the coordinates in Latitude/Longitude while the coordinates as they are stored in the feature class shape@xy are stored as Longitude/Langitude. 

Can someone confirm this? It doesn't make any sense to me why the vincenty module should require the coordinates the "wrong way" but I only get correct measures when using the coordinates switched to Latitude/Longitude...

0 Kudos
15 Replies
DanPatterson_Retired
MVP Emeritus

longitude first then latitude... that is the problem with geowhater that I noted before and proposed a simple solution if anyone wanted to edit their code

  • coords = [45, -75]
    coords[::-1]
    Out[5]: [-75, 45]
XanderBakker
Esri Esteemed Contributor

You are (as always) completely right. I assumed that the code would use the coordinates in lat, lon order (as the OP mentioned), but it uses them the "right way" as X , Y and I provided Y, X. Switching the order did the trick and returns the expected values.

:--------------------------------------------------------:
:Vincenty inverse...
:Longitude, Latitude
:From: (-75.60019300, 6.23927000)
:To: (-74.07436300, 4.72356700)
:Distance: 238078.892 m
:Bearings...
: Initial 134.67 deg
: Final 134.82 deg
: Iterations taken.... 4
:--------------------------------------------------------:

DanPatterson_Retired
MVP Emeritus

You had already mentioned this in one of you previous comments as well...

The X property of a point always corresponds to Longitude and the Y always to Latitude

I belong to the Long/Lat... aka... X/Y, column/row... school 

XanderBakker
Esri Esteemed Contributor

Don't get met wrong, I really feel weird if I have o specify something like Y, X, but I was focused on the way vincenty and geopy works with lat, long and therefore specified it incorrectly in your code, not noticing the correct example you provided that was not including point in the South Pole.. Anyway thanks for pointing out my mistake!

XanderBakker
Esri Esteemed Contributor

The X property of a point always corresponds to Longitude and the Y always to Latitude. As far as I can see geopy 1.11.0 : Python Package Index seems to use a tuple of coordinates where the first element is the Latitude and the second is Longitude). So the answer would be yes...

DanPatterson_Retired
MVP Emeritus

of course, you can edit their code and swap the coordinates yourself

coords = [45, -75]
coords[::-1]
Out[5]: [-75, 45]