Skip to content
Merged
Show file tree
Hide file tree
Changes from 26 commits
Commits
Show all changes
32 commits
Select commit Hold shift + click to select a range
daca1fd
Implement Temporal Primitive Geometry for MovingFeatures
KrausMatthias May 12, 2025
4f7d540
Implement CRS and TRS for Moving Features
KrausMatthias May 17, 2025
00ecbf5
Use serde(try_from ...) instead of custom deserialization for tempora…
KrausMatthias May 18, 2025
4a0c5de
Inline AnglesType and ScaleType in Orientation
KrausMatthias May 18, 2025
9719dd4
Used adjacent tags for Trs and Crs
KrausMatthias May 19, 2025
33a09b2
Implement TemporalGeometry and TemporalComplexGeometry
KrausMatthias May 19, 2025
61a1b48
Add moving features property types
KrausMatthias May 23, 2025
99072bf
Refactor and comment temporal properties
KrausMatthias May 24, 2025
2b3e9d2
Some doc comment fixes
KrausMatthias May 25, 2025
98064b0
Add test to temporal properties and fix some bugs
KrausMatthias May 25, 2025
d5200aa
Integrate with moving features with collection, feature collection an…
KrausMatthias May 25, 2025
83f77ec
Add traits for moving features transactions to drivers
KrausMatthias May 25, 2025
c4a7978
Add a blanket implementation of moving feature geometry transactions …
KrausMatthias May 25, 2025
a32f31c
Drop unnecessary complexity on ItemType for MovingFeatures
KrausMatthias May 29, 2025
06b2067
Add convenience method to SameLengthDateTimeCoordinatesVec
KrausMatthias May 29, 2025
4b94480
Somehow serde(rename = camelCase) does not work here, resort to serde…
KrausMatthias May 29, 2025
ad6aaca
Add accessors to SameLengthCoordinatesVec
KrausMatthias May 31, 2025
ed998a5
Add into_inner to Prisms
KrausMatthias May 31, 2025
d60220c
Drop enforcment of Prisms having >= 1 geometry
KrausMatthias Jun 22, 2025
5b11edd
Implement same length checks at ser/de for datetime aligned types
KrausMatthias Jun 22, 2025
93d6eb0
Drop foreign members for temporal primitive geometry as it can't be f…
KrausMatthias Sep 1, 2025
7c5938c
Enforce Same Length DateTimeCoords and add convenience functions
KrausMatthias Sep 1, 2025
53c1f80
Fix time type in feature
KrausMatthias Sep 1, 2025
14b4f0c
Add utoipa support
KrausMatthias Sep 1, 2025
7e70a76
Move moving features driver to separate PR #27
KrausMatthias Sep 1, 2025
ad4edea
Add movingfeatures to changelog
KrausMatthias Sep 1, 2025
49f3c10
Add serde(default)
KrausMatthias Sep 2, 2025
940321e
When CRS or TRS are missing use the default spatial or temporal CRS
KrausMatthias Sep 5, 2025
2b9ca5e
Address some todos and propositions
b4l Nov 29, 2025
b4e6a1f
Merge `main`
b4l Nov 29, 2025
774456c
Fix typo
KrausMatthias Nov 30, 2025
980dc25
Merge branch 'main' into feature/movingfeatures
b4l Nov 30, 2025
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,8 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

### Added

- Dynamic OpenAPI definition extration.
- Dynamic OpenAPI definition extraction.
- Types for `OGCAPI - Moving Features`

### Changed

Expand Down
1 change: 1 addition & 0 deletions ogcapi-types/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ stac = ["features"]
styles = []
tiles = ["common"]
coverages = []
movingfeatures = ["common", "features"]

[dependencies]
chrono = { version = "0.4.41", features = ["serde"] }
Expand Down
6 changes: 6 additions & 0 deletions ogcapi-types/src/common/collection.rs
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,10 @@ pub struct Collection {
#[cfg(feature = "stac")]
#[serde(default, skip_serializing_if = "std::collections::HashMap::is_empty")]
pub assets: std::collections::HashMap<String, crate::stac::Asset>,
#[cfg(feature = "movingfeatures")]
#[serde(rename = "updateFrequency")]
/// A time interval of sampling location. The time unit of this property is millisecond.
pub update_frequency: Option<i64>,
#[serde(flatten, default, skip_serializing_if = "Map::is_empty")]
pub additional_properties: Map<String, Value>,
}
Expand Down Expand Up @@ -131,6 +135,8 @@ impl Default for Collection {
summaries: Default::default(),
#[cfg(feature = "stac")]
assets: Default::default(),
#[cfg(feature = "movingfeatures")]
update_frequency: Default::default(),
additional_properties: Default::default(),
}
}
Expand Down
2 changes: 1 addition & 1 deletion ogcapi-types/src/common/extent.rs
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ impl Default for TemporalExtent {
}
}

fn serialize_interval<S>(
pub(crate) fn serialize_interval<S>(
interval: &Vec<[Option<DateTime<Utc>>; 2]>,
serializer: S,
) -> Result<S::Ok, S::Error>
Expand Down
27 changes: 27 additions & 0 deletions ogcapi-types/src/features/feature.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,16 @@ use std::fmt::Display;

#[cfg(feature = "stac")]
use crate::common::Bbox;

#[cfg(feature = "movingfeatures")]
use crate::movingfeatures::{
crs::Crs, temporal_geometry::TemporalGeometry, temporal_properties::TemporalProperties,
trs::Trs,
};

#[cfg(feature = "movingfeatures")]
use chrono::{DateTime, Utc};

use geojson::Geometry;
use serde::{Deserialize, Serialize};
use serde_json::{Map, Value};
Expand Down Expand Up @@ -69,6 +79,23 @@ pub struct Feature {
#[cfg(feature = "stac")]
#[serde(default)]
pub assets: HashMap<String, crate::stac::Asset>,
#[cfg(feature = "movingfeatures")]
#[serde(serialize_with="crate::common::serialize_interval")]
/// Life span information for the moving feature.
/// See [MF-Json 7.2.3 LifeSpan](https://docs.ogc.org/is/19-045r3/19-045r3.html#time)
pub time: Vec<[Option<DateTime<Utc>>; 2]>,
#[cfg(feature = "movingfeatures")]
// TODO should this be #[serde(default)] instead of option?
pub crs: Option<Crs>,
#[cfg(feature = "movingfeatures")]
// TODO should this be #[serde(default)] instead of option?
pub trs: Option<Trs>,
#[cfg(feature = "movingfeatures")]
#[serde(rename = "temporalGeometry")]
pub temporal_geometry: Option<TemporalGeometry>,
#[cfg(feature = "movingfeatures")]
#[serde(rename = "temporalProperties")]
pub temporal_properties: Option<TemporalProperties>,
}

impl Feature {
Expand Down
9 changes: 9 additions & 0 deletions ogcapi-types/src/features/feature_collection.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,9 @@ use utoipa::ToSchema;

use crate::common::Link;

#[cfg(feature = "movingfeatures")]
use crate::common::Bbox;

use super::Feature;

#[derive(Serialize, Deserialize, ToSchema, Default, Debug, Clone, Copy, PartialEq, Eq)]
Expand All @@ -26,6 +29,12 @@ pub struct FeatureCollection {
pub time_stamp: Option<String>,
pub number_matched: Option<u64>,
pub number_returned: Option<u64>,
#[cfg(feature = "movingfeatures")]
pub crs: Option<crate::movingfeatures::crs::Crs>,
#[cfg(feature = "movingfeatures")]
pub trs: Option<crate::movingfeatures::trs::Trs>,
#[cfg(feature = "movingfeatures")]
pub bbox: Option<Bbox>,
}

impl FeatureCollection {
Expand Down
5 changes: 5 additions & 0 deletions ogcapi-types/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,5 +22,10 @@ pub mod styles;
#[cfg(feature = "tiles")]
pub mod tiles;

/// Types specified in the `OGC API - Moving Features` standard.
// FIXME
// #[cfg(feature = "movingfeatures")]
pub mod movingfeatures;

#[cfg(feature = "coverages")]
mod coverages;
92 changes: 92 additions & 0 deletions ogcapi-types/src/movingfeatures/crs.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,92 @@
use serde::{Deserialize, Serialize};
use utoipa::ToSchema;
use std::str::FromStr;

use crate::common;

/// MF-JSON uses a CRS as described in in (GeoJSON:2008)[https://geojson.org/geojson-spec#coordinate-reference-system-objects]
/// See (7.2.3 CoordinateReferenceSystem Object)[https://docs.ogc.org/is/19-045r3/19-045r3.html#crs]
/// See (6. Overview of Moving features JSON Encodings)[https://docs.ogc.org/is/19-045r3/19-045r3.html#_overview_of_moving_features_json_encodings_informative]
#[derive(Serialize, Deserialize, Debug, Clone, PartialEq, Eq, ToSchema)]
#[serde(tag = "type", content = "properties")]
pub enum Crs {
/// A Named CRS object indicates a coordinate reference system by name. In this case, the value of its "type" member
/// is the string "Name". The value of its "properties" member is a JSON object containing a "name" member whose
/// value is a string identifying a coordinate reference system (not JSON null value). The value of "href" and "type"
/// is a JSON null value. This standard recommends an EPSG[3] code as the value of "name", such as "EPSG::4326."
///
/// See (7.2.3.1 Named CRS)[https://docs.ogc.org/is/19-045r3/19-045r3.html#_7_2_3_1_named_crs]
Name { name: String },
/// A linked CRS object has one required member "href" and one optional member "type". The value of the required "href"
/// member is a dereferenceable URI. The value of the optional "type" member is a string that hints at the format used
/// to represent CRS parameters at the provided URI. Suggested values are: "Proj4", "OGCWKT", "ESRIWKT", but others can
/// be used.
///
/// See (7.2.3.2. Linked CRS)[https://docs.ogc.org/is/19-045r3/19-045r3.html#_7_2_3_2_linked_crs]
Link {
r#type: Option<String>,
href: String,
},
}

impl Default for Crs {
fn default() -> Self {
Self::Name {
name: "urn:ogc:def:crs:OGC:1.3:CRS84".to_string(),
}
}
}

impl TryFrom<Crs> for common::Crs {
type Error = String;

fn try_from(value: Crs) -> Result<Self, Self::Error> {
match value {
// TODO this might not work for names like "EPSG:4326"
Crs::Name { name } => Self::from_str(name.as_str()),
Crs::Link { href, .. } => Self::from_str(href.as_str()),
}
}
}

impl From<common::Crs> for Crs {
fn from(value: common::Crs) -> Self {
Self::Name {
name: value.to_urn(),
}
}
}

#[cfg(test)]
mod tests {

use super::*;

#[test]
fn serde_json() {
// TODO this contradicts example from https://developer.ogc.org/api/movingfeatures/index.html#tag/MovingFeatures/operation/retrieveMovingFeatures
// Example from https://docs.ogc.org/is/19-045r3/19-045r3.html#_7_2_3_1_named_crs
let trs: Crs = serde_json::from_str(
r#"
{
"type": "Name",
"properties": {
"name": "urn:ogc:def:crs:OGC:1.3:CRS84"
}
}
"#,
)
.expect("Failed to parse Crs");
let expected_trs = Crs::default();
assert_eq!(trs, expected_trs);
}

#[test]
fn into_common_crs() {
// assert_eq!(common::Crs::try_from(Crs::default()).unwrap(), common::Crs::default());
assert_eq!(common::Crs::default(), Crs::default().try_into().unwrap());

// assert_eq!(Crs::from(common::Crs::default()), Crs::default());
assert_eq!(Crs::default(), common::Crs::default().into());
}
}
178 changes: 178 additions & 0 deletions ogcapi-types/src/movingfeatures/mfjson_temporal_properties.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,178 @@
use std::collections::HashMap;

use chrono::{DateTime, Utc};
use serde::{ser, Deserialize, Serialize, Serializer};
use serde_json::json;
use utoipa::ToSchema;

use super::temporal_property::Interpolation;

/// MF-JSON TemporalProperties
///
/// A TemporalProperties object is a JSON array of ParametricValues objects that groups a collection of dynamic
/// non-spatial attributes and its parametric values with time.
///
/// See [7.2.2 MF-JSON TemporalProperties](https://docs.ogc.org/is/19-045r3/19-045r3.html#tproperties)
///
/// Opposed to [TemporalProperty](super::temporal_property::TemporalProperty) values for all
/// represented properties are all measured at the same points in time.
// TODO enforce same length of datetimes and values
#[derive(Deserialize, Debug, Clone, PartialEq, ToSchema)]
pub struct MFJsonTemporalProperties {
pub datetimes: Vec<DateTime<Utc>>,
#[serde(flatten)]
pub values: HashMap<String, ParametricValues>,
}

#[derive(Debug, Clone, PartialEq, Deserialize)]
struct MFJsonTemporalPropertiesUnchecked {
datetimes: Vec<DateTime<Utc>>,
values: HashMap<String, ParametricValues>,
}

impl TryFrom<MFJsonTemporalPropertiesUnchecked> for MFJsonTemporalProperties {
type Error = &'static str;

fn try_from(value: MFJsonTemporalPropertiesUnchecked) -> Result<Self, Self::Error> {
let dt_len = value.datetimes.len();
if value.values.values().all(|property| property.len() == dt_len) {
Err("all values and datetimes must be of same length")
} else {
Ok(Self {
datetimes: value.datetimes,
values: value.values,
})
}
}
}

impl Serialize for MFJsonTemporalProperties {
fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error>
where
S: Serializer,
{
let dt_len = self.datetimes.len();
if self.values.values().all(|property| property.len() == dt_len) {
Err(ser::Error::custom(
"all values and datetimes must be of same length",
))
} else {
let value = json!(self);
value.serialize(serializer)
}
}
}

/// A ParametricValues object is a JSON object that represents a collection of parametric values of dynamic non-spatial
/// attributes that are ascertained at the same times. A parametric value may be a time-varying measure, a sequence of
/// texts, or a sequence of images. Even though the parametric value may depend on the spatiotemporal location,
/// MF-JSON Prism only considers the temporal dependencies of their changes of value.
///
/// See [7.2.2.1 MF-JSON ParametricValues](https://docs.ogc.org/is/19-045r3/19-045r3.html#pvalues)
#[derive(Serialize, Deserialize, Debug, Clone, PartialEq, ToSchema)]
#[serde(tag = "type")]
pub enum ParametricValues {
/// The "values" member contains any numeric values.
Measure {
values: Vec<f64>,
/// Allowed Interpolations: Discrete, Step, Linear, Regression
interpolation: Option<Interpolation>,
description: Option<f64>,
/// The "form" member is optional and its value is a JSON string as a common code (3 characters) described in
/// the [Code List Rec 20 by the UN Centre for Trade Facilitation and Electronic Business (UN/CEFACT)](https://www.unece.org/uncefact/codelistrecs.html) or a
/// URL specifying the unit of measurement. This member is applied only for a temporal property whose value
/// type is Measure.
form: Option<String>,
},
/// The "values" member contains any strings.
Text {
values: Vec<String>,
/// Allowed Interpolations: Discrete, Step
// TODO enforce?
interpolation: Option<Interpolation>,
description: Option<String>,
},
/// The "values" member contains Base64 strings converted from images or URLs to address images.
Image {
values: Vec<String>,
/// Allowed Interpolations: Discrete, Step
// TODO enforce?
interpolation: Option<Interpolation>,
description: Option<String>,
},
}

impl ParametricValues {
fn len(&self) -> usize {
match self {
Self::Measure{values, ..} => values.len(),
Self::Text{values, ..} => values.len(),
Self::Image{values, ..} => values.len(),
}
}
}

#[cfg(test)]
mod tests {

use super::*;

#[test]
fn serde_mfjson_temporal_properties() {
// https://developer.ogc.org/api/movingfeatures/index.html#tag/TemporalProperty/operation/insertTemporalProperty
let tp_json = r#"[
{
"datetimes": [
"2011-07-14T22:01:01.450Z",
"2011-07-14T23:01:01.450Z",
"2011-07-15T00:01:01.450Z"
],
"length": {
"type": "Measure",
"form": "http://qudt.org/vocab/quantitykind/Length",
"values": [
1,
2.4,
1
],
"interpolation": "Linear"
},
"discharge": {
"type": "Measure",
"form": "MQS",
"values": [
3,
4,
5
],
"interpolation": "Step"
}
},
{
"datetimes": [
"2011-07-14T22:01:01.450Z",
"2011-07-14T23:01:01.450Z"
],
"camera": {
"type": "Image",
"values": [
"http://www.opengis.net/spec/movingfeatures/json/1.0/prism/example/image1",
"iVBORw0KGgoAAAANSUhEU......"
],
"interpolation": "Discrete"
},
"labels": {
"type": "Text",
"values": [
"car",
"human"
],
"interpolation": "Discrete"
}
}
]"#;

let _: Vec<MFJsonTemporalProperties> =
serde_json::from_str(tp_json).expect("Failed to parse MF-JSON Temporal Properties");
}
}
Loading
Loading