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;
12
13use geo_types::Geometry;
14
15/// An enumeration representing the value of a property associated with a feature.
16#[derive(Debug, Clone, PartialEq, PartialOrd)]
17pub enum Value {
18 String(String),
19 Float(f32),
20 Double(f64),
21 Int(i64),
22 UInt(u64),
23 SInt(i64),
24 Bool(bool),
25 Null,
26}
27
28/// A structure representing a feature in a vector tile.
29#[derive(Debug, Clone)]
30pub struct Feature {
31 /// The geometry of the feature.
32 pub geometry: Geometry<f32>,
33
34 /// Optional identifier for the feature.
35 pub id: Option<u64>,
36
37 /// Optional properties associated with the feature.
38 pub properties: Option<HashMap<String, Value>>,
39}
40
41impl Feature {
42 /// Retrieves the geometry of the feature.
43 ///
44 /// # Returns
45 ///
46 /// A reference to the geometry of the feature.
47 ///
48 /// # Examples
49 ///
50 /// ```
51 /// use mvt_reader::feature::Feature;
52 /// use geo_types::{Geometry, Point};
53 ///
54 /// let feature = Feature {
55 /// geometry: Geometry::Point(Point::new(0.0, 0.0)),
56 /// id: None,
57 /// properties: None,
58 /// };
59 ///
60 /// let geometry = feature.get_geometry();
61 /// println!("{:?}", geometry);
62 /// ```
63 pub fn get_geometry(&self) -> &Geometry<f32> {
64 &self.geometry
65 }
66}