Table of Contents

Class Mvt

Namespace
SpatialNET.IO
Assembly
SpatialNET.IO.dll

Encoding and decoding of Mapbox Vector Tiles (MVT 2.1, https://github.com/mapbox/vector-tile-spec) with a hand-written protobuf codec, plus gzip helpers. Geometry in a tile is in integer tile coordinates; SpatialNET.IO.MvtTileBuilder converts world coordinates of any tile grid.

public static class Mvt

Inheritance

Mvt

Inherited Members

Remarks

Field order on writing follows the common reference encoders: layer = version, name, features, keys, values, extent; feature = id (if set), tags (if any), type, geometry (if any). Keys and values are deduplicated per layer in order of first use. Reading accepts any field order, packed and unpacked repeated fields, skips unknown fields and decompresses gzip input automatically.

Methods

Decode(ReadOnlySpan<byte>)

Decodes a tile; gzip-compressed input is decompressed first.

public static MvtTile Decode(ReadOnlySpan<byte> data)

Parameters

data ReadOnlySpan<byte>

The tile bytes.

Returns

MvtTile

Exceptions

FormatException

The data is not a valid vector tile; the message names the byte offset.

Encode(MvtTile)

Encodes the tile into protobuf bytes (not compressed).

public static byte[] Encode(MvtTile tile)

Parameters

tile MvtTile

The tile.

Returns

byte[]

Exceptions

ArgumentNullException

tile is null.

ArgumentException

Two layers have the same name.

Gunzip(ReadOnlySpan<byte>)

Decompresses gzip bytes.

public static byte[] Gunzip(ReadOnlySpan<byte> data)

Parameters

data ReadOnlySpan<byte>

The compressed bytes.

Returns

byte[]

Exceptions

FormatException

The data is not valid gzip.

Gzip(ReadOnlySpan<byte>, CompressionLevel)

Compresses bytes with gzip (as tiles are commonly stored and served with Content-Encoding: gzip).

public static byte[] Gzip(ReadOnlySpan<byte> data, CompressionLevel level = CompressionLevel.Optimal)

Parameters

data ReadOnlySpan<byte>

The bytes.

level CompressionLevel

The compression level; default System.IO.Compression.CompressionLevel.Optimal.

Returns

byte[]

IsGzip(ReadOnlySpan<byte>)

Whether the bytes start with the gzip magic number (0x1F 0x8B).

public static bool IsGzip(ReadOnlySpan<byte> data)

Parameters

data ReadOnlySpan<byte>

The bytes.

Returns

bool