Closed this-josh closed 3 weeks ago
M
P
This PR fixes a bug that can occur when using restrictions currently if you
restrictions=None
restrictions = ['suez']
Then if you solve with no restriction restrictions=None it keeps the suez restriction.
Here is an MWE for the problem
import searoute as sr import folium src_lat = -15.46667 src_lon = 28.26667 dst_lat = 51.5 dst_lon = -0.1666667 b = sr.searoute( [src_lon, src_lat], [dst_lon, dst_lat], include_ports=True, port_params=dict( country_pol="ZM", country_pod="GB" ), restrictions = None ) d = sr.searoute( [src_lon, src_lat], [dst_lon, dst_lat], include_ports=True, port_params=dict( country_pol="ZM", country_pod="GB" ), restrictions = ['suez'] ) nb = sr.searoute( [src_lon, src_lat], [dst_lon, dst_lat], include_ports=True, port_params=dict( country_pol="ZM", country_pod="GB" ), restrictions = None ) # Swap coord order for folium b['geometry']['coordinates'] = [list(reversed(coord)) for coord in b['geometry']['coordinates']] d['geometry']['coordinates'] = [list(reversed(coord)) for coord in d['geometry']['coordinates']] nb['geometry']['coordinates'] = [list(reversed(coord)) for coord in nb['geometry']['coordinates']] m = folium.Map(location=[0,0],zoom_start=3) folium.PolyLine(b['geometry']['coordinates'], color="blue", weight=2.5, opacity=1).add_to(m) folium.PolyLine(d['geometry']['coordinates'], color="red", weight=2.5, opacity=1).add_to(m) folium.PolyLine(nb['geometry']['coordinates'], color="black", weight=2.5, opacity=0.5).add_to(m) m
You can see the disrupted and the second undisrupted go via the horn of Africa while the first undisrupted uses the Suez canal
thanks @this-josh !
No problem, thanks for a great package!
M
andP
are as default arguments (https://github.com/genthalili/searoute-py/blob/85c395fa7dbe9111ad91101bc3aa49079229577d/searoute/searoute.py#L16) , in python default arguments should not be mutable, so we make them None and then initialise in the function.This PR fixes a bug that can occur when using restrictions currently if you
restrictions=None
restrictions = ['suez']
Then if you solve with no restriction
restrictions=None
it keeps the suez restriction.Here is an MWE for the problem
You can see the disrupted and the second undisrupted go via the horn of Africa while the first undisrupted uses the Suez canal