pub struct Reader { /* private fields */ }Expand description
Reader for decoding and accessing vector tile data.
Implementations§
Source§impl Reader
impl Reader
Sourcepub fn new(data: Vec<u8>) -> Result<Self, ParserError>
pub fn new(data: Vec<u8>) -> Result<Self, ParserError>
Creates a new Reader instance with the provided vector tile data.
§Arguments
data- The vector tile data as a byte vector.
§Returns
A result containing the Reader instance if successful, or a DecodeError if decoding the vector tile data fails.
§Examples
use mvt_reader::Reader;
let data = vec![/* Vector tile data */];
let reader = Reader::new(data);Sourcepub fn get_layer_names(&self) -> Result<Vec<String>, ParserError>
pub fn get_layer_names(&self) -> Result<Vec<String>, ParserError>
Retrieves the names of the layers in the vector tile.
§Returns
A result containing a vector of layer names if successful, or a ParserError if there is an error parsing the tile.
§Examples
use mvt_reader::Reader;
let data = vec![/* Vector tile data */];
let reader = Reader::new(data).unwrap();
match reader.get_layer_names() {
Ok(layer_names) => {
for name in layer_names {
println!("Layer: {}", name);
}
}
Err(error) => {
todo!();
}
}Sourcepub fn get_layer_metadata(&self) -> Result<Vec<Layer>, ParserError>
pub fn get_layer_metadata(&self) -> Result<Vec<Layer>, ParserError>
Retrieves metadata about the layers in the vector tile.
§Returns
A result containing a vector of Layer structs if successful, or a ParserError if there is an error parsing the tile.
§Examples
use mvt_reader::Reader;
let data = vec![/* Vector tile data */];
let reader = Reader::new(data).unwrap();
match reader.get_layer_metadata() {
Ok(layers) => {
for layer in layers {
println!("Layer: {}", layer.name);
println!("Extent: {}", layer.extent);
}
}
Err(error) => {
todo!();
}
}Sourcepub fn get_features(
&self,
layer_index: usize,
) -> Result<Vec<Feature>, ParserError>
pub fn get_features( &self, layer_index: usize, ) -> Result<Vec<Feature>, ParserError>
Retrieves the features of a specific layer in the vector tile.
§Arguments
layer_index- The index of the layer.
§Returns
A result containing a vector of features if successful, or a ParserError if there is an error parsing the tile or accessing the layer.
§Examples
use mvt_reader::Reader;
let data = vec![/* Vector tile data */];
let reader = Reader::new(data).unwrap();
match reader.get_features(0) {
Ok(features) => {
for feature in features {
todo!();
}
}
Err(error) => {
todo!();
}
}Sourcepub fn get_features_as<T: CoordNum>(
&self,
layer_index: usize,
) -> Result<Vec<Feature<T>>, ParserError>
pub fn get_features_as<T: CoordNum>( &self, layer_index: usize, ) -> Result<Vec<Feature<T>>, ParserError>
Retrieves the features of a specific layer with geometry coordinates in the specified numeric type.
This is a generic version of get_features that allows you to choose
the coordinate type for the geometry. Supported types include f32 (default), i32, and i16.
§Arguments
layer_index- The index of the layer.
§Type Parameters
T- The numeric type for geometry coordinates (e.g.f32,i32,i16).
§Returns
A result containing a vector of features if successful, or a ParserError if there is an error parsing the tile or accessing the layer.
§Examples
use mvt_reader::Reader;
let data = vec![/* Vector tile data */];
let reader = Reader::new(data).unwrap();
// Get features with i32 coordinates
let features = reader.get_features_as::<i32>(0);
// Get features with i16 coordinates
let features = reader.get_features_as::<i16>(0);