Package: searoute
Searoute pyA 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.InstallationpipinstallsearouteUsageimportsearouteassr#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 unitprint("{:.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' = yardsrouteMiles=sr.searoute(origin,destination,units="mi")Bring your network :# 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)my_edges={(1,2):{(2,2):{"weight":10,"other_attr":"some_value"}}}# MarnetmyM=sr.from_nodes_edges_set(sr.Marnet(),my_nodes,my_edges)# PortsmyP=sr.from_nodes_edges_set(sr.Ports(),my_nodes,None)# get shortest with your portsroute_with_my_ports=sr.searoute(origin,destination,P=myP,include_ports=True)# get shortest with your portsroute_with_my_ntw=sr.searoute(origin,destination,P=myP,M=myM)Nodes and EdgesNodesA 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 atupleof lon,lat, and it's attributes:x: float ; requiredy: float ; requiredt: bool ; optional. default isFalse, will be used for filtering ports withterminals.{(lon:float,lat:float):{'x':lon:float,'y':lat:float,*args:any},...}EdgesAn edge is a line or connection between a note and an other. This connection can be represented by a set of node_id->node_id with it's attributes:weight: float ; required. Can be distance, cost etc... if not set will by default calculate the distance between nodes usingHaversine 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 updateMarnet().restrictions = [...]with your list of passages to avoid.{(lon:float,lat:float)->node_id:{(lon:float,lat:float)->node_id:{"weight":distance:float,*args:any}},...}Example with more parameters :## Using all parameters, wil include ports as wellroute=sr.searoute(origin,destination,append_orig_dest=True,restrictions=['northwest'],include_ports=True,port_params={'only_terminals':True,'country_pol':'FR','country_pod':'CN'})returns :{"geometry":{"coordinates":[],"type":"LineString"},"properties":{"duration_hours":461.88474412693756,"length":20529.85310695412,"port_dest":{"cty":"China","name":"Tianjin","port":"CNTSN","t":1,"x":117.744852,"y":38.986802},"port_origin":{"cty":"France","name":"Le Havre","port":"FRLEH","t":1,"x":0.107054,"y":49.485998},"units":"km"},"type":"Feature"}ParametersoriginMandatory. A tuple or array of 2 floats representing longitude and latitude i.e :({lon}, {lat})destinationMandatory. A tuple or array of 2 floats representing longitude and latitude i.e :({lon}, {lat})unitsOptional. Default tokm= kilometers, can bem= metersmi= milesft= feetsin= inchesdeg= degreescen= centimetersrad= radiansnaut= nauticalsyd= yardsspeed_knotOptional. Speed of the boat, default 24 knotsappend_orig_destOptional. If the origin and destination should be appended to the LineString, default isFalserestrictionsOptional. List of passages to be restricted during calculations.
Possible values :babalmandab,bosporus,gibraltar,suez,panama,ormuz,northwest,malacca,sunda;
default is['northwest']include_portsOptional. If the port of load and discharge should be included, default isFalseport_paramsOptional. Ifinclude_portsisTruethen you can set port configuration for advanced filtering :only_terminalsto include only terminal ports, defaultFalsecountry_polcountry iso code (2 letters) for closest port of load, defaultNone. When not set or not found, closest port is based on geography.country_podcountry iso code (2 letters) for closest port of discharge, defaultNone. When not set or not found, closest port is based on geography.country_restrictedto filter out ports that have registered an argument keyto_cty(a list) which indicates an existing route to the country same as incountry_pod; defaultFalsedefault is{}ReturnsGeoJson FeatureCreditsNetworkX, a Python package for the creation, manipulation, and study of the structure, dynamics, and functions of complex networks.GeoJson, a python package for GeoJSONturfpy, a Python library for performing geo-spatial data analysis which reimplements turf.js. (up to versionsearoute 1.1.0)OSMnx, for geo-spacial networks. (up to versionsearoute 1.1.0)Eurostat'sSearoute Java libraryChange Log1.0.2 (30/09/2022)First Release, published module1.0.3 (04/10/2022)changed the core of the calculation to osmnx library for better performancemaking 1.0.2 obsoleteadded duration measurement together with length in the LineString properties1.0.4 (04/10/2022)fix requirements of the module1.0.5 (04/10/2022)Adjusted network (.json) by connecting all LineStrings in order to return a route from any location to any location1.0.6 (05/10/2022)Improved network connectivity1.0.7 (13/10/2022)Improved network connectivityConnection points were not adjusted1.0.8 (25/10/2022)Improved network connectivityAdded append_orig_dest parameter as input to append origin and destination points to the LineStringUpdated README.md1.0.9 (04/01/2023)Improved network connectivityAdded restrictions parameter as input to control restrictiveness of connections due to different reasonsUpdated README.md1.1.0 (23/05/2023)Improved network connectivityAdded new feature : closest port of load and port of dischargeUpdated README.md1.2.0 (24/08/2023)35x Faster: Significantly accelerated compared to v1.1 by rethinking and reorganizing the code.Re-think Class Design: Re-structured and simplified class structure.Easy API AccessImproved Network Connectivity: Enhanced network reliability.Updated README.md: Revised for the latest information.1.2.1 (28/08/2023)Patch fixed issue when querying country with no port result1.2.2 (08/09/2023)Patch fixed and simplified coords line normalization1.2.3 (05/01/2024)Patch fixed and improved coords validation1.3.0 (11/01/2024)Added in port_params additional parameter country_restrictedUpdated license to Apache 2.01.3.1 (27/01/2024)Enriched network with additional passages