Introducing a new way to review your PRs.

Read the announcement

maplibre / martin

Blazing fast and lightweight PostGIS, MBtiles and PMtiles tile server, tile generation, and mbtiles tooling.

View on GitHub

22 documents · Updated Nov 23, 2026

docs / openstreetmap-tile-generation

OpenStreetMap tile generation

OpenStreetMap tile generation turns an .osm.pbf extract into a vector tile archive. The run reads tagged OSM objects, applies a Shortbread-style layer plan, renders the selected geometry at each requested zoom, and writes MLT or MVT tiles to MBTiles or PMTiles.

Source model

An OpenStreetMap PBF source is a feature stream for bulk generation. The source exposes tagged nodes as points, tagged ways as lines or areas, and selected relations as polygon features. It does not contain ready-made tiles; the generator builds them from the source objects. See Tilegen inputs and output sinks for the shared source and archive contracts.

The source configuration names the PBF file and the tag keys that layers may read. Every exposed tag is a string value, while osm_type identifies the object kind. A missing or empty tag behaves as null. This fixed tag set is part of the plan contract, so a layer cannot safely read a tag that the source does not declare.

OSM objectTile featureFeature identity
Tagged nodePointOSM id multiplied by 10, plus 1
Tagged wayLine, or polygon when it is a closed areaOSM id multiplied by 10, plus 2
multipolygon or boundary relationPolygon or multipolygonOSM id multiplied by 10, plus 3

The reader reconstructs ways and relations from node locations in the extract. It omits untagged objects, unsupported relations, and incomplete geometries. It can keep node locations in memory for smaller inputs or use temporary storage for larger inputs, which lets the same PBF support several output layers without rebuilding those locations for each layer.

References: docs/…/sources-osm.md• L10-16 docs/…/sources-osm.md• L53-70 martin-tilegen/…/mod.rs• L41-58 martin-tilegen/…/mod.rs• L554-588 martin-tilegen/…/mod.rs• L825-947

Shortbread-style plans

A Shortbread-style plan is a layer schema that turns OSM tags into map-ready layers and attributes. It expresses which objects belong to each layer, when they appear, which geometry form they use, and which output attributes a style can draw. The plan is the bridge between raw OSM tagging and the archive's stable vector-layer contract.

The plan commonly separates map features into water, land, boundaries, roads, labels, buildings, transport, and points of interest. One OSM object may feed several layers. Each layer can use a different geometry representation, zoom range, filter, and derived attributes.

Layer conditions

Layer conditions select objects before geometry is rendered. They use OSM tags and the derived geometry kind, and they follow null-aware expression rules. A condition such as highway in [...] can select roads, while a condition that checks name can create a label layer from the same source object.

The reader uses the same condition in several stages. It first skips object kinds that no layer can accept. It can then skip PBF blocks whose string tables cannot satisfy the condition. It finally checks each object before it loads way nodes. This reduces work without changing which objects the plan accepts.

flowchart LR
    A[OSM object] --> B{Layer condition}
    B -->|does not match| C[Skip object]
    B -->|matches| D[Select geometry and zooms]
    D --> E[Compute output attributes]
    E --> F[Render into tile records]

References: martin-tilegen/…/mod.rs• L308-376 martin-tilegen/…/condition.rs• L35-116 martin-tilegen/…/condition.rs• L127-210

Layer outputs

The plan maps source tags into a smaller output schema. Literal values and expressions can create stable fields such as kind, name, name_en, or population. Zoom rules can add a field only when it is useful at that zoom, which keeps low-zoom tiles small while preserving detail at higher zooms.

The repository's Shortbread example is a port of the Planetiler Shortbread configuration. It is intended to work with VersaTiles styles, but it is not a full match for every Planetiler behavior. In particular, ocean data and area-derived fields are outside the current OSM plan, and some polygon and centroid cases differ.

References: docs/…/shortbread.yaml• L63-174 docs/…/shortbread.yaml• L175-239 docs/…/shortbread.yaml• L239-377 docs/…/recipe-osm-basemap.md• L10-28 martin-tilegen/…/condition.rs• L35-116 martin-tilegen/…/condition.rs• L127-210

Generation command

martin cp --mode bulk is the entry point for turning an OSM source and its plan into an archive. The configuration file describes the OSM source and its layers, while command options choose the output path, tile format, zoom range, spatial bound, and resource limits.

The command selects either OSM sources or database sources for a run. It lowers the source and layer settings into one generation plan, rejects sources or layers that bulk mode cannot use, creates a new output, and then scans the PBF once for the requested zoom range. A failed or interrupted run removes the output that it created.

sequenceDiagram
    participant C as martin cp
    participant P as OSM PBF
    participant L as Shortbread plan
    participant G as Tile generator
    participant A as MBTiles or PMTiles
    C->>L: Load source and layer settings
    C->>P: Open selected extract
    P->>G: Stream matching features
    L->>G: Provide filters, zooms, geometry, and fields
    G->>A: Write ordered encoded tiles
    G->>A: Finish archive metadata

The main run settings have these effects:

SettingPurpose
--formatSelects MLT or MVT tile bytes. MLT is the default.
--encodingSelects compression for the archive tiles. MLT in PMTiles must remain uncompressed.
--min-zoom, --max-zoom or --zoom-levelsDefines the continuous zoom range to render. Source and layer limits narrow it.
--bboxLimits the output to tiles that touch the requested area.
--threads, --memory, --temp-dirSet the parallel work and the temporary sort resources.

The output sink receives complete encoded tiles in its required archive order. After tile work ends, generated layer fields and zoom statistics become the archive's vector-layer metadata. Read Tilegen pipeline and plans for the shared render, sort, and write stages and Tilegen inputs and output sinks for archive behavior.

References: docs/…/sources-osm.md• L12-41 docs/…/martin-generate.md• L28-40 docs/…/martin-generate.md• L88-175 martin/…/osm.rs• L17-61 martin/…/osm.rs• L64-107 martin/…/mod.rs• L342-375 martin/…/mod.rs• L433-476

MLT conversion

MLT is a column-based vector tile format that can be written during generation. When the requested format is MLT, phase two assembles each layer and encodes its features directly as MLT before applying the archive's allowed tile encoding. This avoids a later MVT-to-MLT conversion step.

The convert_to_mlt setting supplies source-level encoder choices for bulk generation. An explicit setting changes the MLT encoder configuration. auto or an unset value uses the generator's normal defaults. A source cannot disable MLT while the command writes MLT; use --format mvt if the source must produce MVT.

MLT output is useful for archives that will serve MLT to clients. Martin can also convert an existing MVT tile to MLT at serve time, but generation-time MLT avoids that per-request work. The reverse path is available when an MLT archive must serve MVT to a client that does not support MLT.

References: docs/…/martin-generate.md• L133-156 docs/…/mlt.md• L13-20 docs/…/mlt.md• L118-154 docs/…/mlt.md• L156-170 martin/…/mod.rs• L117-131 martin/…/mod.rs• L589-619 martin/…/mod.rs• L777-793 martin-tilegen/…/encode.rs• L281-328 martin/…/to_mlt.rs• L10-41

Change checklist

When these files or sections are changed, remember to consider these:

  • Keep the declared OSM tag set aligned with every condition and attribute expression in the Shortbread plan. An undeclared tag can make a run fail or remove a needed field.
  • Keep OSM object classification aligned with layer geometry conditions. A change to area rules can move a closed way between line and polygon layers.
  • Keep relation assembly aligned with feature selection. A condition that admits a relation must still have all required member ways and node locations available.
  • Keep the bulk format, encoder setting, and archive encoding rules aligned. MLT in PMTiles must remain uncompressed.
  • Keep the generated vector-layer metadata aligned with the fields that the MLT or MVT encoder actually emits.
  • Keep Shortbread compatibility notes aligned with the plan and its review specs when layer geometry or zoom rules change.

Important failure modes

TriggerConsequenceGuard
A layer reads a tag that is not in tagsPlan evaluation cannot provide the expected valueAdd the tag key to the source declaration before using it
A way or relation lacks a referenced node or member wayThe incomplete feature is omittedUse a complete extract and check source warnings
An OSM source is selected with database sourcesBulk source selection stopsRun OSM sources separately from database sources
No OSM layer intersects the requested zoom rangeGeneration stops without an archiveSet compatible source, layer, and command zoom limits
MLT is disabled while the command selects MLT outputConfiguration is rejected before generationSelect MVT or enable MLT for the run
Compressed MLT is requested for PMTilesPMTiles creation is rejectedUse uncompressed MLT or choose MVT
The PBF contains unsupported or malformed dataSource reading stops or affected geometries are skippedValidate the extract and review the generation summary

Key files

FileWhy to read it
docs/…/sources-osm.mdUser-facing OSM source model, object mapping, filtering, and node storage behavior.
docs/…/shortbread.yamlThe Shortbread-style layer schema and its conditions, zoom rules, and output fields.
docs/…/recipe-osm-basemap.mdThe end-to-end OSM basemap goal and known Shortbread differences.
martin/…/osm.rsThe source-level configuration contract for PBF paths, tags, zooms, and layers.
martin/…/osm.rsThe handoff from OSM configuration to the bulk generation plan.
martin-tilegen/…/mod.rsThe OSM feature stream and conversion from PBF objects to tilegen features.
martin-tilegen/…/condition.rsThe condition behavior used for OSM pushdown and object selection.
martin/…/mod.rsThe bulk command lifecycle, output creation, MLT choices, and cleanup.
martin-tilegen/…/encode.rsThe final per-layer encoding path for MLT and MVT tiles.
martin/…/osm_shortbread_test.rsThe compatibility checks for Shortbread example outputs and Monaco row cases.