Select to view content in your preferred language

geopy.distance vincenty - pairs of coordinates

4416
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
1 Solution

Accepted Solutions
DanPatterson_Retired
MVP Emeritus

I use python 3... I forget some are still on legacy python

comment out line 50 and remove the word 'dedent' in line 163

And besides... you just don't 'run' it unless you want the demo to run.  the def is the main part, but don't forget the imports

View solution in original post

15 Replies
DanPatterson_Retired
MVP Emeritus

Use this Vincenty then.... for comparison

0 Kudos
Nicole_Ueberschär
Esri Regular Contributor

Hi Dan, the python file is empty 😞

0 Kudos
DanPatterson_Retired
MVP Emeritus

strange, it used to be there because people have used it.. I uploaded again, let me know

Nicole_Ueberschär
Esri Regular Contributor

Thanks Dan! Unfortunately now it says it can't import the textwrapper functions. Will have to look at it at a later stage again.

0 Kudos
DanPatterson_Retired
MVP Emeritus

I use python 3... I forget some are still on legacy python

comment out line 50 and remove the word 'dedent' in line 163

And besides... you just don't 'run' it unless you want the demo to run.  the def is the main part, but don't forget the imports

Nicole_Ueberschär
Esri Regular Contributor

Thank you! I will give it another try. 

Of course you are right, that I don't run the script by itself, I imported it to my script and run it from there...

0 Kudos
DanPatterson_Retired
MVP Emeritus

closed?

0 Kudos
XanderBakker
Esri Esteemed Contributor

Hi Dan Patterson ,

I just did a small test with your script and obtained this result:

:--------------------------------------------------------:
:Vincenty inverse...
:Longitude, Latitude
:From: (  6.23927000, -75.60019300)
:To:   (  4.72356700, -74.07436300)
:Distance: 175953.991 m
:Bearings...
:  Initial   344.70 deg
:  Final     346.16 deg
:  Iterations taken.... 2
:--------------------------------------------------------:

When I run this script using the distance and angle to in arcpy:

def main():
    import arcpy
    coords = [[6.239270, -75.600193], [4.723567, -74.074363]]
    sr = arcpy.SpatialReference(4326)

    pntg1 = arcpy.PointGeometry(arcpy.Point(*coords[0][::-1]), sr)
    pntg2 = arcpy.PointGeometry(arcpy.Point(*coords[1][::-1]), sr)

    methods = ['PLANAR', 'GEODESIC', 'GREAT_ELLIPTIC',
               'LOXODROME', 'PLANAR', 'PRESERVE_SHAPE']

    for method in methods:
        print "{0}\t{1}\t{2}".format('%14s' % method,
                                     *pntg1.angleAndDistanceTo(pntg2, method))

if __name__ == '__main__':
    main()

... it gives me this:

        PLANAR     134.674409847     238078.891905
      GEODESIC     134.674454363     238078.891905
GREAT_ELLIPTIC     134.674961722     238078.891908
     LOXODROME     134.750719983     238078.956191
        PLANAR     134.674409847     238078.891905
PRESERVE_SHAPE     134.674454363     238078.891905‍‍‍‍‍‍

Any idea why the distance is so different?

0 Kudos
XanderBakker
Esri Esteemed Contributor

And when using geopy:

def main():
    from geopy.distance import vincenty, great_circle
    medellin = (6.239270, -75.600193)
    bogota = (4.723567, -74.074363)
    print(vincenty(medellin, bogota).meters)
    print(great_circle(medellin, bogota).meters)

if __name__ == '__main__':
    main()

... I get this result:

238078.891889
238660.799202

Showing that vincenty is very close to what arcpy calculated.

0 Kudos