Crate mvt

source ·
Expand description

A library for encoding mapbox vector tiles.

A tile is composed of one or more layers. Each layer can have any number of features, which contain the geometry to be rendered. They can also have metadata tags, which are key/value pairs.


use mvt::{Error, GeomEncoder, GeomType, Tile};
use pointy::Transform;

fn main() -> Result<(), Error> {
    let mut tile = Tile::new(4096);
    let layer = tile.create_layer("First Layer");
    // NOTE: normally, the Transform would come from MapGrid::tile_transform
    let b = GeomEncoder::new(GeomType::Linestring)
        .point(0.0, 0.0)?
        .point(1024.0, 0.0)?
        .point(1024.0, 2048.0)?
        .point(2048.0, 2048.0)?
        .point(2048.0, 4096.0)?
    let mut feature = layer.into_feature(b);
    feature.add_tag_string("key", "value");
    let layer = feature.into_layer();
    let data = tile.to_bytes()?;
    println!("encoded {} bytes: {:?}", data.len(), data);


  • A Feature contains map geometry with related metadata.
  • Validated geometry data for Features.
  • Encoder for Feature geometry.
  • A layer is a set of related features in a tile.
  • A map grid is used to address tiles on a map.
  • A tile represents a rectangular region of a map.
  • A tile ID identifies a tile on a map grid at a specific zoom level.
  • Web mercator (EPSG:3857) position.
  • WGS-84 (EPSG:4326) position.