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 MvtTileBuilderInheritance
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
gridTileGrid-
The tile grid.
levelint-
The level.
rowlong-
The row.
columnlong-
The column.
optionsMvtTileOptions?-
The options;
null= SpatialNET.IO.MvtTileOptions.Default.
Exceptions
- ArgumentNullException
-
gridisnull. - ArgumentOutOfRangeException
-
levelis 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
IsEmpty
Whether no feature has been added yet.
public bool IsEmpty { get; }Property Value
Transform
The mapping between world and tile coordinates of this tile.
public MvtTileTransform Transform { get; }Property Value
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
layerNamestring-
The layer name.
geometryIGeometry2D-
The geometry in world coordinates of the grid's CRS.
attributesIEnumerable<KeyValuePair<string, object?>>?-
The attributes;
nullvalues are skipped, a repeated key keeps its first value. idulong?-
The feature id (typically the object id) or
null.
Returns
- bool
-
trueif the feature was added;falseif nothing of the geometry is left in the tile.
Exceptions
- ArgumentNullException
-
layerNameorgeometryisnull. - NotSupportedException
-
geometryis not a known geometry kind.
Build()
The tile with all non-empty layers.
public MvtTile Build()Returns
ToBytes(bool)
The encoded tile.
public byte[] ToBytes(bool gzip = false)Parameters
gzipbool-
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
geometryIGeometry2D-
The geometry in world coordinates.
factoryIGeometryFactory?-
The factory for the result;
null= SpatialNET.GeometryFactory.Default.
Returns
Exceptions
- ArgumentNullException
-
geometryisnull. - NotSupportedException
-
geometryis not a known geometry kind. - InvalidOperationException
-
No factory available.