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

This lesson is about creating your own polygons and leveraging Oceanbolt’s algorithms to do vessel counts – quickly at scale. You can follow along in this Jupyter Notebook or read the summary below.

Oceanbolt Python SDK Lesson 3: Custom Polygons

At Oceanbolt, a core part of our work is geospatial analytics. We use geofences (or polygons as we refer to them internally) to build our cargo tracking algorithms and to infer what the dry bulk fleet is doing (now and historically). While we provide our users with a fully mapped world of dry bulk infrastructure (e.g. ports, berths, terminals), a user may have a desire to create her or his own polygons to monitor particular areas of interest. An example of this may be a Handysize operator, who thinks differently about zones, than a Capesize operator does.

We have therefore introduced the functionality to unleash the power of Oceanbolt’s algorithms on a user’s “self-defined” or “custom” polygons. All that is required are the coordinates that make up the user-defined polygons.

In the example below, we create a polygon of the Atlantic Ocean to track the number of Ultramaxes in laden and ballast status since 2019. The calculation on this polygon to get all historical daily counts since 2019 takes less than 1 second (pretty fast, yes!).

How to generate polygons

In order to generate counts, we need a polygon and its coordinate in GeoJSON format. There are many tools available to create and manage polygons and geospatial layers, e.g. QGIS and geojson.io. For our purpose, we use geojson.io, as it is quick and easy to use and directly prints the coordinates for the polygons required GeoJSON string.

Below you will find a GIF outlining how we get the polygon coordinates for the Atlantic Ocean by using geojson.io.

Atlantic Ocean Polygon
Generating a polygon on geojson.io

NOTE: The polygon is rather crude and users may actually be more diligent in properly drawing the polygons.

Now that we have the polygon ready, we turn to the Oceanbolt Python SDK to write the actual script. Here is a sample of the code from the Jupyter Notebook. You can follow along in the notebook to get a better understanding of the steps.

In the Jupyter Notebook you will see an additional code snippet that calculates the time it takes to run each of these operations. As per the notebook, it takes 0.7 seconds to get the laden vessels and 0.5 seconds to get the ballast vessels. Note that this includes all historical counts going back to 01 Jan 2019 up until today.

We continue to plot the timeseries:

The resulting output, we get is the chart below with ballaster in orange and laden in blue.

Number of ballast (orange) versus laden (blue) Ultramaxes in Atlantic Ocean

Thanks for reading this! If you are interested in getting access to our data, sign up for a product demo and stay tuned for future lessons!

NOTE: The custom polygons feature will be available in our web-based dashboard to allow non-Python users to define their own polygons as well.