osm_io/osm/pbf/
file_info.rs

1use crate::osm::model::bounding_box::BoundingBox;
2
3/// *.osm.pbf header data
4#[derive(Debug, Clone)]
5pub struct FileInfo {
6    bounding_box: Option<BoundingBox>,
7    required_features: Vec<String>,
8    optional_features: Vec<String>,
9    writingprogram: Option<String>,
10    source: Option<String>,
11    osmosis_replication_timestamp: Option<i64>,
12    osmosis_replication_sequence_number: Option<i64>,
13    osmosis_replication_base_url: Option<String>,
14}
15
16impl FileInfo {
17    /// Prepare OSM header data
18    ///
19    /// Example:
20    /// ```
21    /// use osm_io::osm::pbf::file_info::FileInfo;
22    /// let file_info = FileInfo::default()
23    ///     .with_writingprogram_str("example-osm-pbf-writer");
24    /// ```
25    #[allow(clippy::too_many_arguments)]
26    pub fn new(
27        bounding_box: Option<BoundingBox>,
28        required_features: Vec<String>,
29        optional_features: Vec<String>,
30        writingprogram: Option<String>,
31        source: Option<String>,
32        osmosis_replication_timestamp: Option<i64>,
33        osmosis_replication_sequence_number: Option<i64>,
34        osmosis_replication_base_url: Option<String>,
35    ) -> Self {
36        FileInfo {
37            bounding_box,
38            required_features,
39            optional_features,
40            writingprogram,
41            source,
42            osmosis_replication_timestamp,
43            osmosis_replication_sequence_number,
44            osmosis_replication_base_url,
45        }
46    }
47
48    #[allow(dead_code)]
49    pub(crate) fn merge_bounding_box(&mut self, bounding_box: Option<BoundingBox>) {
50        if self.bounding_box.is_none() {
51            self.bounding_box = bounding_box;
52        } else if bounding_box.is_some() {
53            self.bounding_box.as_mut().unwrap().merge_bounding_box(bounding_box.as_ref().unwrap());
54        }
55    }
56
57    /// Get the bounding box for the data in this file
58    pub fn bounding_box(&self) -> &Option<BoundingBox> {
59        &self.bounding_box
60    }
61
62    /// Set the bounding box for the data in this file
63    pub fn with_bounding_box(&mut self, bounding_box: &Option<BoundingBox>) {
64        self.bounding_box = bounding_box.clone();
65    }
66
67    /// Get required features for this file
68    pub fn required_features(&self) -> &Vec<String> {
69        &self.required_features
70    }
71
72    /// Set required features for this file
73    pub fn with_required_features(&mut self, required_features: &[String]) {
74        self.required_features = required_features.to_vec();
75    }
76
77    /// Get optional features for this file
78    pub fn optional_features(&self) -> &Vec<String> {
79        &self.optional_features
80    }
81
82    /// Set optional features for this file
83    pub fn with_optional_features(&mut self, optional_features: &[String]) {
84        self.optional_features = optional_features.to_vec();
85    }
86
87    /// Get writing program set for this file
88    pub fn writingprogram(&self) -> &Option<String> {
89        &self.writingprogram
90    }
91
92    /// Set writing program for this file
93    pub fn with_writingprogram(&mut self, writingprogram: &Option<String>) {
94        self.writingprogram = writingprogram.clone();
95    }
96
97    /// As with_writingprogram above but accept &str
98    pub fn with_writingprogram_str(&mut self, writingprogram: &str) {
99        self.writingprogram = Some(writingprogram.to_string())
100    }
101
102    /// Get the source set for this file
103    pub fn source(&self) -> &Option<String> {
104        &self.source
105    }
106
107    /// Set the source for this file
108    pub fn with_source(&mut self, source: &Option<String>) {
109        self.source = source.clone();
110    }
111
112    /// Get the osmosis_replication_timestamp set for this file
113    pub fn osmosis_replication_timestamp(&self) -> &Option<i64> {
114        &self.osmosis_replication_timestamp
115    }
116
117    /// Set the osmosis_replication_timestamp for this file
118    pub fn with_osmosis_replication_timestamp(&mut self, osmosis_replication_timestamp: &Option<i64>) {
119        self.osmosis_replication_timestamp = *osmosis_replication_timestamp;
120    }
121
122    /// Get osmosis_replication_sequence_number set for this file
123    pub fn osmosis_replication_sequence_number(&self) -> &Option<i64> {
124        &self.osmosis_replication_sequence_number
125    }
126
127    /// Set osmosis_replication_sequence_number for this file
128    pub fn with_osmosis_replication_sequence_number(&mut self, osmosis_replication_sequence_number: &Option<i64>) {
129        self.osmosis_replication_sequence_number = *osmosis_replication_sequence_number;
130    }
131
132    /// Get osmosis_replication_base_url set for this file
133    pub fn osmosis_replication_base_url(&self) -> &Option<String> {
134        &self.osmosis_replication_base_url
135    }
136
137    /// Set osmosis_replication_base_url for this file
138    pub fn with_osmosis_replication_base_url(&mut self, osmosis_replication_base_url: &Option<String>) {
139        self.osmosis_replication_base_url = osmosis_replication_base_url.clone();
140    }
141
142    pub fn required(&self, feature: &str) -> bool {
143        self.required_features.contains(&feature.to_string())
144    }
145
146    pub fn optional(&self, feature: &str) -> bool {
147        self.optional_features.contains(&feature.to_string())
148    }
149}
150
151impl Default for FileInfo {
152    fn default() -> Self {
153        FileInfo::new(
154            None,
155            ["OsmSchema-V0.6", "DenseNodes"].map(|s| s.to_string()).to_vec(),
156            ["Sort.Type_then_ID"].map(|s| s.to_string()).to_vec(),
157            None,
158            None,
159            None,
160            None,
161            None,
162        )
163    }
164}