use super::*;
use crate::common::{BoundingBox, Keyword, TemporalExtent};
use serde::{Deserialize, Serialize};
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct DataIdentification {
pub citation: Citation,
pub abstract_text: String,
pub purpose: Option<String>,
pub credit: Vec<String>,
pub status: Vec<ProgressCode>,
pub point_of_contact: Vec<ResponsibleParty>,
pub resource_maintenance: Option<MaintenanceInformation>,
pub keywords: Vec<Vec<Keyword>>,
pub resource_constraints: Vec<Constraints>,
pub spatial_representation_type: Vec<SpatialRepresentationType>,
pub spatial_resolution: Vec<Resolution>,
pub language: Vec<String>,
pub character_set: Vec<CharacterSet>,
pub topic_category: Vec<TopicCategory>,
pub extent: Extent,
}
impl Default for DataIdentification {
fn default() -> Self {
Self {
citation: Citation::default(),
abstract_text: String::new(),
purpose: None,
credit: Vec::new(),
status: Vec::new(),
point_of_contact: Vec::new(),
resource_maintenance: None,
keywords: Vec::new(),
resource_constraints: Vec::new(),
spatial_representation_type: Vec::new(),
spatial_resolution: Vec::new(),
language: vec!["eng".to_string()],
character_set: vec![CharacterSet::Utf8],
topic_category: Vec::new(),
extent: Extent::default(),
}
}
}
#[derive(Debug, Clone, Copy, Serialize, Deserialize)]
pub enum ProgressCode {
Completed,
HistoricalArchive,
Obsolete,
Ongoing,
Planned,
Required,
UnderDevelopment,
}
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct MaintenanceInformation {
pub maintenance_frequency: MaintenanceFrequency,
pub date_of_next_update: Option<chrono::DateTime<chrono::Utc>>,
pub user_defined_frequency: Option<String>,
pub maintenance_note: Vec<String>,
}
#[derive(Debug, Clone, Copy, Serialize, Deserialize)]
pub enum MaintenanceFrequency {
Continual,
Daily,
Weekly,
Fortnightly,
Monthly,
Quarterly,
Biannually,
Annually,
AsNeeded,
Irregular,
NotPlanned,
Unknown,
}
#[derive(Debug, Clone, Serialize, Deserialize)]
pub enum Constraints {
Legal(LegalConstraints),
Security(SecurityConstraints),
General(GeneralConstraints),
}
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct LegalConstraints {
pub access_constraints: Vec<RestrictionCode>,
pub use_constraints: Vec<RestrictionCode>,
pub other_constraints: Vec<String>,
pub use_limitation: Vec<String>,
}
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct SecurityConstraints {
pub classification: ClassificationCode,
pub user_note: Option<String>,
pub classification_system: Option<String>,
pub handling_description: Option<String>,
}
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct GeneralConstraints {
pub use_limitation: Vec<String>,
}
#[derive(Debug, Clone, Copy, Serialize, Deserialize)]
pub enum RestrictionCode {
Copyright,
Patent,
PatentPending,
Trademark,
License,
IntellectualPropertyRights,
Restricted,
OtherRestrictions,
}
#[derive(Debug, Clone, Copy, Serialize, Deserialize)]
pub enum ClassificationCode {
Unclassified,
Restricted,
Confidential,
Secret,
TopSecret,
}
#[derive(Debug, Clone, Copy, Serialize, Deserialize)]
pub enum SpatialRepresentationType {
Vector,
Grid,
TextTable,
Tin,
StereoModel,
Video,
}
#[derive(Debug, Clone, Serialize, Deserialize)]
pub enum Resolution {
Distance(f64),
Scale(i32),
}
#[derive(Debug, Clone, Copy, Serialize, Deserialize)]
pub enum TopicCategory {
Farming,
Biota,
Boundaries,
ClimatologyMeteorologyAtmosphere,
Economy,
Elevation,
Environment,
GeoscientificInformation,
Health,
ImageryBaseMapsEarthCover,
IntelligenceMilitary,
InlandWaters,
Location,
Oceans,
PlanningCadastre,
Society,
Structure,
Transportation,
UtilitiesCommunication,
}
#[derive(Debug, Clone, Serialize, Deserialize, Default)]
pub struct Extent {
pub description: Option<String>,
pub geographic_extent: Option<BoundingBox>,
pub temporal_extent: Option<TemporalExtent>,
pub vertical_extent: Option<VerticalExtent>,
}
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct VerticalExtent {
pub minimum_value: f64,
pub maximum_value: f64,
pub unit_of_measure: String,
pub vertical_crs: Option<String>,
}
#[cfg(feature = "xml")]
impl Iso19115Metadata {
pub fn to_xml(&self) -> Result<String> {
use quick_xml::se::to_string;
to_string(&self).map_err(|e| MetadataError::XmlError(e.to_string()))
}
pub fn from_xml(xml: &str) -> Result<Self> {
use quick_xml::de::from_str;
from_str(xml).map_err(|e| MetadataError::XmlError(e.to_string()))
}
}
impl Iso19115Metadata {
pub fn to_json(&self) -> Result<String> {
serde_json::to_string_pretty(&self).map_err(|e| MetadataError::JsonError(e.to_string()))
}
pub fn from_json(json: &str) -> Result<Self> {
serde_json::from_str(json).map_err(|e| MetadataError::JsonError(e.to_string()))
}
}