Skip to main content

cimstructs/
CoordinateSystem.rs

1/// Coordinate reference system.
2#[derive(Debug, Default, Clone, serde::Serialize, serde::Deserialize)]
3pub struct CoordinateSystem {
4    #[serde(flatten)]
5    pub base: super::IdentifiedObject,
6    /// A Uniform Resource Name (URN) for the coordinate reference system (crs) used to define 'Location.PositionPoints'. An example would be the European Petroleum Survey Group (EPSG) code for a coordinate reference system, defined in URN under the Open Geospatial Consortium (OGC) namespace as: urn:ogc:def:crs:EPSG::XXXX, where XXXX is an EPSG code (a full list of codes can be found at the EPSG Registry web site http://www.epsg-registry.org/). To define the coordinate system as being WGS84 (latitude, longitude) using an EPSG OGC, this attribute would be urn:ogc:def:crs:EPSG::4236. A profile should limit this code to a set of allowed URNs agreed to by all sending and receiving parties.
7    pub crs_urn: String,
8}
9impl crate::base::CimElement for CoordinateSystem {
10    fn mrid(&self) -> &str { &self.base.id }
11    fn type_name(&self) -> &'static str { "CoordinateSystem" }
12    fn as_any(&self) -> &dyn std::any::Any { self }
13    fn to_json_value(&self) -> serde_json::Value {
14        serde_json::to_value(self).unwrap_or(serde_json::Value::Null)
15    }
16    fn to_block(&self) -> crate::base::RdfBlock {
17        let mut block = self.base.to_block();
18        block.type_name = "CoordinateSystem".to_string();
19        if !self.crs_urn.is_empty() {
20            block.fields.insert("CoordinateSystem.crsUrn".into(), crate::base::FieldValue::Text(self.crs_urn.clone()));
21        }
22        block
23    }
24}
25
26impl CoordinateSystem {
27    pub fn from_block(b: &crate::base::RdfBlock) -> Self {
28        let mut obj = Self::default();
29        obj.base.id.clone_from(&b.mrid);
30        for (key, val) in &b.fields {
31            match key.as_str() {
32                "CoordinateSystem.crsUrn" => {
33                    match val {
34                        crate::base::FieldValue::Text(sv) => { obj.crs_urn = sv.clone(); }
35                        crate::base::FieldValue::TextList(svs) => {
36                            if let Some(sv) = svs.last() { obj.crs_urn = sv.clone(); }
37                        }
38                        _ => {}
39                    }
40                }
41                "IdentifiedObject.description" => {
42                    match val {
43                        crate::base::FieldValue::Text(sv) => { obj.base.description = sv.clone(); }
44                        crate::base::FieldValue::TextList(svs) => {
45                            if let Some(sv) = svs.last() { obj.base.description = sv.clone(); }
46                        }
47                        _ => {}
48                    }
49                }
50                "IdentifiedObject.energyIdentCodeEic" => {
51                    match val {
52                        crate::base::FieldValue::Text(sv) => { obj.base.energy_ident_code_eic = sv.clone(); }
53                        crate::base::FieldValue::TextList(svs) => {
54                            if let Some(sv) = svs.last() { obj.base.energy_ident_code_eic = sv.clone(); }
55                        }
56                        _ => {}
57                    }
58                }
59                "IdentifiedObject.mRID" => {
60                    match val {
61                        crate::base::FieldValue::Text(sv) => { obj.base.m_rid = sv.clone(); }
62                        crate::base::FieldValue::TextList(svs) => {
63                            if let Some(sv) = svs.last() { obj.base.m_rid = sv.clone(); }
64                        }
65                        _ => {}
66                    }
67                }
68                "IdentifiedObject.name" => {
69                    match val {
70                        crate::base::FieldValue::Text(sv) => { obj.base.name = sv.clone(); }
71                        crate::base::FieldValue::TextList(svs) => {
72                            if let Some(sv) = svs.last() { obj.base.name = sv.clone(); }
73                        }
74                        _ => {}
75                    }
76                }
77                "IdentifiedObject.shortName" => {
78                    match val {
79                        crate::base::FieldValue::Text(sv) => { obj.base.short_name = sv.clone(); }
80                        crate::base::FieldValue::TextList(svs) => {
81                            if let Some(sv) = svs.last() { obj.base.short_name = sv.clone(); }
82                        }
83                        _ => {}
84                    }
85                }
86                _ => {}
87            }
88        }
89        obj
90    }
91}