Determine an approximate route between two points on earth
Project description
scgraph
Supply chain graph package for Python
Documentation
Getting Started: https://connor-makowski.github.io/scgraph/ Low Level: https://connor-makowski.github.io/scgraph/core.html
Key Features
- Calculate the shortest path between two points on earth using a latitude / longitude pair
- Inputs:
- A latitude / longitude pair for the origin
- A latitude / longitude pair for the destination
- Calculation:
- Algorithms:
- Dijkstra's algorithm
- Modified to support sparse network data structures
- Possible future support for other algorithms
- Dijkstra's algorithm
- Distances:
- Uses the haversine formula to calculate the distance between two points on earth
- Algorithms:
- Returns:
path
:- A list of dictionaries (
latitude
andlongitude
) that make up the shortest path
- A list of dictionaries (
length
:- The distance in kilometers between the two points
- Inputs:
- Antimeridian support
- Arbitrary start and end points
- Arbitrary network data sets
Setup
Make sure you have Python 3.6.x (or higher) installed on your system. You can download it here.
Installation
pip install scgraph
Getting Started
Basic Usage
Get the shortest path between two points on earth using a latitude / longitude pair In this case, calculate the shortest maritime path between Shanghai, China and Savannah, Georgia, USA.
from scgraph import Graph
from scgraph.data import marnet_data
my_graph = Graph(data=marnet_data)
# Get the shortest path between
output = my_graph.get_shortest_path(
origin={"latitude": 31.23,"longitude": 121.47},
destination={"latitude": 32.08,"longitude": -81.09}
)
print('Length: ',output['length']) #=> Length: 19596.735
In the above example, the path
variable is a dictionary with two keys: length
and path
. The length
key contains the distance in kilometers between the two points. The path
key contains a list of dictionaries (containing latitude
and longitude
) that make up the shortest path between the two points.
To get the latitude / longitude pairs that make up the shortest path, as a list of lists, you could do something like the following:
from scgraph import Graph
from scgraph.data import marnet_data
my_graph = Graph(data=marnet_data)
# Get the shortest path between
output = my_graph.get_shortest_path(
origin={"latitude": 31.23,"longitude": 121.47},
destination={"latitude": 32.08,"longitude": -81.09}
)
print(str([[i['latitude'],i['longitude']] for i in output['path']]))
Included Data Sets
- marnet_data:
- What: A maritime network data set
- Use:
from scgraph.data import marnet_data
Attributions and Thanks
Inspired by searoute including the use of one of their datasets that has been modified to work properly with this package.
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.