Mapbox Vector Tiles¶
Prepare, encode and decode vector tiles, reuse indexed sources, and generate addressed tiles.
Related: Vector-tile guide
Types¶
TileBounds
¶
Accepted call forms
TileBounds(
bounds: Iterable[float], *, space: Space | None = None
) -> TileBounds
A tile rectangle and the coordinate frame in which it is expressed.
Define a rectangular tile coordinate frame.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
bounds
|
Iterable[float]
|
The |
required |
space
|
Space | None
|
Complete planar interpretation of the bounds. Omission means an unreferenced plane. A geographic CRS is valid with the planar model; chart and spherical models are not affine tile frames. |
None
|
Returns:
| Type | Description |
|---|---|
TileBounds
|
The immutable tile rectangle and its coordinate frame. |
Raises:
| Type | Description |
|---|---|
TypeError
|
If |
GeometryError
|
If the Space is not Planar or the bounds do not define a rectangle with positive width and height. |
bounds
property
¶
bounds: tuple[float, float, float, float]
The frame rectangle.
Returns:
| Type | Description |
|---|---|
tuple of float
|
Bounds as |
MVTLayer
¶
Accepted call forms
MVTLayer(features: Features, *, extent: SupportsIndex = 4096) -> MVTLayer
An immutable feature snapshot in an MVT-local integer grid.
Create a layer from geometry already in the local integer grid.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
features
|
Features
|
Local geometries, supported scalar properties, and optional unsigned integer IDs. Missing and empty geometries are omitted. |
required |
extent
|
SupportsIndex
|
Positive integer width and height of the tile grid. |
4096
|
Returns:
| Type | Description |
|---|---|
MVTLayer
|
The immutable local layer. |
extent
property
¶
extent: int
The tile-grid extent.
Returns:
| Type | Description |
|---|---|
int
|
Integer width and height of the grid. |
features
property
¶
The layer's feature snapshot.
Returns:
| Type | Description |
|---|---|
Features
|
Local geometry, sparse properties and optional IDs. |
version
property
¶
version: int
The MVT wire version.
Returns:
| Type | Description |
|---|---|
int
|
The version number, always 2. |
to_features
¶
Accepted call forms
to_features(
*,
tile: Tile,
target_space: Space | None = None,
tolerance: float | None = None,
unit: Literal['meters'] | None = None,
) -> Features[Geometry, str | bool | int | float | None, int]
to_features(
*,
frame: TileBounds,
target_space: Space | None = None,
tolerance: float | None = None,
unit: Literal['meters'] | None = None,
) -> Features[Geometry, str | bool | int | float | None, int]
Locate local coordinates in an XYZ tile or custom frame.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
tile
|
Tile
|
XYZ address in Web Mercator. Supply exactly one of |
None
|
frame
|
TileBounds
|
Custom rectangle and complete planar Space. |
None
|
target_space
|
Space or None
|
Additional shape conversion after affine placement in the tile or
frame Space. Omission retains that Space. An explicit target owns
its complete CRS, model and epoch; |
None
|
tolerance
|
float or None
|
Positional objective for shape conversion, in the target Space's
natural units unless |
None
|
unit
|
'meters'
|
Unit for the conversion objective, with the ordinary |
'meters'
|
Returns:
| Type | Description |
|---|---|
Features
|
Located geometries with the layer's properties and IDs. |
Raises:
| Type | Description |
|---|---|
CRSError
|
If the requested coordinate transformation cannot be performed. |
GeometryError
|
If the located geometry cannot be represented. |
MVTSource
¶
Accepted call forms
An immutable original feature source with reusable spatial selection.
Snapshot and index a feature collection for repeated tile preparation.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
features
|
Features | Iterable[Features]
|
Input features or batches. Batches are consumed once. |
required |
target_space
|
Space | None
|
Complete planar preparation Space. Omission means planar EPSG:3857 without an epoch, as required by XYZ tiles. Source geometries retain their original Spaces until actual conversion. |
None
|
coverage
|
bool
|
Treat the source as a polygonal coverage and validate it jointly. |
False
|
options
|
Unpack[PrepareOptions]
|
Preparation settings: |
not applicable
|
Returns:
| Type | Description |
|---|---|
MVTSource
|
The original snapshot and reusable source index. |
Raises:
| Type | Description |
|---|---|
CRSError
|
If source and target CRS metadata do not admit the requested coordinate operation. |
GeometryError
|
If an input geometry or declared coverage is invalid. |
with_options
¶
with_options(**options: Unpack[TileOptions]) -> MVTSource
Return another tile policy sharing the source and spatial index.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
**options
|
Unpack[TileOptions]
|
Replacement |
{}
|
Returns:
| Type | Description |
|---|---|
MVTSource
|
A source sharing the indexed snapshot with the new tile policy. |
Functions¶
mvt_prepare
¶
Accepted call forms
mvt_prepare(
features: Features | Iterable[Features],
*,
tile: Tile,
**options: Unpack[PrepareOptions],
) -> MVTLayer
mvt_prepare(
features: Features | Iterable[Features],
*,
frame: TileBounds,
**options: Unpack[PrepareOptions],
) -> MVTLayer
mvt_prepare(features: MVTSource, *, frame: TileBounds) -> MVTLayer
Prepare feature geometry on a tile's integer grid.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
features
|
Features, MVTSource or iterable of Features
|
Features, a reusable indexed source, or batches of features. |
required |
tile
|
Tile
|
XYZ address. Supply exactly one of |
None
|
frame
|
TileBounds
|
Custom tile frame. |
None
|
**options
|
Any
|
Preparation settings for ordinary features: |
{}
|
Returns:
| Type | Description |
|---|---|
MVTLayer
|
Prepared local integer geometry and aligned properties and IDs. |
Notes
Coordinate conversion uses the original geometry's Space and a positional
objective of 0.1 continuous grid units for this tile, before integer rounding
and optional simplification. drop_zm=True permits Z/M loss in the tile;
physical source Z still participates in coordinate conversion.
to_mvt
¶
Accepted call forms
to_mvt(
values: Features | Iterable[Features],
*,
layer: str,
tile: Tile,
**options: Unpack[PrepareOptions],
) -> bytes
to_mvt(
values: Features | Iterable[Features],
*,
layer: str,
frame: TileBounds,
**options: Unpack[PrepareOptions],
) -> bytes
to_mvt(
values: Mapping[str, Features | Iterable[Features]],
*,
tile: Tile,
**options: Unpack[PrepareOptions],
) -> bytes
to_mvt(
values: Mapping[str, Features | Iterable[Features]],
*,
frame: TileBounds,
**options: Unpack[PrepareOptions],
) -> bytes
to_mvt(values: MVTSource, *, layer: str, frame: TileBounds) -> bytes
to_mvt(
values: Mapping[str, Features | Iterable[Features] | MVTSource],
*,
frame: TileBounds,
) -> bytes
to_mvt(values: MVTLayer, *, layer: str) -> bytes
to_mvt(values: Mapping[str, MVTLayer]) -> bytes
Prepare and encode feature data as an uncompressed vector tile.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
values
|
(MVTLayer, Features, MVTSource, iterable or mapping)
|
A single layer or a mapping of names to layer inputs. Ordinary features are prepared in the supplied tile or frame; local layers are encoded directly. |
required |
layer
|
str
|
Name of a single layer. Omit for a mapping of layers. |
None
|
tile
|
Tile
|
XYZ address used to prepare ordinary or source features. |
None
|
frame
|
TileBounds
|
Custom tile frame, mutually exclusive with |
None
|
**options
|
Any
|
Preparation settings for ordinary features; see |
{}
|
Returns:
| Type | Description |
|---|---|
bytes
|
Uncompressed MVT data. |
from_mvt
¶
Accepted call forms
from_mvt(
data: Buffer,
*,
layer: str,
properties: Iterable[str] | None = None,
target_space: None = None,
) -> MVTLayer
from_mvt(
data: Buffer,
*,
layers: Iterable[str] | None = None,
properties: Iterable[str] | None = None,
target_space: None = None,
) -> dict[str, MVTLayer]
from_mvt(
data: Buffer,
*,
layer: str,
tile: Tile,
properties: Iterable[str] | None = None,
target_space: Space | None = None,
tolerance: float | None = None,
unit: Literal['meters'] | None = None,
) -> Features[Geometry, str | bool | int | float | None, int]
from_mvt(
data: Buffer,
*,
layer: str,
frame: TileBounds,
properties: Iterable[str] | None = None,
target_space: Space | None = None,
tolerance: float | None = None,
unit: Literal['meters'] | None = None,
) -> Features[Geometry, str | bool | int | float | None, int]
from_mvt(
data: Buffer,
*,
tile: Tile,
layers: Iterable[str] | None = None,
properties: Iterable[str] | None = None,
target_space: Space | None = None,
tolerance: float | None = None,
unit: Literal['meters'] | None = None,
) -> dict[str, Features[Geometry, str | bool | int | float | None, int]]
from_mvt(
data: Buffer,
*,
frame: TileBounds,
layers: Iterable[str] | None = None,
properties: Iterable[str] | None = None,
target_space: Space | None = None,
tolerance: float | None = None,
unit: Literal['meters'] | None = None,
) -> dict[str, Features[Geometry, str | bool | int | float | None, int]]
Decode raw MVT bytes into local or located feature layers.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
data
|
buffer
|
Uncompressed MVT bytes. |
required |
layer
|
str or None
|
Select one named layer and return it directly. |
None
|
layers
|
iterable of str or None
|
Select named layers, returning a mapping. Mutually exclusive with
|
None
|
properties
|
iterable of str or None
|
Property names to retain, or |
None
|
tile
|
Tile or None
|
Locate geometries in an XYZ tile. Mutually exclusive with |
None
|
frame
|
TileBounds or None
|
Locate geometries in a custom frame. |
None
|
target_space
|
Space or None
|
Additional actual shape conversion after locating the grid in its
planar tile/frame Space. Omission retains the placement Space; an
explicit target supplies its complete model and epoch, including
clearing the placement epoch with |
None
|
tolerance
|
float or None
|
Positional objective for located shape conversion, with the ordinary
|
None
|
unit
|
'meters'
|
Unit for that objective. Omitted target retains the placement Space. |
'meters'
|
Returns:
| Type | Description |
|---|---|
(MVTLayer, Features or dict)
|
Local layers by default, or located features when a tile or frame is
supplied. A single |
Raises:
| Type | Description |
|---|---|
CRSError
|
If located geometries cannot be transformed to the requested frame. |
GeometryError
|
If decoded geometry is invalid. |
ParseError
|
If the vector tile is malformed. |
mvt_query_regions
¶
Accepted call forms
mvt_query_regions(
*, tile: Tile, extent: SupportsIndex = 4096, buffer: SupportsIndex = 64
) -> tuple[TileBounds, ...]
mvt_query_regions(
*,
frame: TileBounds,
extent: SupportsIndex = 4096,
buffer: SupportsIndex = 64,
) -> tuple[TileBounds, ...]
Return conservative preparation-Space rectangles for clipped tiles.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
tile
|
Tile
|
XYZ address. Supply exactly one of |
None
|
frame
|
TileBounds
|
Custom frame to expand. |
None
|
extent
|
int
|
Positive integer tile-grid extent. |
4096
|
buffer
|
int
|
Nonnegative tile-grid buffer. |
64
|
Returns:
| Type | Description |
|---|---|
tuple of TileBounds
|
Conservative query rectangles in the custom frame's Space, or planar EPSG:3857 for XYZ tiles. XYZ rectangles may be split at the world seam. These are not inverse-projected windows in an arbitrary dataset Space. |
mvt_tiles
¶
Accepted call forms
Generate addressed tiles lazily, or traverse nonempty tiles in zoom order.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
sources
|
mapping of str to MVTSource
|
Named layers indexed in EPSG:3857 without an epoch. |
required |
tiles
|
iterable of Tile
|
Explicit addresses to generate in input order, including empty tiles. Do not combine with a zoom range. |
None
|
min_zoom
|
int
|
First zoom level for automatic traversal. |
None
|
max_zoom
|
int
|
Last zoom level for automatic traversal. Both zoom bounds are inclusive and must lie between 0 and 29. Automatic traversal requires clipped sources and omits empty tiles. |
None
|
Returns:
| Type | Description |
|---|---|
generator of (Tile, bytes)
|
Tile addresses and their uncompressed MVT data. |