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
66
67
68
69
70
use std::collections::HashMap;
use std::str::FromStr;
use crate::errors::Error;
use crate::types::{
CoordType, Element, LineString, LinearRing, MultiGeometry, Placemark, Point, Polygon,
};
#[derive(Clone, Debug, PartialEq)]
#[non_exhaustive]
pub enum KmlVersion {
Unknown,
V22,
V23,
}
impl Default for KmlVersion {
fn default() -> KmlVersion {
KmlVersion::Unknown
}
}
impl FromStr for KmlVersion {
type Err = Error;
fn from_str(s: &str) -> Result<Self, Self::Err> {
match s {
"http://www.opengis.net/kml/2.2" => Ok(Self::V22),
"http://www.opengis.net/kml/2.3" => Ok(Self::V23),
v => Err(Error::InvalidKmlVersion(v.to_string())),
}
}
}
#[derive(Clone, Default, PartialEq, Debug)]
pub struct KmlDocument<T: CoordType = f64> {
pub version: KmlVersion,
pub attrs: HashMap<String, String>,
pub elements: Vec<Kml<T>>,
}
#[derive(Clone, Debug, PartialEq)]
#[non_exhaustive]
pub enum Kml<T: CoordType = f64> {
KmlDocument(KmlDocument<T>),
Point(Point<T>),
LineString(LineString<T>),
LinearRing(LinearRing<T>),
Polygon(Polygon<T>),
MultiGeometry(MultiGeometry<T>),
Placemark(Placemark<T>),
Document {
attrs: HashMap<String, String>,
elements: Vec<Kml<T>>,
},
Folder {
attrs: HashMap<String, String>,
elements: Vec<Kml<T>>,
},
Element(Element),
}