Skip to content
oslew
Get a free key

Use case

Port call detection from AIS data

Port call detection from AIS data means finding the stretches where a ship stopped at a berth or an anchorage, and saying where and when. With oslew the stop comes from a vessel’s track — a run of reports at almost no speed — the country comes from the maritime zone dwell that run falls inside, and the traffic context comes from density rows with exact report counts. Zone crossings mark territorial waters, not arrival in port, so the two parts of the report are built separately and joined.

Last reviewed

A port call is not something AIS reports. Ships broadcast where they are and how fast they are moving; whether that adds up to a call at a terminal, a wait at anchor or a pilot boarding is an inference. This workflow makes the inference explicit, keeps the thresholds in your hands, and records how confident each row is, so the report can be defended when a charter party or an auditor asks how a call was established.

Decide what the report counts

Two different events tend to get merged under “port call”, and the API answers them from different routes:

Event What it means Where it comes from
Stop The ship stayed nearly still for a meaningful time: a berth, an anchorage, a lay-by Runs of slow reports in /v1/track
Territorial entry or exit The ship came inside or went beyond a country’s territorial sea /v1/crossings with the maritime zones

A report usually wants both: each stop, with the country whose waters it was in and the time the ship entered and left those waters. The port’s own boundary — a harbour limit or a terminal polygon — is something you hold. The vessel tracking API evaluates only the loaded divisions, so a harbour polygon of your own is tested against positions in your code.

Step one: find the ships

Start from a point in the port and ask /v1/vessels for the cell around it over the reporting window. Each ship appears once, so the list is the set of MMSIs to follow. A cell is a square, not a radius, so a port near a cell’s edge needs a coarser level or a second query from the neighbouring cell. For a busy port over a long period, split the window into days so no single answer reaches its limit.

Step two: pull each track

For every MMSI, /v1/track returns every report in the window in time order, wherever the ship went. The window is the only bound on its size, so ask for the reporting period plus a margin either side; a call that began just before the period starts is otherwise cut in half. Each track is a request against the Platform rate, so pace the loop rather than meeting HTTP 429.

One vessel’s track and its territorial-water events for a day
curl -H "Authorization: Bearer $OSLEW_KEY" \
"https://api.oslew.com/v1/track?mmsi=311827000&from=1672531200&to=1672617599"

curl -H "Authorization: Bearer $OSLEW_KEY" \
"https://api.oslew.com/v1/crossings?mmsi=311827000&from=1672531200&to=1672617599"

Step three: turn slow runs into stops

Walk each track and collect runs of consecutive reports whose speed over ground is under a threshold, keeping runs that last longer than a minimum. Under half a knot for at least an hour catches berths and anchorages while ignoring a ship slowing for a pilot; container feeders, tankers and ferries each deserve their own numbers. Three details decide whether the rule works:

  • Unknown speed is not slow. AIS marks an unavailable speed with a code far above any real value, so a naive comparison would treat a missing reading as fast and split a stop. Treat unknowns as neither, and carry the run across them.
  • Join short breaks. A ship swinging at anchor or shifting berth briefly exceeds the threshold. Merge stops separated by less than, say, half an hour at the same place.
  • Use status as a check, not a rule. Moored or at anchor supports a stop; “under way using engine” at zero knots is common and means little.

Step four: say where each stop was

If you maintain a list of berths, anchorages or harbour polygons, match each stop’s middle report against it in your code — that is the most reliable naming you will get. Without one, reverse geocode the middle report with the reverse geocoding API for the nearest named place, and add the administrative chain from the boundaries API for the country and municipality. A stop that reverse geocodes to nothing nearby is often an offshore anchorage, which is itself worth reporting.

Step five: attach territorial-water events

/v1/crossings for the same MMSI and window reduces the track to entries, exits and dwells against the maritime zones. For each stop, find the dwell whose first and last reports bracket it: that dwell’s zone is the country whose waters the call was in, and its crossings are when the ship arrived in and left those waters. Two flags matter. A dwell that starts with an at_start entry began before the window, so the arrival time is not known. A dwell marked open ends at the window’s last report, not at an exit.

Asking with zones=all adds every loaded land division to the evaluation. Where a berth falls inside a coastal municipality’s polygon, a dwell in that locality can corroborate a call; many berths sit on reclaimed land or water outside such polygons, so treat it as supporting evidence only.

Step six: add traffic volume

A port report often closes with how busy the approaches were. /v1/aggregate over the region around the port, with a daily or hourly bucket, gives exact report counts and moving reports per cell, which can be summed or re-bucketed on your side without losing accuracy. Its distinct-vessel figure is a range except at the finest cell and a one-hour bucket; print it as a range. For an exact number of ships, your own list of MMSIs with detected calls is better than either.

What a finished row looks like

Column Source Confidence to record
MMSI The vessel list —
Arrival, departure First and last slow reports of the stop The gap to the neighbouring reports
Place Your berth list, or the nearest named place Distance to the match
Country The maritime dwell containing the stop Whether that dwell is at_start or open
Entered, left territorial waters The crossings bracketing the dwell The gap either side of each crossing

Positions from NOAA are public domain (US Government work). The maritime zones are ODbL-1.0, the licence Overture publishes its Divisions theme under, so the finished table may be stored, but shared as a database it carries the ODbL’s share-alike and attribution with it; the licensing page covers the other layers a report might add. The vessel, crossing and boundary routes are the Platform product and reverse geocoding the Address product; the Platform plan carries both, $699 a month for 20 requests a second sustained, burst 100 of platform requests on the pricing page.

Bottom line

Detect calls from slow runs in each track, name them from your own berth list or the nearest place, take the country and the territorial-water times from maritime dwells and crossings, and report density with its vessel range intact. Record the reporting gap beside every time, because AIS silence is the main source of error, and the report is only as complete as the receivers behind the loaded data.

Where this workflow falls short

  • AIS has gaps wherever no receiver heard a ship. A stop inside a gap is invisible, and every arrival and departure time is only as precise as the spacing of reports on either side of it.
  • The answers cover only the AIS loaded into the deployment. A port with no calls in the report may have had no traffic, or no receiver coverage in the loaded data; the output cannot tell the two apart.
  • Distinct vessels in density rows are a [min, max] bound. For an exact count of ships in one cell and window, use the vessels route, which lists each ship once.
  • Navigational status is set by the crew and often stale. Speed over ground is the better signal of a stop, with status as a second opinion only.
  • Custom port polygons are not an API input. Zones evaluated by the crossings route are the loaded divisions, so a port’s own boundary has to be tested in your code.

Questions

Does oslew detect port calls automatically?

There is no port-call endpoint. The service provides the pieces — each vessel’s full track, zone entries and exits with dwells, and nearest-place lookups — and a port call is a rule you apply to them: a run of reports below a speed threshold for longer than a minimum time. The thresholds are yours to tune for the fleet.

Why does arriving in port not show up as a zone crossing?

A maritime zone is a country’s land plus its territorial sea. A ship already inside a country’s waters that proceeds to a berth stays inside the same zone the whole way, so nothing is crossed. Crossings answer when a ship entered or left a country’s waters; the stop itself has to be found in the track.

How precise are arrival and departure times?

As precise as the reports around them. The arrival is the first slow report and the departure the last, so the true moment lies in the gap before or after. Where reports are a minute apart the error is small; across a reception gap it can be hours, and the report should flag it.

Can I count how many ships called at a port?

Count distinct MMSIs among your detected calls for an exact figure. For traffic volume around the port, density rows give exact report counts, but their distinct-vessel figure over a large cell or long bucket is a range, and should be reported as one.

Is the AIS data live?

It is whatever AIS the deployment has loaded, named with its release in every answer’s provenance. A report built from it describes that period. For a current port-call feed, the deployment needs a current AIS source loaded; the routes themselves do not fetch one.

Browse every page →