Calculate Great Circle Distances Between Pairs of Points Using OSMnx module

Below are the code example by which we can understand how to Calculate Great Circle Distances Between pairs of points Using OSMnx distance module in Python:

Calculate Great Circle Distance

Let’s calculate the great circle distance between Thiruvananthapuram and New Delhi. The code as follows: code uses the OSMnx library to calculate the great circle distance (in meters) between two geographical coordinates: New Delhi (28.6139° N, 77.2090° E) and Thiruvananthapuram (8.50606° N, 76.96153° E), considering the Earth as a sphere with a radius of 6371009 meters.

Python3
import osmnx as ox
# coordinates
tvm_lat, tvm_lon = 8.50606, 76.96153
nwdelhi_lat, nwdelhi_lon = 28.6139, 77.2090

# great circle distance
ox.distance.great_circle(
    nwdelhi_lat, nwdelhi_lon, tvm_lat, tvm_lon,
    earth_radius=6371009)

Output:

2236043.023561823

The great circle distance between Thiruvananthapuram and New Delhi is 2236043.02 meters or 2236.04km.

Pass Array of Coordinates as Parameter

Let’s calculate the Great Circle Distance between Thiruvananthapuram – Mumbai and New Delhi – Thiruvananthapuram. Let’s look at the Python code. Below code uses the OSMnx library and NumPy to calculate the great circle distances (in meters) for an array of coordinate pairs. It computes the distances between Thiruvananthapuram (8.50606° N, 76.96153° E) and New Delhi (28.6139° N, 77.2090° E).

Python3
import osmnx as ox
import numpy as np

# coordinates
tvm_lat, tvm_lon = 8.50606, 76.96153
mum_lat, mum_lon = 19.0760, 72.8777
dlh_lat, dlh_lon = 28.6139, 77.2090

# set array of coordinates
from_lat = np.array([tvm_lat, dlh_lat])
from_lon = np.array([tvm_lon, dlh_lon])
to_lat = np.array([mum_lat, tvm_lat])
to_lon = np.array([mum_lon, tvm_lon])

# great circle distance for array of params
ox.distance.great_circle(
    from_lat, from_lon, to_lat, to_lon,
    earth_radius=6371009)

Output:

array([1255079.11904625, 2236043.02356182])

From the output, it’s clear that the Great Circle Distance between Thiruvananthapuram and Mumbai is 1255079.119 meters or 1255.079 Km and for New Delhi and Thiruvananthapuram it is 2236043.023 meters or 2236.043 Km.


Calculate Great Circle Distances Between Pairs of Points Using OSMnx Module

The Great Circle Distance evaluates the shortest distance between two points considering Earth as a sphere. It is an arc linking two points on a sphere. Here, we will see how to calculate great circle distances between pairs of points using the OSMnx distance module.

Similar Reads

Syntax of osmnx.distance.great_circle() Function

The vectorized function calculates the great-circle distance between two points’ coordinates or between arrays of points’ coordinates using the haversine formula....

Calculate Great Circle Distances Between Pairs of Points Using OSMnx module

Below are the code example by which we can understand how to Calculate Great Circle Distances Between pairs of points Using OSMnx distance module in Python:...