[][src]Crate mvt

A library for encoding mapbox vector tiles (MVT).

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, Transform};

fn main() -> Result<(), Error> {
    let mut tile = Tile::new(4096);
    let layer = tile.create_layer("First Layer");
    let b = GeomEncoder::new(GeomType::Linestring, Transform::new())
                        .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(())
}

Structs

BBox

A bounding box is an axis-aligned rectangle. It is defined by two corners: north_west and south_east.

Feature

Features contain map geometry with related metadata.

GeomData

Validated geometry data for Features. Use GeomEncoder to encode.

GeomEncoder

Encoder for Feature geometry. This can consist of Point, Linestring or Polygon data.

Layer

A layer is a set of related features in a tile.

MapGrid

A map grid is used to address tiles on a map. The grid should be in projected coördinates.

Tile

A tile represents a rectangular region of a map. Each tile can contain any number of layers. When all layers have been added to the tile, it can be written out or converted to a Vec<u8>.

TileId

A tile ID identifies a tile on a map grid at a specific zoom level. It uses XYZ addressing, with X increasing from west to east and Y increasing from north to south. The X and Y values can range from 0 to 2Z-1.

Transform

An affine transform can translate, scale, rotate and skew 2D points.

Vec2

2-dimensional vector / point.

Enums

Error

MVT Error types

GeomType

Geometry types for Features.