Table of Contents

Class MvtTileBuilder

Namespace
SpatialNET.IO
Assembly
SpatialNET.IO.dll

Builds one vector tile of any tile grid from world geometries: each geometry is clipped to the tile plus buffer, simplified (about one pixel), transformed to tile coordinates, rounded to integers, cleaned of repeated points and degenerate parts and its rings oriented as MVT requires (exterior clockwise on screen, i.e. positive area in tile coordinates with y down; interior rings opposite). Multipolygons are written part by part, each exterior ring followed by its holes.

public sealed class MvtTileBuilder

Inheritance

Inherited Members

Remarks

Rounding to integers can make a valid polygon touch or cross itself at sub-unit features; this is the usual MVT trade-off and renderers handle it. Layers keep the order of their first feature; layers without features are not written.

Constructors

MvtTileBuilder(TileGrid, int, long, long, MvtTileOptions?)

Creates a builder for a tile of a grid.

public MvtTileBuilder(TileGrid grid, int level, long row, long column, MvtTileOptions? options = null)

Parameters

grid TileGrid

The tile grid.

level int

The level.

row long

The row.

column long

The column.

options MvtTileOptions?

The options; null = SpatialNET.IO.MvtTileOptions.Default.

Exceptions

ArgumentNullException

grid is null.

ArgumentOutOfRangeException

level is not a level of the grid, or an option is out of range.

Properties

ClipEnvelope

The world envelope geometries are clipped to: the tile plus buffer.

public Envelope2D ClipEnvelope { get; }

Property Value

Envelope2D

IsEmpty

Whether no feature has been added yet.

public bool IsEmpty { get; }

Property Value

bool

Transform

The mapping between world and tile coordinates of this tile.

public MvtTileTransform Transform { get; }

Property Value

MvtTileTransform

Methods

AddFeature(string, IGeometry2D, IEnumerable<KeyValuePair<string, object?>>?, ulong?)

Adds a feature in world coordinates to a layer (created on first use).

public bool AddFeature(string layerName, IGeometry2D geometry, IEnumerable<KeyValuePair<string, object?>>? attributes = null, ulong? id = null)

Parameters

layerName string

The layer name.

geometry IGeometry2D

The geometry in world coordinates of the grid's CRS.

attributes IEnumerable<KeyValuePair<string, object?>>?

The attributes; null values are skipped, a repeated key keeps its first value.

id ulong?

The feature id (typically the object id) or null.

Returns

bool

true if the feature was added; false if nothing of the geometry is left in the tile.

Exceptions

ArgumentNullException

layerName or geometry is null.

NotSupportedException

geometry is not a known geometry kind.

Build()

The tile with all non-empty layers.

public MvtTile Build()

Returns

MvtTile

ToBytes(bool)

The encoded tile.

public byte[] ToBytes(bool gzip = false)

Parameters

gzip bool

Whether to gzip the bytes; default false.

Returns

byte[]

ToTileGeometry(IGeometry2D, IGeometryFactory?)

The tile-coordinate geometry a world geometry becomes in this tile (clipped, simplified, rounded and oriented as for SpatialNET.IO.MvtTileBuilder.AddFeature(System.String,SpatialNET.IGeometry2D,System.Collections.Generic.IEnumerable{System.Collections.Generic.KeyValuePair{System.String,System.Object}},System.Nullable{System.UInt64})), or null if nothing is left.

public IGeometry2D? ToTileGeometry(IGeometry2D geometry, IGeometryFactory? factory = null)

Parameters

geometry IGeometry2D

The geometry in world coordinates.

factory IGeometryFactory?

The factory for the result; null = SpatialNET.GeometryFactory.Default.

Returns

IGeometry2D?

Exceptions

ArgumentNullException

geometry is null.

NotSupportedException

geometry is not a known geometry kind.

InvalidOperationException

No factory available.