Traffic density
/v1/aggregate answers "how busy", not "who". For every cell and time bucket under a region it counts the AIS reports, how many of them were under way, their mean speed, and how many distinct vessels there were — that last one as a range, for a reason worth understanding before you draw anything with it. It reads a cube summed in advance from the same AIS as vessels and tracks, so a day of a region is one quick request rather than thousands of positions.
curl -G "https://api.oslew.com/v1/aggregate" \
-H "Authorization: Bearer $GEO_API_KEY" \
--data-urlencode 'at=32.70,-117.20' \
--data-urlencode 'in_level=6' \
--data-urlencode 'level=8' \
--data-urlencode 'from=1735603200' \
--data-urlencode 'to=1735689600' \
--data-urlencode 'bucket=21600' \
--data-urlencode 'limit=5'from oslew import Client
# The key is read from GEO_API_KEY.
client = Client(base_url="https://api.oslew.com")
answer = client.aggregate(
"32.70,-117.20",
in_level=6,
level=8,
from_=1735603200,
to=1735689600,
bucket=21600,
limit=5,
)import { Client } from "@oslew/client";
// The key is read from GEO_API_KEY.
const client = new Client({ baseUrl: "https://api.oslew.com" });
const answer = await client.aggregate("32.70,-117.20", {
in_level: 6,
level: 8,
from: 1735603200,
to: 1735689600,
bucket: 21600,
limit: 5,
});HTTP/1.1 200 OK
content-type: application/json
ratelimit-limit: 100
ratelimit-remaining: 291
ratelimit-reset: 1
{
"at": [
32.7,
-117.2
],
"cell": 9286140956661252096,
"in_level": 6,
"level": 8,
"from": 1735603200,
"to": 1735689600,
"bucket": 21600,
"rows": [
{
"cell": 9286017811358941184,
"level": 8,
"from": 1735603200,
"to": 1735624800,
"entries": 9,
"positions": 161,
"moving": 161,
"mean_sog_kn": 9.190062111801241,
"vessels_min": 2,
"vessels_max": 10
},
{
"cell": 9286017811358941184,
"level": 8,
"from": 1735624800,
"to": 1735646400,
"entries": 11,
"positions": 134,
"moving": 134,
"mean_sog_kn": 13.72313432835821,
"vessels_min": 1,
"vessels_max": 11
},
{
"cell": 9286017811358941184,
"level": 8,
"from": 1735646400,
"to": 1735668000,
"entries": 5,
"positions": 70,
"moving": 70,
"mean_sog_kn": 15.29857142857143,
"vessels_min": 1,
"vessels_max": 5
},
{
"cell": 9286017811358941184,
"level": 8,
"from": 1735668000,
"to": 1735689600,
"entries": 1,
"positions": 19,
"moving": 19,
"mean_sog_kn": 10.963157894736844,
"vessels_min": 1,
"vessels_max": 1
},
{
"cell": 9286052995731030016,
"level": 8,
"from": 1735603200,
"to": 1735624800,
"entries": 19,
"positions": 26169,
"moving": 719,
"mean_sog_kn": 0.1749933126982307,
"vessels_min": 233,
"vessels_max": 1476
}
],
"provenance": {
"name": "noaa-ais",
"release": "2024-12-31",
"license": "public domain (US Government work)"
},
"took_us": 205
}A real response, captured from the service at commit b8f4bde-dirty. Timing fields such as took_us differ on every call.
Asking
| Parameter | Default | Is |
|---|---|---|
at | required | lat,lon: a point in the region. |
in_level | 4 | The region: the cell at this level that contains at. Clamped to 0–10; 4 is about 600 km across. |
level | the larger of in_level and 6 | The output cells, each inside the region. Clamped to in_level–10. |
from, to | the cube's span | Unix seconds. from must be before to, or it is a 400, from must be before to. |
bucket | 3600 | Seconds per time bucket: at least 3,600, and rounded down to whole hours. |
limit | 1,000 | Rows to return, clamped to 1–10,000. |
Above, the region is the level-6 cell around a point off San Diego — about 150 km across — and the rows are the level-8 cells inside it, about 40 km each, in six-hour buckets over 31 December 2024. The answer echoescell (the region's id), in_level, level, the window and the bucket it used.Cells and levels has the size of every level and how to draw a cell from its id.
Nothing is finer than the cube. It holds level-10 cells, about 10 km, by clock hour, solevel stops at 10 and a bucket is a whole number of hours. Buckets start at from and step by bucket, and an hour of the cube counts in the bucket its start falls in — so only hours thatstart inside the window count. Put from on the hour, and on midnight for daily buckets: a window from 00:30 leaves the 00:00 hour out entirely. The last bucket's to can reach past the window's.
A row
| Field | Is |
|---|---|
cell, level | The output cell's id, and its level. |
from, to | The bucket: its start, and its end, exclusive. |
entries | How many cube entries — level-10 cells in one hour, with traffic — were summed into the row. |
positions | Position reports. Exact. |
moving | Reports with a speed of at least 0.5 kn. Exact. |
mean_sog_kn | Mean speed over ground, in knots, over the reports whose speed is known; null when none is. |
vessels_min, vessels_max | Distinct vessels: a bound, below. |
- No row means no reports. Rows exist only where there was traffic; a cell and bucket missing from the answer is a zero, not a gap in the data — within the area the loaded AIS covers.
- Rows are sorted by cell, then time, and
limitcuts that order. It keeps the first cells by id, not the busiest: the five rows above are the first five, not the top five. If you get exactlylimitrows, raise it or narrow the region or the window, and sort by traffic yourself. - The mean speed is per report. A ship that transmits twice as often weighs twice as much in
mean_sog_kn, and AIS transmits more often under way than at anchor.moving ÷ positionsis the share of reports under way, not the share of ships.
Distinct vessels are a bound, and why
The cube stores, for each level-10 cell and hour, how many reports there were, how many were under way, their summed speed — and how many different vessels sent them. The first three add: the reports in a 40 km cell over six hours are exactly the sum of the reports in its 10 km cells in each of those hours, sopositions and moving are exact at any level and any bucket.
A count of distinct vessels does not add. A ship that spends three hours in one 10 km cell is one vessel in each of three entries: summed, three; in truth, one. A ship that crosses four cells in an hour is counted in four entries. The entries record how many vessels, not which, so the overlap between them cannot be recovered afterwards. What can be said honestly is a range:
vessels_min— at least the busiest single entry: those vessels were all distinct from each other.vessels_max— at most the sum of all the entries, if no vessel appeared in two.
The third row above is five entries of one vessel each: vessels_min 1 and vessels_max5. That is one ship seen in five cell-hours, five ships seen once, or anything between, and the answer says so rather than picking one. The midpoint is not an estimate of anything.
Where it is exact. At level=10 with bucket=3600 each row is a single entry, and the two numbers are equal. For an exact count over a bigger cell or a longer window, ask/v1/vessels for the same cell and window: it answers one row per vessel, so its length is the distinct count.
A heatmap
Ask for the bucket you mean to draw. For one picture of a day, one bucket the length of the day gives one row per cell. Colour by positions, on a logarithmic scale: traffic is concentrated in lanes and ports, and a linear scale shows the port and nothing else.
import math
from oslew import Client
client = Client(base_url="https://api.oslew.com")
day = client.aggregate(
"32.70,-117.20", in_level=6, level=10,
from_=1_735_603_200, to=1_735_689_600, bucket=86_400, limit=10_000,
)
if len(day["rows"]) == 10_000:
raise RuntimeError("cut at the limit: narrow the region")
top = max((r["positions"] for r in day["rows"]), default=1)
heat = {
r["cell"]: {
"shade": math.log1p(r["positions"]) / math.log1p(top), # 0..1, for a colour ramp
"positions": r["positions"],
"moving_share": r["moving"] / r["positions"],
"vessels": (r["vessels_min"], r["vessels_max"]),
}
for r in day["rows"]
}import { Client } from "@oslew/client";
const client = new Client({ baseUrl: "https://api.oslew.com" });
const day = await client.aggregate("32.70,-117.20", {
in_level: 6, level: 10, from: 1_735_603_200, to: 1_735_689_600, bucket: 86_400, limit: 10_000,
});
if (day.rows.length === 10_000) throw new Error("cut at the limit: narrow the region");
const top = Math.max(1, ...day.rows.map((r) => r.positions));
const heat = new Map(
day.rows.map((r) => [
BigInt(r.cell).toString(), // a cell id is 64-bit: never print or key it as a plain number
{
shade: Math.log1p(r.positions) / Math.log1p(top), // 0..1, for a colour ramp
positions: r.positions,
movingShare: r.moving / r.positions,
vessels: [r.vessels_min, r.vessels_max],
},
]),
);Rows name their cells by id, not by shape; cells and levels covers turning an id into a polygon to fill. For an animation over the day, ask again with bucket=3600 and draw a frame per hour — positions in each frame is exact, and the frames add up to the day.
Coverage and refusals
The cube covers what the loaded AIS covers — NOAA's AIS for one day, as heard by US coastal receivers; the box at the top of this page says which — and its span is the default window. A region with no receivers has no rows, which on a map looks exactly like an empty sea; know the coverage of the source before you read an absence. With no cube loaded the answer is a 400,no cube loaded.
Endpoints
/v1/aggregateplatformVessel traffic under a cell rolled up by cell and time bucket: exact position counts, and a bound on distinct vessels.