#cartography #gis #vector #tile #mapbox

bin+lib mvt

A library for encoding mapbox vector tiles

12 releases (7 breaking)

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

#242 in Encoding

Download history 8/week @ 2022-12-01 23/week @ 2022-12-08 7/week @ 2022-12-15 14/week @ 2022-12-22 11/week @ 2022-12-29 10/week @ 2023-01-05 19/week @ 2023-01-12 18/week @ 2023-01-19 150/week @ 2023-01-26 437/week @ 2023-02-02 299/week @ 2023-02-09 288/week @ 2023-02-16 267/week @ 2023-02-23 507/week @ 2023-03-02 695/week @ 2023-03-09 481/week @ 2023-03-16

1,996 downloads per month
Used in earthwyrm

MIT/Apache

62KB
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, Transform::default())
        .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.2–8.5MB
~164K SLoC