#tile #vector #gis #mapbox #cartography

bin+lib mvt

A library for encoding mapbox vector tiles

15 releases (8 breaking)

0.9.2 Jan 19, 2024
0.8.1 Mar 7, 2023
0.7.0 Sep 29, 2020
0.5.3 Oct 30, 2019
0.5.2 Feb 28, 2019

#533 in Encoding

Download history 139/week @ 2023-12-06 126/week @ 2023-12-13 114/week @ 2023-12-20 91/week @ 2023-12-27 144/week @ 2024-01-03 183/week @ 2024-01-10 178/week @ 2024-01-17 200/week @ 2024-01-24 181/week @ 2024-01-31 135/week @ 2024-02-07 144/week @ 2024-02-14 204/week @ 2024-02-21 93/week @ 2024-02-28 113/week @ 2024-03-06 83/week @ 2024-03-13 76/week @ 2024-03-20

400 downloads per month
Used in 2 crates

MIT/Apache

72KB
1.5K SLoC

mvt

A Rust library for encoding mapbox vector tiles. Decoding is not implemented.

The API is designed to prevent creating files which are not allowed by the specification.

Version 2.1 of the standard is supported.


lib.rs:

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.

Example

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)?
        .encode()?;
    let mut feature = layer.into_feature(b);
    feature.set_id(1);
    feature.add_tag_string("key", "value");
    let layer = feature.into_layer();
    tile.add_layer(layer)?;
    let data = tile.to_bytes()?;
    println!("encoded {} bytes: {:?}", data.len(), data);
    Ok(())
}

Dependencies

~2–13MB
~149K SLoC