Oceanbolt Python SDK Lesson 6 - Port Distances at Scale

Oceanbolt Python SDK Lesson 6 - Port Distances at Scale

Welcome to Lesson 6 in our Python SDK learning series. Each lesson is independent, but make sure you check out Lesson 1, Lesson 2, Lesson 3, Lesson 4, and Lesson 5.

For certain maritime analyses, you will require a distance parameter. E.g. to calculate voyage times or estimate bunker consumption. It is often a tedious process to access many port to port distances or calculating the distance from a current position of a vessel to a port. We have made this easy by exposing our proprietary Oceanbolt Port Distance calculator.

As always, you can follow along in this Jupyter Notebook or read the summary below.

Port Distances at Scale

You can use our Port Distance API to get port(s) to port(s) or vessel to port distances.

Vessel to Port Example

The vessel MAGIC VELA (IMO: 9473327) is currently heading to Santos. You can find the distance from its current position to Santos by running the code below.

distance = DistanceCalculator(base_client).distance(
    locations=[
        {"imo": 9473327},
        {"unlocode": "BRSSZ"},
    ]
)

At the time of writing, this code would return 545 nautical miles. The picture below visualizes this query in our dashboard.

Magic Vela underway to Santos

Magic Vela underway to Santos

Port to Port Example

For port to port queries, you can run the code below.

distance = DistanceCalculator(base_client).distance(
    locations=[
        {"unlocode": "BRSSZ"},
        {"unlocode": "CNQDG"},
    ]
)
print("There are",round(distance),"nautical miles from Santos to Qingdao")

In this case, the code returns: “There are 11,211 nautical miles from Santos to Qingdao”.

Multiple Ports to Ports Example

See our Jupyter Notebook to find the code for how to get multiple port to port distances.

Thanks for reading this!