:right-sidebar: True
VectorReaderIter
===================================================================
.. currentmodule:: gi.repository.Shumate
.. versionadded:: 1.2
.. class:: VectorReaderIter(**properties: ~typing.Any)
:no-contents-entry:
Superclasses: :class:`~gi.repository.GObject.Object`
Reads the layers and features of a vector tile.
To create a new :obj:`~gi.repository.Shumate.VectorReaderIter`\, use :obj:`~gi.repository.VectorReader.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 :obj:`~gi.repository.VectorReaderIter.get_layer_count` and
:obj:`~gi.repository.VectorReaderIter.read_layer`\. If you know the name of the layer you
want, you can also use :obj:`~gi.repository.VectorReaderIter.read_layer_by_name`\.
Once the iterator is reading a layer, you can call
:obj:`~gi.repository.VectorReaderIter.next_feature` in a loop to read all the features in
the layer.
A :obj:`~gi.repository.Shumate.VectorReaderIter` is not thread-safe, but iterators created
from the same :obj:`~gi.repository.Shumate.VectorReader` can be used in different threads.
See `the Mapbox Vector Tile specification `__
for more information about the vector tile format.
Methods
-------
.. rst-class:: interim-class
.. class:: VectorReaderIter
:no-index:
.. method:: 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
:obj:`~gi.repository.VectorReaderIter.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 :const:`False`.
If the point is on the border of the polygon, this function may return
either :const:`True` or :const:`False`.
.. versionadded:: 1.2
:param x:
:param y:
.. method:: get_feature_geometry_type() -> ~gi.repository.Shumate.GeometryType
Gets the geometry type of the current feature.
.. versionadded:: 1.2
.. method:: get_feature_id() -> int
Gets the ID of the current feature.
.. versionadded:: 1.2
.. method:: get_feature_keys() -> list[str]
Gets the keys of the tags of the current feature.
.. versionadded:: 1.2
.. method:: get_feature_point() -> ~typing.Tuple[bool, float, float]
Gets the coordinates of the current feature in tile space, if the
feature is a single point.
See :obj:`~gi.repository.VectorReaderIter.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 :obj:`~gi.repository.VectorReaderIter.get_feature_geometry_type` to check
the feature's geometry type.
.. versionadded:: 1.2
.. method:: get_feature_tag(key: str) -> ~typing.Tuple[bool, ~gi.repository.GObject.Value]
Gets the value of the tag with the given key.
.. versionadded:: 1.2
:param key: The key of the tag to get.
.. method:: get_layer_count() -> int
Gets the number of layers in the vector tile.
.. versionadded:: 1.2
.. method:: 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.
.. versionadded:: 1.2
.. method:: 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
:obj:`~gi.repository.VectorReaderIter.read_feature` with each index from 0 to
the feature count, but it might be easier to use
:obj:`~gi.repository.VectorReaderIter.next_feature` instead.
.. versionadded:: 1.2
.. method:: get_layer_name() -> str
Gets the name of the current layer.
.. versionadded:: 1.2
.. method:: get_reader() -> ~gi.repository.Shumate.VectorReader
Gets the reader that the iterator is iterating over.
.. versionadded:: 1.2
.. method:: next_feature() -> bool
Advances the iterator to the next feature in the current layer.
.. versionadded:: 1.2
.. method:: 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
:obj:`~gi.repository.VectorReaderIter.get_layer_feature_count`\.
.. versionadded:: 1.2
:param index: The index of the feature to read.
.. method:: read_layer(index: int) -> None
Sets the current layer of the reader to the layer at the given index.
.. versionadded:: 1.2
:param index: The index of the layer to read.
.. method:: 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 :const:`None` and the
function will return :const:`False`. 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 :const:`None` after calling this function;
use :obj:`~gi.repository.VectorReaderIter.next_feature` to advance to the first feature
in the layer.
.. versionadded:: 1.2
:param name:
Properties
----------
.. rst-class:: interim-class
.. class:: VectorReaderIter
:no-index:
.. attribute:: props.reader
:type: ~gi.repository.Shumate.VectorReader
The type of the None singleton.