use super::Extension;
use geojson::Geometry;
use serde::{Deserialize, Serialize};
use serde_json::{Map, Value};
#[derive(Debug, Serialize, Deserialize, Default, PartialEq, Clone)]
pub struct Projection {
#[serde(skip_serializing_if = "Option::is_none")]
pub code: Option<String>,
#[serde(skip_serializing_if = "Option::is_none")]
pub wkt2: Option<String>,
#[serde(skip_serializing_if = "Option::is_none")]
pub projjson: Option<Map<String, Value>>,
#[serde(skip_serializing_if = "Option::is_none")]
pub geometry: Option<Geometry>,
#[serde(skip_serializing_if = "Option::is_none")]
pub bbox: Option<Vec<f64>>,
#[serde(skip_serializing_if = "Option::is_none")]
pub centroid: Option<Centroid>,
#[serde(skip_serializing_if = "Option::is_none")]
pub shape: Option<Vec<usize>>,
#[serde(skip_serializing_if = "Option::is_none")]
pub transform: Option<Vec<f64>>,
}
#[derive(Debug, Serialize, Deserialize, PartialEq, Clone)]
pub struct Centroid {
pub lat: f64,
pub lon: f64,
}
impl Projection {
pub fn is_empty(&self) -> bool {
serde_json::to_value(self)
.map(|v| v == Value::Object(Default::default()))
.unwrap_or(true)
}
}
impl Extension for Projection {
const IDENTIFIER: &'static str =
"https://stac-extensions.github.io/projection/v2.0.0/schema.json";
const PREFIX: &'static str = "proj";
}
#[cfg(test)]
mod tests {
use super::Projection;
use crate::{Extensions, Item};
#[test]
fn example() {
let item: Item =
stac::read("examples/extensions-collection/proj-example/proj-example.json").unwrap();
let projection = item.extension::<Projection>().unwrap();
assert_eq!(projection.code.unwrap(), "EPSG:32614");
}
}