VectorReaderIter#
Added in version 1.2.
Superclasses: Object
Reads the layers and features of a vector tile.
To create a new VectorReaderIter
, use iterate
.
A vector tile consists of named layers, which contain features. Each feature has an ID, a geometry, and a set of key/value tags. The meanings of the IDs and tags depends on the data source that the tile came from. The OpenMapTiles schema is a common schema for vector tiles.
To read all layers in a tile, use get_layer_count
and
read_layer
. If you know the name of the layer you
want, you can also use read_layer_by_name
.
Once the iterator is reading a layer, you can call
next_feature
in a loop to read all the features in
the layer.
A VectorReaderIter
is not thread-safe, but iterators created
from the same VectorReader
can be used in different threads.
See the Mapbox Vector Tile specification for more information about the vector tile format.
Methods#
- class VectorReaderIter
- feature_contains_point(x: float, y: float) bool #
Determines whether the current feature contains the given point.
The point must be specified in tile space. See
get_layer_extent
to get the range of the coordinates.Only polygon or multipolygon features can contain a point. For all other feature types, this function returns
False
.If the point is on the border of the polygon, this function may return either
True
orFalse
.Added in version 1.2.
- Parameters:
x
y
- get_feature_geometry_type() GeometryType #
Gets the geometry type of the current feature.
Added in version 1.2.
- get_feature_keys() list[str] #
Gets the keys of the tags of the current feature.
Added in version 1.2.
- get_feature_point() Tuple[bool, float, float] #
Gets the coordinates of the current feature in tile space, if the feature is a single point.
See
get_layer_extent
to get the range of the coordinates.It is an error to call this function if the feature is not a single point. Use
get_feature_geometry_type
to check the feature’s geometry type.Added in version 1.2.
- get_feature_tag(key: str) Tuple[bool, Value] #
Gets the value of the tag with the given key.
Added in version 1.2.
- Parameters:
key – The key of the tag to get.
- get_layer_extent() int #
Gets the extent for coordinates in the current layer.
0 represents the top and left edges of the tile, and this value represents the bottom and right edges. Feature geometries may extend outside of this range, since tiles often include some margin.
Tiles do not contain metadata about the location of the tile within the world, so it is up to the caller to know the tile’s coordinates and convert latitude/longitude to tile-space coordinates.
Added in version 1.2.
- get_layer_feature_count() int #
Gets the number of features in the current layer.
You can loop over all features in the current layer by calling
read_feature
with each index from 0 to the feature count, but it might be easier to usenext_feature
instead.Added in version 1.2.
- get_reader() VectorReader #
Gets the reader that the iterator is iterating over.
Added in version 1.2.
- next_feature() bool #
Advances the iterator to the next feature in the current layer.
Added in version 1.2.
- read_feature(index: int) None #
Moves the iterator to the feature at the given index in the current layer.
You can get the number of features in the current layer with
get_layer_feature_count
.Added in version 1.2.
- Parameters:
index – The index of the feature to read.
- read_layer(index: int) None #
Sets the current layer of the reader to the layer at the given index.
Added in version 1.2.
- Parameters:
index – The index of the layer to read.
- read_layer_by_name(name: str) bool #
Moves the iterator to the layer with the given name, if present.
If the layer is not found, the current layer will be set to
None
and the function will returnFalse
. Layers are typically omitted if they are empty, so don’t assume that a layer in the schema will always be present.The iterator’s current feature will be
None
after calling this function; usenext_feature
to advance to the first feature in the layer.Added in version 1.2.
- Parameters:
name
Properties#
- class VectorReaderIter
- props.reader: VectorReader#
The type of the None singleton.