-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathfeature.rs
More file actions
65 lines (59 loc) · 1.65 KB
/
feature.rs
File metadata and controls
65 lines (59 loc) · 1.65 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
//! 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
}
}