3

I want to calculate the distance between two points on surface of earth in meteres

I have tried with both basemap and cartopy but both result in different numbers.

Basemap:

import mpl_toolkits.basemap.pyproj as pyproj

k = pyproj.Geod(ellps="WGS84")
distance = k.inv(c0[1], c0[0], c1[1], c1[0])[-1]/1000.

Cartopy:

import cartopy.geodesic as gd

k = gd.Geodesic() // defaults to WGS84
distance = k.inverse(c0, c1).base[0,0]/1000

where both coord0 and coord1 are numpy arrays of size 2 having lat and lon of a coordinate.

c0 = numpy.array([77.343750, 22.593726])
c1 = numpy.array([86.945801, 23.684774])

Cartopy Output: 990.6094719605074

Basemap Output: 1072.3456344712142

Anveshan Lal
  • 115
  • 9

1 Answers1

2

With Basemap, you must use proper order of (long, lat):

distance = k.inv(c0[0], c0[1], c1[0], c1[1])[-1]/1000.

and the result will agree with Cartopy's, which is the correct result:

990.6094719605074
swatchai
  • 17,400
  • 3
  • 39
  • 58
  • Thank you so much I didn't noticed that. I am new to stackoverflow so I don't know if its appropriate but can you tell me how to replicate the ```npts``` from Geod class of basemap in Cartopy? Or it would be more ideal to ask it in a seperate question? – Anveshan Lal May 31 '19 at 06:41
  • @AnveshanLal You better ask as a new question. More people will see and help. – swatchai May 31 '19 at 07:05