mvt_reader/feature.rs
1//! This module provides types and utilities for working with features in the `mvt-reader` crate.
2//!
3//! A feature represents a geographic entity with geometry and associated properties. Features are typically found within layers of a vector tile.
4//!
5//! # Types
6//!
7//! The `feature` module defines the following types:
8//!
9//! - `Feature`: Represents a feature with geometry, an optional id and optional properties.
10
11use std::collections::HashMap;
12use geo_types::{CoordNum, Geometry};
13
14/// An enumeration representing the value of a property associated with a feature.
15#[derive(Debug, Clone, PartialEq, PartialOrd)]
16pub enum Value {
17 String(String),
18 Float(f32),
19 Double(f64),
20 Int(i64),
21 UInt(u64),
22 SInt(i64),
23 Bool(bool),
24 Null,
25}
26
27/// A structure representing a feature in a vector tile.
28#[derive(Debug, Clone)]
29pub struct Feature<T: CoordNum = f32> {
30 /// The geometry of the feature.
31 pub geometry: Geometry<T>,
32
33 /// Optional identifier for the feature.
34 pub id: Option<u64>,
35
36 /// Optional properties associated with the feature.
37 pub properties: Option<HashMap<String, Value>>,
38}
39
40impl<T: CoordNum> Feature<T> {
41 /// Retrieves the geometry of the feature.
42 ///
43 /// # Returns
44 ///
45 /// A reference to the geometry of the feature.
46 ///
47 /// # Examples
48 ///
49 /// ```
50 /// use mvt_reader::feature::Feature;
51 /// use geo_types::{Geometry, Point};
52 ///
53 /// let feature = Feature {
54 /// geometry: Geometry::Point(Point::new(0.0, 0.0)),
55 /// id: None,
56 /// properties: None,
57 /// };
58 ///
59 /// let geometry = feature.get_geometry();
60 /// println!("{:?}", geometry);
61 /// ```
62 pub fn get_geometry(&self) -> &Geometry<T> {
63 &self.geometry
64 }
65}