osm_primitives/
lib.rs

1/// Common metadata for an element
2///
3/// [Openstreetmap wiki](https://wiki.openstreetmap.org/wiki/Elements#Common_attributes)
4#[derive(Debug, PartialEq, Clone)]
5pub struct ElementMetadata {
6  pub id: i64,
7
8  /// The display name of the user who last modified the object; exclusively informative and may be empty.
9  /// A user can change their display name at any time (existing elements will reflect the new user name without needing any version change).
10  pub user: String,
11
12  /// The user-id of the user who last modified the object.
13  pub uid: u64,
14
15  /// The version of the object; newly created objects start at version 1 and the value
16  /// is incremented by the server when a client uploads a new version of the object.
17  pub version: u32,
18
19  /// The changeset number in which the object was created or last updated.
20  pub changeset: u64,
21
22  /// Time of the last modification,
23  /// encoded in any [W3C standard date and time format](https://www.w3.org/TR/NOTE-datetime)
24  pub timestamp: String,
25}
26
27/// A single point in space defined by its latitude, longitude and node id.
28///
29/// [Openstreetmap wiki](https://wiki.openstreetmap.org/wiki/Node)
30#[derive(Debug, PartialEq, Clone)]
31pub struct Node {
32  pub lat: f64,
33  pub lon: f64,
34  pub metadata: ElementMetadata,
35  pub tags: Vec<Tag>,
36}
37
38/// A way is an ordered list of nodes which normally also has at least one tag or is included within a Relation.
39/// It can be open or closed, a closed way is one whose last nodes on the way is also the first on that way.
40/// A closed way may be interpreted as a closed polyline, a polygon, or both.
41///
42/// [Openstreetmap wiki](https://wiki.openstreetmap.org/wiki/Way)
43///
44/// Note that this library does not impose any upper limit for the size of a way, as the 2000-node-limit is considered an API limit
45#[derive(Debug, PartialEq, Clone)]
46pub struct Way {
47  pub nodes: Vec<ReferencedNode>,
48  pub metadata: ElementMetadata,
49  pub tags: Vec<Tag>,
50}
51
52/// A collection of Elements
53///
54/// [Openstreetmap wiki](https://wiki.openstreetmap.org/wiki/Relation)
55#[derive(Debug, PartialEq, Clone)]
56pub struct Relation {
57  pub members: Vec<RelationMember>,
58  pub metadata: ElementMetadata,
59  pub tags: Vec<Tag>,
60}
61
62/// A reference to a Node, by wrapping it's `id`.
63#[derive(Debug, PartialEq, Clone)]
64pub struct ReferencedNode {
65  pub id: i64,
66}
67
68/// A key value pair.
69///
70/// [Openstreetmap wiki](https://wiki.openstreetmap.org/wiki/Tags)
71#[derive(Debug, PartialEq, Clone)]
72pub struct Tag {
73  pub key: String,
74  pub value: String
75}
76
77/// A reference to an element, by wrapping it's `id`.
78#[derive(Debug, PartialEq, Clone)]
79pub enum ReferencedElement {
80  Node(i64),
81  Way(i64),
82  Relation(i64)
83}
84
85/// An entry from a Relation which references another element by id and role.
86#[derive(Debug, PartialEq, Clone)]
87pub struct RelationMember {
88  pub role: String,
89  pub element: ReferencedElement,
90}
91
92#[derive(Debug, PartialEq, Clone)]
93pub enum Element {
94  Node(Node),
95  Way(Way),
96  Relation(Relation),
97}
98
99impl Element {
100  pub fn metadata(&self) -> &ElementMetadata {
101    match self {
102      Element::Node(me) => &me.metadata,
103      Element::Way(me) => &me.metadata,
104      Element::Relation(me) => &me.metadata,
105    }
106  }
107}
108
109impl From<Node> for Element {
110  fn from(node: Node) -> Element {
111    Element::Node(node)
112  }
113}
114
115impl From<Way> for Element {
116  fn from(way: Way) -> Element {
117    Element::Way(way)
118  }
119}
120
121impl From<Relation> for Element {
122  fn from(relation: Relation) -> Element {
123    Element::Relation(relation)
124  }
125}