Java core codec
The Java core codec turns layered feature data into MapLibre Tile (MLT) bytes and turns those bytes back into a tile object. It is the codec layer under the Java tile library and supplies the processing used by the Java CLI and tools. It keeps geometry, IDs, and properties aligned through shared schema and stream metadata, while shared Java resources provide compression, geometry, and optional native string coding.
Tile data model
The tile model presents an MLT tile as ordered layers. Each layer has a name, a coordinate extent, and features with optional IDs, JTS geometry, and typed properties. The model accepts both simple scalar values and nested map values so the codec can represent data that is richer than a basic vector tile. java/…/MapLibreTile.java• L7-17 java/…/Layer.java• L7-15 java/…/Feature.java• L16-30
Feature properties
Properties carry a name, a schema type, and a value. Scalar properties use the supported numeric, Boolean, or string types. Map properties carry nested values and let MLT features preserve nested data. java/…/Property.java• L8-35 java/…/MLTFeature.java• L13-46
References: java/…/Property.java• L8-35 java/…/MLTFeature.java• L13-46
Schema and stream metadata
The codec uses two related descriptions of encoded data. Tile-set metadata describes each layer's columns and field types. Embedded feature-table metadata repeats the layer name, extent, and column shape inside each encoded layer so a decoder can read a tile without an external schema. java/…/MltMetadata.java• L39-67 java/…/MltConverter.java• L487-515
Fields describe scalar or complex types and whether values can be null. Top-level columns use feature scope in the current encoder. Geometry is required for an encoded feature table. IDs are represented as a logical field that selects 32-bit or 64-bit storage. java/…/MltMetadata.java• L85-107 java/…/MltConverter.java• L182-208
Stream metadata describes how each value stream is stored. It records the stream role, logical transforms such as delta or run-length coding, the physical codec, the value count, and the byte length. The decoder reads this description before it reads each stream, so the same stream contract connects encoding and decoding. java/…/StreamMetadata.java• L10-18 java/…/StreamMetadata.java• L79-107
References: java/…/MltMetadata.java• L85-107 java/…/MltConverter.java• L487-515 java/…/StreamMetadata.java• L10-18 java/…/StreamMetadata.java• L79-107
Encoding flow
Encoding combines source layers with tile-set metadata and conversion settings. The converter filters usable features, encodes geometry first, encodes IDs and property columns in the resulting feature order, then writes embedded metadata and a version tag around each layer body. This keeps every column aligned to the same feature sequence. java/…/MltConverter.java• L528-553 java/…/MltConverter.java• L625-743
The high-level sequence is:
- Build or receive column metadata for each layer.
- Select features that have usable geometry.
- Encode geometry and decide the feature order.
- Encode IDs and property columns in that order.
- Add the layer name, extent, column metadata, stream metadata, and stream bytes.
- Prefix the layer body with its length and format tag.
This diagram shows how source data becomes a self-describing tile.
flowchart LR
A[LayerSource] --> B[Feature and column metadata]
B --> C[Geometry column]
C --> D[Aligned ID and property columns]
D --> E[Embedded layer metadata]
E --> F[Length and version tag]
F --> G[MLT tile bytes]
References: java/…/MltConverter.java• L528-553 java/…/MltConverter.java• L625-743
Geometry columns
Geometry encoding flattens supported point, line, and polygon forms into geometry types, counts, offsets, and vertex data. It delta-encodes vertex coordinates and can select plain vertices, a vertex dictionary, or Morton-ordered dictionary data based on encoded size. Polygon pre-tessellation adds triangle and index streams when enabled. java/…/GeometryEncoder.java• L70-79 java/…/GeometryEncoder.java• L125-181
The geometry settings also control feature sorting and optional polygon outlines. If geometry sorting changes the order, the converter rebuilds the feature sequence before it writes IDs and properties. java/…/MltConverter.java• L770-846
References: java/…/GeometryEncoder.java• L70-79 java/…/GeometryEncoder.java• L125-181 java/…/MltConverter.java• L770-846
Property columns
Property encoding writes one column per schema entry. Nullable columns use a presence stream so the value stream can stay dense. Integer columns use plain, delta, run-length, or combined delta and run-length forms. String columns choose among plain, dictionary, and optional FSST dictionary forms by encoded size. java/…/PropertyEncoder.java• L67-119 java/…/PropertyEncoder.java• L426-471
Nested map columns use the MLT version-2 tag. Struct columns currently use shared dictionary encoding for nested string fields. The conversion policy controls whether mismatched values fail, become strings, or are omitted from the encoded column. java/…/PropertyEncoder.java• L73-114 java/…/ConversionConfig.java• L48-69
References: java/…/PropertyEncoder.java• L67-119 java/…/PropertyEncoder.java• L426-471 java/…/ConversionConfig.java• L48-69
Decoding flow
Decoding reads the tile as a sequence of length-delimited layer blocks. It accepts the supported format tags, reads each layer's embedded schema and extent, then decodes columns into geometry, IDs, and property lists before rebuilding features and layers. Unknown layer tags are skipped so the reader can move past unsupported blocks. java/…/MltDecoder.java• L31-62
The decoder processes columns in schema order. It expands dense nullable streams with presence bits, reconstructs geometry from counts and vertex data, and merges each property list by feature position. The result is a MapLibreTile with MLTFeature instances rather than raw stream buffers. java/…/MltDecoder.java• L66-157
This diagram shows how self-describing bytes return to the tile model.
flowchart LR
A[MLT tile bytes] --> B[Layer length and tag]
B --> C[Embedded schema and extent]
C --> D[Geometry, ID, and property streams]
D --> E[Feature-position alignment]
E --> F[MLTFeature objects]
F --> G[MapLibreTile]
References: java/…/MltDecoder.java• L31-62 java/…/MltDecoder.java• L66-157
Geometry reconstruction
Geometry decoding reverses the geometry column contract. It reads geometry types and optional count, offset, triangle, and vertex streams, then rebuilds JTS points, lines, polygons, and multi-geometries. Plain and dictionary vertex layouts use the same geometry counts to restore feature shapes. java/…/GeometryDecoder.java• L38-121 java/…/GeometryDecoder.java• L123-151
Pre-tessellated polygon data needs outline streams when the decoder must rebuild polygon rings. Without those outlines, triangle data alone cannot restore the original polygon shape. java/…/GeometryDecoder.java• L144-151
References: java/…/GeometryDecoder.java• L38-121 java/…/GeometryDecoder.java• L123-151
Property reconstruction
Property decoding reads the type and stream metadata, restores scalar values, and uses presence streams to put nulls back in their original feature positions. String decoding supports plain, dictionary, and FSST dictionary layouts. Map columns return per-feature nested values, while current struct support focuses on nested strings. java/…/PropertyDecoder.java• L16-34 java/…/PropertyDecoder.java• L63-143 java/…/StringDecoder.java• L154-232
References: java/…/PropertyDecoder.java• L16-34 java/…/PropertyDecoder.java• L63-143 java/…/StringDecoder.java• L154-232
Round-trip validation
Round-trip validation checks that decoded MLT content still matches its source vector-tile content. The comparison can focus on layers, geometry, properties, or all content. It ignores empty layers and can filter layers by name, which lets large fixture checks target the data under review. java/…/CompareHelper.java• L27-33 java/…/CompareHelper.java• L70-133
The comparison accounts for codec ordering rules. Features with IDs can match even when their input order differs because both sides use stable ID order. Features without IDs keep their relative order. Geometry comparison accepts equivalent polygon topology, while property comparison treats null values as absent and accepts numeric values with the same text form. java/…/CompareHelper.java• L152-188 java/…/CompareHelper.java• L222-275
The decoder tests apply this check to every MVT fixture in both plain and advanced encoding modes. The advanced path combines integer compression, string compression, and polygon tessellation, while outline data remains available for polygon reconstruction. java/…/MltDecoderTest.java• L27-52 java/…/MltDecoderTest.java• L54-95
References: java/…/CompareHelper.java• L27-33 java/…/CompareHelper.java• L70-133 java/…/CompareHelper.java• L152-188 java/…/CompareHelper.java• L222-275 java/…/MltDecoderTest.java• L27-95
Shared resources
The core codec relies on shared Java resources for geometry objects, integer compression, stream metadata, and optional native string compression. These resources are part of the codec contract because their type names and encoded stream choices must match on both sides of a round trip. java/…/build.gradle• L16-28
Compression resources
Integer streams use varints by default and can use FastPFOR for 32-bit data. Strings can use a Java FSST path by default or a native FSST path when the native wrapper is selected. The native path loads FsstWrapper.so, which is built from the shared CMake resource and the external FSST library. java/…/IntegerEncoder.java• L451-529 java/…/FsstEncoder.java• L3-35 java/…/CMakeLists.txt• L41-73
The native wrapper is optional for normal Java string decoding because the Java FSST implementation can decode the shared symbol-table format. Native loading mainly affects encoding choice and requires the expected build output and platform setup. java/…/FsstJni.java• L5-40 java/resources/compile#L1-L15
References: java/…/build.gradle• L16-28 java/…/IntegerEncoder.java• L451-529 java/…/FsstEncoder.java• L3-35 java/…/CMakeLists.txt• L41-73 java/…/FsstJni.java• L5-40 java/…/compile• L1-15
Change checklist
When these files or sections are changed, remember to consider these:
- Keep
MltTypeMaptype tags, embedded metadata writing, and metadata parsing aligned. A tag change affects both the layer header and its child-field rules. - Keep stream count rules aligned between each encoder and its decoder. This is especially important for nullable strings, shared dictionaries, maps, and geometry columns.
- Keep feature ordering changes in
MltConverterpaired with ID and property-column ordering. A new geometry sort must preserve row alignment. - Keep round-trip comparison ordering aligned with encoder ordering. Features without IDs must retain their relative order, while ID-bearing features must remain matchable by stable ID order.
- Keep FSST symbol lengths, dictionary lengths, compressed corpus length, and
Fsstdecode input in the same order. - Keep native wrapper output and
FsstJniclass or library paths aligned when changing the shared resource build.
Important failure modes
| Trigger | Consequence | Guard |
|---|---|---|
| A layer has no matching tile-set metadata | Encoding stops with a missing metadata error | Create metadata for every source layer before encoding |
| A feature table has no usable geometry | The layer is skipped during tile encoding | Supply non-empty supported JTS geometry |
| A non-nullable property is absent or has an incompatible type | Encoding can assert, fail, coerce, or elide based on policy | Use metadata that matches source values or choose an explicit mismatch policy |
| A nullable stream count does not match the field nullability | Property decoding rejects the column or misreads later streams | Preserve encoder and decoder stream-count rules |
| Pre-tessellated polygons omit outline streams | Geometry decoding cannot rebuild polygon rings | Encode outlines when decoded polygon geometry is required |
| Feature order changes for rows without IDs | Round-trip comparison reports a mismatch even when the feature set is the same | Preserve relative order for features without IDs |
| The native FSST library is not built at the expected path | Native FSST loading fails and native encoding is unavailable | Run the shared resource compile step or use the Java FSST path |
Key files
| File | Why to read it |
|---|---|
| java/…/MapLibreTile.java | Top-level tile container and layer access |
| java/…/Feature.java | Shared feature contract for IDs, geometry, and properties |
| java/…/MLTFeature.java | MLT feature form with nested property support |
| java/…/MltMetadata.java | Shared schema model for layers, columns, fields, and types |
| java/…/MltConverter.java | Main metadata, embedded-header, and tile encoding flow |
| java/…/GeometryEncoder.java | Geometry column choices and vertex representation |
| java/…/PropertyEncoder.java | Scalar, string, map, and struct property encoding |
| java/…/MltDecoder.java | Tile and layer decoding flow |
| java/…/GeometryDecoder.java | Geometry stream reconstruction |
| java/…/PropertyDecoder.java | Scalar and complex property reconstruction |
| java/…/StreamMetadata.java | Stream header contract used by encoders and decoders |
| java/…/CompareHelper.java | MLT and MVT round-trip comparison rules |
| java/…/MltDecoderTest.java | Fixture-wide checks for plain and advanced codec paths |
| java/…/build.gradle | Core dependencies and Java runtime integration |
| java/…/CMakeLists.txt | Native FSST resource build and linkage |