Skip to main content

powerio_dist/
geo.rs

1//! Typed coordinate metadata for the distribution model.
2
3use serde::{Deserialize, Serialize};
4
5mod component;
6mod transform;
7pub use component::{
8    DistComponentLocation, DistGeographicPoint, DistLocationTarget, MAX_COMPONENT_LOCATIONS,
9};
10pub(crate) use transform::ComponentLocationEdits;
11
12/// A point attached to one model element.
13#[derive(Debug, Clone, Copy, PartialEq, Serialize, Deserialize)]
14#[cfg_attr(feature = "schema", derive(schemars::JsonSchema))]
15pub struct DistLocation {
16    /// X coordinate. In geographic space this is longitude.
17    pub x: f64,
18    /// Y coordinate. In geographic space this is latitude.
19    pub y: f64,
20    /// Point origin when it differs from the network default.
21    #[serde(default, skip_serializing_if = "Option::is_none")]
22    pub kind: Option<DistCoordsKind>,
23}
24
25/// Coordinate origin.
26#[derive(Debug, Clone, Copy, PartialEq, Eq, Serialize, Deserialize)]
27#[cfg_attr(feature = "schema", derive(schemars::JsonSchema))]
28#[serde(rename_all = "snake_case")]
29#[non_exhaustive]
30pub enum DistCoordsKind {
31    Source,
32    Synthetic,
33    Manual,
34    Derived,
35}
36
37/// Network level coordinate metadata.
38#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
39#[cfg_attr(feature = "schema", derive(schemars::JsonSchema))]
40pub struct DistGeoMeta {
41    /// Coordinate space shared by every location on the network.
42    #[serde(flatten)]
43    pub space: CoordinateSpace,
44    /// Default origin for points without their own `kind`.
45    #[serde(default, skip_serializing_if = "Option::is_none")]
46    pub kind: Option<DistCoordsKind>,
47}
48
49/// Coordinate space for locations in a network.
50#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
51#[cfg_attr(feature = "schema", derive(schemars::JsonSchema))]
52#[serde(tag = "space", rename_all = "snake_case")]
53#[non_exhaustive]
54pub enum CoordinateSpace {
55    /// x = longitude and y = latitude in decimal degrees. `None` means EPSG:4326.
56    Geographic {
57        #[serde(default, skip_serializing_if = "Option::is_none")]
58        crs: Option<String>,
59    },
60    /// Planar coordinates, with the CRS named when known.
61    Projected {
62        #[serde(default, skip_serializing_if = "Option::is_none")]
63        crs: Option<String>,
64    },
65    /// Drawing coordinates with no earth referent.
66    Diagram {
67        #[serde(default, skip_serializing_if = "Option::is_none")]
68        canvas: Option<DistCanvas>,
69    },
70    /// The source did not declare a coordinate space.
71    Unknown,
72}
73
74/// Diagram canvas metadata.
75#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
76#[cfg_attr(feature = "schema", derive(schemars::JsonSchema))]
77pub struct DistCanvas {
78    #[serde(default, skip_serializing_if = "Option::is_none")]
79    pub width: Option<f64>,
80    #[serde(default, skip_serializing_if = "Option::is_none")]
81    pub height: Option<f64>,
82    #[serde(default, skip_serializing_if = "Option::is_none")]
83    pub units: Option<String>,
84}