Skip to content

Commit

Permalink
v1.0.9
Browse files Browse the repository at this point in the history
  • Loading branch information
genthalili committed Jan 1, 2023
1 parent 29a8aae commit 3f0d1c7
Show file tree
Hide file tree
Showing 7 changed files with 44 additions and 16 deletions.
12 changes: 9 additions & 3 deletions CHANGELOG.txt
Original file line number Diff line number Diff line change
Expand Up @@ -22,15 +22,21 @@ Change Log

1.0.6 (05/10/2022)
------------------
- Imporved network connectivity
- Improved network connectivity

1.0.7 (13/10/2022)
------------------
- Imporved network connectivity
- Improved network connectivity
- Connection points were not adjusted

1.0.8 (25/10/2022)
------------------
- Imporved network connectivity
- Improved network connectivity
- Added append_orig_dest parameter as input to append origin and destination points to the LineString
- Updated README.md

1.0.9 (04/01/2023)
------------------
- Improved network connectivity
- Added restrictions parameter as input to control restrictivity of connections due to different reasons
- Updated README.md
5 changes: 5 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,11 @@ 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`;
default is `['northwest']`

## Credits

Based on Eurostat's [Searoute Java library](https://github.com/eurostat/searoute) and Dijkstra's algorithm implemented by [perliedman](https://www.liedman.net/geojson-path-finder/).
Binary file modified searoute/__pycache__/searoute.cpython-310.pyc
Binary file not shown.
2 changes: 1 addition & 1 deletion searoute/data/marnet_densified_v2.geojson

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion searoute/data/marnet_densified_v2_old.geojson

Large diffs are not rendered by default.

36 changes: 26 additions & 10 deletions searoute/searoute.py
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,9 @@ def createGraph():
for i in fc.features:
coords = i['geometry']['coordinates']
coord_l = len(coords)

properties = i['properties']

k = 0
for l in coords:
c_X = l[0]
Expand All @@ -85,19 +88,26 @@ def createGraph():

ll = LineString([(c_X, c_Y), (n_X, n_Y)])
lenght = measurement.length(ll)
G.add_edge(c_node, nx_node, weight=lenght)
G.add_edge(nx_node, c_node, weight=lenght)
G.add_edge(c_node, nx_node, weight=lenght, **properties)
G.add_edge(nx_node, c_node, weight=lenght, **properties)


k= k+1

return G

G = createGraph()

#possible passages: babalmandab, bosporus, gibraltar, suez, panama, ormuz, northwest
RESTRICTIONS = ['northwest']

G = createGraph()
def filter_edge(n1, n2, n3):
val = G[n1][n2][n3].get('passage')

def searoute(origin, destination, units='km', speed_knot=24, append_orig_dest = False):
if (val is None) or (val not in RESTRICTIONS):
return True
return False

def searoute(origin, destination, units='km', speed_knot=24, append_orig_dest = False, restrictions = RESTRICTIONS):
"""
searoute Returnes the shortest sea route between two points on Earth.
Expand All @@ -106,20 +116,26 @@ def searoute(origin, destination, units='km', speed_knot=24, append_orig_dest =
:param units: units default to 'km' = kilometers, can be 'm' = meters 'mi = miles 'ft' = feets 'in' = inches 'deg' = degrees 'cen' = centimeters 'rad' = radians 'naut' = nauticals 'yd' = yards
:param speed_knot: speed of the boat, default 24 knots
:param append_orig_dest: add origin and dest geopoints in the LineString of the route, default is False
:param restrictions: an list of restrictions of paths to awoid, use as per your specific need; default restricted ['northwest']; possible passages: babalmandab, bosporus, gibraltar, suez, panama, ormuz, northwest
:return: a Feature (geojson) of a LineSring of sea route with parameters : unit and legth
"""



global RESTRICTIONS
RESTRICTIONS = restrictions

H = nx.subgraph_view(G, filter_edge=filter_edge)

# In the graph, get the nodes closest to the points
origin_node = ox.distance.nearest_nodes(G, origin[0], origin[1])
destination_node = ox.distance.nearest_nodes(G, destination[0], destination[1])
origin_node = ox.distance.nearest_nodes(H, origin[0], origin[1])
destination_node = ox.distance.nearest_nodes(H, destination[0], destination[1])

# Get the shortest route by distance
shortest_route_by_distance = ox.shortest_path(G, origin_node, destination_node, weight='weight')
shortest_route_by_distance = ox.shortest_path(H, origin_node, destination_node, weight='weight')
ls = []
previousX = None
for i in shortest_route_by_distance:
node = G.nodes[i]
node = H.nodes[i]
nowX = node['x']

if previousX:
Expand Down
3 changes: 2 additions & 1 deletion test.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,8 @@
destination = [-118.2629, 33.7276]


route = sr.searoute(origin, destination, append_orig_dest=True)

route = sr.searoute(origin, destination, append_orig_dest=True, restrictions=['northwest'])
# > Returns a GeoJSON LineString Feature
# show route distance with unit
print("{:.1f} {}".format(route.properties['length'], route.properties['units']))
Expand Down

0 comments on commit 3f0d1c7

Please sign in to comment.