Mapbox Vector Tile

2.2.0 · active · verified Thu Apr 16

Mapbox Vector Tile (MVT) is a Python library for encoding and decoding Mapbox Vector Tiles. It is currently at version 2.2.0 and receives active maintenance releases, typically addressing dependency updates and minor improvements. MVTs are an efficient format for tiled vector data, commonly used in web mapping applications for performant rendering.

Common errors

Warnings

Install

Imports

Quickstart

Demonstrates encoding a simple GeoJSON-like structure (using WKT geometries) into a Mapbox Vector Tile and then decoding it back. The `encode` method expects a list of layer dictionaries, each containing a name and a list of features with geometry (WKT, WKB, or Shapely object) and properties. The `decode` method returns a dictionary where keys are layer names and values are the decoded layer data.

import mapbox_vector_tile

# Example GeoJSON-like data structure for a layer
layer_data = {
    "name": "water",
    "features": [
        {
            "geometry": "POLYGON ((0 0, 0 1, 1 1, 1 0, 0 0))", # WKT geometry
            "properties": {"uid": 123, "foo": "bar"}
        },
        {
            "geometry": "LINESTRING(-71.160281 42.258729,-71.160837 42.259113)", # WKT geometry
            "properties": {"id": 456, "type": "river"}
        }
    ]
}

# Encode to MVT (bytes)
encoded_tile = mapbox_vector_tile.encode([layer_data])
print(f"Encoded tile size: {len(encoded_tile)} bytes")

# Decode MVT (returns dictionary of layers)
decoded_layers = mapbox_vector_tile.decode(encoded_tile)

# Accessing decoded data
print(f"Decoded layers: {list(dec_layers.keys())}")
water_layer = decoded_layers.get('water')
if water_layer:
    print(f"First feature in 'water' layer: {water_layer['features'][0]['properties']}")

view raw JSON →