mvt-reader 2.4.0

A library for decoding and reading mapbox vector tiles in Rust and WebAssembly
Documentation
//! This module provides types and utilities for working with features in the `mvt-reader` crate.
//!
//! A feature represents a geographic entity with geometry and associated properties. Features are typically found within layers of a vector tile.
//!
//! # Types
//!
//! The `feature` module defines the following types:
//!
//! - `Feature`: Represents a feature with geometry, an optional id and optional properties.

use std::collections::HashMap;
use geo_types::{CoordNum, Geometry};

/// An enumeration representing the value of a property associated with a feature.
#[derive(Debug, Clone, PartialEq, PartialOrd)]
pub enum Value {
  String(String),
  Float(f32),
  Double(f64),
  Int(i64),
  UInt(u64),
  SInt(i64),
  Bool(bool),
  Null,
}

/// A structure representing a feature in a vector tile.
#[derive(Debug, Clone)]
pub struct Feature<T: CoordNum = f32> {
  /// The geometry of the feature.
  pub geometry: Geometry<T>,

  /// Optional identifier for the feature.
  pub id: Option<u64>,

  /// Optional properties associated with the feature.
  pub properties: Option<HashMap<String, Value>>,
}

impl<T: CoordNum> Feature<T> {
  /// Retrieves the geometry of the feature.
  ///
  /// # Returns
  ///
  /// A reference to the geometry of the feature.
  ///
  /// # Examples
  ///
  /// ```
  /// use mvt_reader::feature::Feature;
  /// use geo_types::{Geometry, Point};
  ///
  /// let feature = Feature {
  ///   geometry: Geometry::Point(Point::new(0.0, 0.0)),
  ///   id: None,
  ///   properties: None,
  /// };
  ///
  /// let geometry = feature.get_geometry();
  /// println!("{:?}", geometry);
  /// ```
  pub fn get_geometry(&self) -> &Geometry<T> {
    &self.geometry
  }
}