searoute
A python package to calculate the shortest sea route between two points on Earth.
Science Score: 44.0%
This score indicates how likely this project is to be science-related based on various indicators:
-
✓CITATION.cff file
Found CITATION.cff file -
✓codemeta.json file
Found codemeta.json file -
✓.zenodo.json file
Found .zenodo.json file -
○DOI references
-
○Academic publication links
-
○Committers with academic emails
-
○Institutional organization owner
-
○JOSS paper metadata
-
○Scientific vocabulary similarity
Low similarity (10.8%) to scientific vocabulary
Keywords
Repository
A python package to calculate the shortest sea route between two points on Earth.
Basic Info
Statistics
- Stars: 98
- Watchers: 3
- Forks: 20
- Open Issues: 9
- Releases: 13
Topics
Metadata Files
README.md
Searoute py
A python package for generating the shortest sea route between two points on Earth.
If points are on land, the function will attempt to find the nearest point on the sea and calculate the route from there.
Not for routing purposes! This library was developed to generate realistic-looking sea routes for visualizations of maritime routes, not for mariners to route their ships.

Installation
~~~bash pip install searoute ~~~
Usage
~~~py import searoute as sr
Define origin and destination points:
origin = [0.3515625, 50.064191736659104]
destination = [117.42187500000001, 39.36827914916014]
route = sr.searoute(origin, destination)
> Returns a GeoJSON LineString Feature
show route distance with unit
print("{:.1f} {}".format(route.properties['length'], route.properties['units']))
Optionally, define the units for the length calculation included in the properties object.
Defaults to km, can be can be 'm' = meters 'mi = miles 'ft' = feet 'in' = inches 'deg' = degrees
'cen' = centimeters 'rad' = radians 'naut' = nautical 'yd' = yards
routeMiles = sr.searoute(origin, destination, units="mi") ~~~
Bring your network :
```py
using version >= 1.2.0
nodes representing (1,2) of lon = 1, lat = 2
required : 'x' for lon, 'y' for lat ; optional 'tt' for terminals (boolean or None)
my_nodes = { (1, 2): {'x': 1, 'y': 2}, (2, 2): {'x': 2, 'y': 2} }
(1,2) -> (2,2) with weight, representing the distance, other attributes can be added
recognized attributes are : weight (distance), passage (name of the passage to be restricted by restrictions)
Note: Ensure that both directions of the edge are included. If (u, v) is added, (v, u) should also be included to account for bidirectional relationships.
myedges = { (1, 2): { (2, 2): {"weight": 10, "otherattr": "somevalue u->v"} } (2, 2): { (1, 2): {"weight": 10, "otherattr": "some_value v->u"} } }
Marnet
myM = sr.fromnodesedgesset(sr.Marnet(), mynodes, my_edges)
Ports
myP = sr.fromnodesedgesset(sr.Ports(), mynodes, None)
get shortest with your ports
routewithmyports = sr.searoute(origin, destination, P = myP, includeports=True)
get shortest with your ports
routewithmy_ntw = sr.searoute(origin, destination, P = myP, M = myM )
```
Nodes and Edges
Nodes
A node (or vertex) is a fundamental unit of which the graphs Ports and Marnet are formed.
In searoute, a node is represented by it's id as a tuple of lon,lat, and it's attributes:
- x : float ; required
- y : float ; required
- t : bool ; optional. default is False, will be used for filtering ports with terminals.
py
{
(lon:float, lat:float): {'x': lon:float, 'y': lat:float, *args:any},
...
}
Edges
An edge is a line or connection between a note and an other. This connection can be represented by a set of nodeid->nodeid with it's attributes:
- weight : float ; required. Can be distance, cost etc... if not set will by default calculate the distance between nodes using Haversine formula.
- passage : str ; optional. Can be one of Passage (searoute.classes.passages.Passage). If not not set, no restriction will be applied. If set make sure to update Marnet().restrictions = [...] with your list of passages to avoid.
py
{
(lon:float, lat:float)->node_id: {
(lon:float, lat:float)->node_id: {
"weight": distance:float,
*args: any}
},
...
}
Example with more parameters :
~~~py
Using all parameters, wil include ports as well
route = sr.searoute(origin, destination, appendorigdest=True, restrictions=['northwest'], includeports=True, portparams={'onlyterminals':True, 'countrypol': 'FR', 'countrypod' :'CN'}) ~~~ returns : ~~~json { "geometry": { "coordinates": [], "type": "LineString" }, "properties": { "durationhours": 461.88474412693756, "length": 20529.85310695412, "portorigin": { "cty": "France", "name": "Le Havre", "port": "FRLEH", "t": 1, "x": 0.107054, "y": 49.485998 }, "portdest": { "cty": "China", "name": "Tianjin", "port": "CNTSN", "t": 1, "x": 117.744852, "y": 38.986802 }, "units": "km" }, "type": "Feature" } ~~~
Preferred Ports
It's possible to select referred ports which can be configured with one or a list of AreaFeature:
Start by creating/referencing preferred ports using PortProps object which should contain a port_id, share (could be any positive number) and props corresponding to attributes of a port.
```py
your preferred ports
portone = PortProps('MYPORTID', 2, {'x':1, 'y':2})
porttwo = PortProps('USNYC', 1)
Initiate a `AreaFeature` with its coords and a name, as well as `list` of `preferred_ports` (could be a `list`, `str`, or `PortProps`)
py
initiate an AreaFeature
areaone = AreaFeature(coordinates=[[[0,0], [0,10],[0,20], [20, 20], [0, 0]]], name= 'SpecialName', preferredports=[portone, port_two])
create other AreaFeature
area_two = AreaFeature(...) ``` Note that the smallest AreaFeature which contains the point will be selected.
Finally, call the function which will return a tuple of 3 values, or 4 values when include_area_name is set to True:
```py
myPorts is the instance of Port, by default is sr.P
origin = (11, 12) prefports = myPorts.getpreferredports(*origin, AreaFeature.create([areaone, areatwo]), top=2, includearea_name = True) ```
Usage in main function
py
areas = AreaFeature.create([area_one, area_two])
sr.searoute(..., include_ports = True, port_params = {'ports_in_areas': areas})
Parameters
origin
Mandatory. A tuple or array of 2 floats representing longitude and latitude i.e : ({lon}, {lat})
destination
Mandatory. A tuple or array of 2 floats representing longitude and latitude i.e : ({lon}, {lat})
units
Optional. Default to km = kilometers, can be m = meters mi = miles ft = feets in = inches deg = degrees cen = centimeters rad = radians naut = nauticals yd = yards
speed_knot
Optional. Speed of the boat, default 24 knots
append_orig_dest
Optional. If the origin and destination should be appended to the LineString, default is False
restrictions
Optional. List of passages to be restricted during calculations.
Possible values : babalmandab, bosporus, gibraltar, suez, panama, ormuz, northwest, malacca, sunda, chili, south_africa;
default is ['northwest']
include_ports
Optional. If the port of load and discharge should be included, default is False
port_params
Optional. If include_ports is True then you can set port configuration for advanced filtering :
- only_terminals to include only terminal ports, default False
- country_pol country iso code (2 letters) for closest port of load, default None. When not set or not found, closest port is based on geography.
- country_pod country iso code (2 letters) for closest port of discharge, default None. When not set or not found, closest port is based on geography.
- country_restricted to filter out ports that have registered an argument key to_cty(a list) which indicates an existing route to the country same as in country_pod; default False
- ports_in_areas : a FeatureCollection containing areas with preferred ports, created of AreaFeature, use AreaFeature.create([...]). The previous configurations will be ignored.
If there are many ports then the result will be a list of GeoJson Features, instead of an object of GeoJson Feature.
Preferred ports with share = 0 will be ignored.
return_passages
Optional. to return traversed passages, default is False
default is {}
Returns
GeoJson Feature or list[GeoJson Feature] if many routes configured in port_params.
Credits
- NetworkX, a Python package for the creation, manipulation, and study of the structure, dynamics, and functions of complex networks.
- GeoJson, a python package for GeoJSON
- turfpy, a Python library for performing geo-spatial data analysis which reimplements turf.js. (up to version
searoute 1.1.0) - OSMnx, for geo-spacial networks. (up to version
searoute 1.1.0) - Eurostat's Searoute Java library
Owner
- Name: Gent
- Login: genthalili
- Kind: user
- Location: Basel, Switzerland
- Company: IKEA
- Website: https://www.inter.ikea.com
- Repositories: 29
- Profile: https://github.com/genthalili
Data Scientist at IKEA
Citation (CITATION.cff)
cff-version: 1.2.0
message: "If you use this software, please cite it as below."
title: "searoute-py"
authors:
- family-names: "Halili"
given-names: "Gent"
affiliation: "searoute-py author"
version: "1.4.3"
date-released: "2025-02-22"
repository-code: "https://github.com/genthalili/searoute-py"
license: "Apache-2.0"
license-url: "https://github.com/genthalili/searoute-py/blob/main/LICENCE.txt"
description: "A python package to calculate the shortest sea route between two points on Earth."
keywords:
- map
- distance
- maritime
- sea route
- shortest path
- maritime navigation
- transport optimization
GitHub Events
Total
- Create event: 1
- Release event: 1
- Issues event: 12
- Watch event: 20
- Issue comment event: 11
- Push event: 3
- Fork event: 5
Last Year
- Create event: 1
- Release event: 1
- Issues event: 12
- Watch event: 20
- Issue comment event: 11
- Push event: 3
- Fork event: 5
Committers
Last synced: about 2 years ago
Top Committers
| Name | Commits | |
|---|---|---|
| Gent Halili | g****i@i****m | 14 |
| genthalili | h****t@g****m | 12 |
| Shashank Deshpande | s****8@g****m | 1 |
| Gent | g****i | 1 |
Committer Domains (Top 20 + Academic)
Issues and Pull Requests
Last synced: 6 months ago
All Time
- Total issues: 46
- Total pull requests: 3
- Average time to close issues: 3 months
- Average time to close pull requests: about 1 month
- Total issue authors: 36
- Total pull request authors: 3
- Average comments per issue: 2.61
- Average comments per pull request: 2.67
- Merged pull requests: 2
- Bot issues: 0
- Bot pull requests: 0
Past Year
- Issues: 7
- Pull requests: 0
- Average time to close issues: 2 months
- Average time to close pull requests: N/A
- Issue authors: 7
- Pull request authors: 0
- Average comments per issue: 0.86
- Average comments per pull request: 0
- Merged pull requests: 0
- Bot issues: 0
- Bot pull requests: 0
Top Authors
Issue Authors
- genthalili (6)
- siggemannen (3)
- bryantek (2)
- jimrobo (2)
- arthys974 (1)
- jutogashi (1)
- DeepeshKalura (1)
- LeoPaoli (1)
- LinYouMin (1)
- bmm23 (1)
- emuir-synmax (1)
- DantasB (1)
- juanjops (1)
- Niloufar375 (1)
- vinisalazar (1)
Pull Request Authors
- abajorat (2)
- this-josh (2)
- shashankdeshpande (1)
Top Labels
Issue Labels
Pull Request Labels
Packages
- Total packages: 1
-
Total downloads:
- pypi 14,099 last-month
- Total dependent packages: 0
- Total dependent repositories: 0
- Total versions: 21
- Total maintainers: 1
pypi.org: searoute
A python package for generating the shortest sea route between two points on Earth.
- Documentation: https://github.com/genthalili/searoute-py/blob/main/README.md
- License: Apache License 2.0
-
Latest release: 1.4.3
published 12 months ago
Rankings
Maintainers (1)
Dependencies
- geojson *
- networkx *
- osmnx *
- turfpy *