oslew docs
Console
Menu

Cells and levels

Everything in the index is addressed by cells of one fixed hierarchy, and several routes let you choose a level of it: how big an isochrone's cells are, how wide an area a vessel query covers, how coarse a density grid is. A few more use a level internally, and knowing which explains behaviour that would otherwise look arbitrary — whynear is not a circle, why a place's precision_m is 6.76 m.

The hierarchy

  • The sphere is projected onto a cube, using S2's projection. Each of the six faces is one cell at level 0, and every cell is split into exactly four at the next level, down to level 30, about a centimetre. Projecting onto a cube rather than cutting a latitude–longitude grid keeps cells of one level roughly the same size everywhere: a latitude–longitude cell shrinks to nothing at the poles, while here the largest cell of a level has about twice the area of the smallest.
  • Nesting is exact. Every cell lies entirely inside its parent, so "is this inside that cell?" is two integer comparisons, and a region at one level is exactly its children at the next. The storage underneath is fetched by ranges of cells, and a child that strayed outside its parent's range would be a row that silently vanished from a query. That is why these are squares and not hexagons: hexagons do not tile a larger hexagon exactly.
  • Ids follow a Hilbert curve. A cell id is a 64-bit integer: three bits for the face, two bits per level for the position along a space-filling curve, and a marker bit whose place encodes the level. Sorting ids sorts cells by place — cells close in id are close on the ground — which is what lets a region be read as a few contiguous ranges.

How big a level is

The approximate width of a cell, from a face's 90° halved once per level — the same estimate the service sizes cells by. Real cells vary around it across a face, so read these as sizes, not measurements. Each level down has four times as many cells.

LevelAboutWhere the service uses it
010,019 kmA whole cube face.
22,505 kmThe coarsest cell /v1/vessels takes.
4626 kmThe default region for vessel traffic density (in_level).
6157 kmThe default output cells for traffic density.
839 kmThe default cell for /v1/vessels; the demand map of query-log analytics.
109.8 kmA near constraint, about a city. The coarsest reverse and road-snap search. The finest traffic-density cell.
122.4 kmPositions in the query log.
131.2 kmA coarser isochrone for a city-scale drive.
14611 mThe default isochrone cell; where a road snap starts.
15306 mWhere a reverse search starts.
16153 mThe finest cell an isochrone or /v1/vessels takes.
2010 mStored place positions.
301 cmThe finest cell there is.

Where levels appear

Levels you choose

RouteParameterDefault and rangeDecides
/v1/isochronelevel14 (about 600 m), clamped to 8–16The size of the cells the answer is made of. Each reachable cell comes with its earliest arrival and its bbox, and the polygon outlines them.
/v1/vesselslevel8 (about 40 km), 2–16The one cell around at whose vessels are listed. The answer names it in cell and level.
/v1/aggregatein_level4 (about 600 km), 0–10The region: the cell around at whose traffic is rolled up.
levelthe larger of in_level and 6; from in_level to 10The rows: one per output cell and time bucket. Density is kept per level-10 cell and hour, which is why 10 is the finest.

A level out of range is clamped, not refused; the answer's level says what was used. Seeconventions.

Levels the service uses for you

  • near on geocoding and autocompleteis the level-10 cell containing the point — about a city. It is a filter, not a bias: results outside that one cell are dropped. It is a square the point lies somewhere in, not a circle centred on it, so a point near the edge of its cell excludes places a short walk away on the other side of the edge. For "closest to here", use reverse or nearby, which measure distance.
  • Reverse geocoding searches the level-15 cell around the point (about 300 m) and the eight around it, then widens a level at a time as far as level 10 (about 10 km) until it has enough results it can prove are nearest.
  • Snapping to a road starts at level 14 and widens to level 10, which is where the "no road within 9 km" limit on routing comes from.
  • A place's position is the centre of the level-20 cell it lies in. A level-20 cell is about 10 m across, so the centre is at most about 7 m from any point in it — the 6.76 m precision_m that place results carry. See reading a result.
  • The query log keeps positions as level-12 cells, about 2 km — a neighbourhood, never a building — and its analytics count demand in level-8 cells. See what is logged.

Choosing a level

  • Four times the cells per level. An isochrone at level 16 has about sixteen times as many cells as the same one at level 14, and so a larger answer and a more detailed outline. Pick the coarsest level that answers the question: 13 or 14 for a city-scale drive, 15 or 16 for a walk.
  • A vessel query covers one cell, not a radius. A port approach fits a level-8 cell; a single harbour wants 10 or 11. If the area you mean straddles a cell edge, query once with a point on each side — seevessels and tracks.
  • For density, the region and the grid are separate choices. in_level is how much sea; level is how fine the grid over it. Each step of difference between them is four times the rows, so a fine grid over a wide region runs into limit (default 1,000, at most 10,000) quickly.
TypeScript
const { cell } = JSON.parse('{"cell": 9286052995731030016}');
String(cell);                  // "9286052995731030000": not a cell
BigInt(cell).toString();       // "9286052995731030016": the id that was sent