• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

geo-engine / geoengine / 21632607119

03 Feb 2026 01:43PM UTC coverage: 88.773%. First build
21632607119

Pull #1116

github

web-flow
Merge 96e6643b8 into 0a5e73d64
Pull Request #1116: feat: Operators in OpenAPI

202 of 311 new or added lines in 4 files covered. (64.95%)

106632 of 120117 relevant lines covered (88.77%)

83952.55 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

98.21
/api/src/processes/source.rs
1
use geoengine_datatypes::dataset::NamedData;
2
use geoengine_macros::type_tag;
3
use geoengine_operators::{
4
    mock::{
5
        MockPointSource as OperatorsMockPointSource,
6
        MockPointSourceParams as OperatorsMockPointSourceParameters,
7
    },
8
    source::{
9
        GdalSource as OperatorsGdalSource, GdalSourceParameters as OperatorsGdalSourceParameters,
10
    },
11
};
12
use serde::{Deserialize, Serialize};
13
use utoipa::ToSchema;
14

15
use crate::parameters::Coordinate2D;
16

17
/// # GdalSource
18
///
19
/// The [`GdalSource`] is a source operator that reads raster data using GDAL.
20
/// The counterpart for vector data is the [`OgrSource`].
21
///
22
/// ## Errors
23
///
24
/// If the given dataset does not exist or is not readable, an error is thrown.
25
///
26
/// ## Example JSON
27
///
28
/// ```json
29
/// {
30
///   "type": "GdalSource",
31
///   "params": {
32
///     "data": "ndvi"
33
///   }
34
/// }
35
/// ```
36
#[type_tag(value = "GdalSource")]
37
#[derive(Debug, Serialize, Deserialize, Clone, PartialEq, ToSchema)]
38
#[serde(rename_all = "camelCase")]
39
pub struct GdalSource {
40
    pub params: GdalSourceParameters,
41
}
42

43
/// Parameters for the [`GdalSource`] operator.
44
#[derive(Debug, Serialize, Deserialize, Clone, PartialEq, ToSchema)]
45
#[serde(rename_all = "camelCase")]
46
pub struct GdalSourceParameters {
47
    /// Dataset name or identifier to be loaded.
48
    ///
49
    /// ### Example
50
    /// `"ndvi"`
51
    pub data: String,
52
}
53

54
impl TryFrom<GdalSource> for OperatorsGdalSource {
55
    type Error = anyhow::Error;
56
    fn try_from(value: GdalSource) -> Result<Self, Self::Error> {
2✔
57
        Ok(OperatorsGdalSource {
58
            params: OperatorsGdalSourceParameters {
59
                data: serde_json::from_str::<NamedData>(&serde_json::to_string(
2✔
60
                    &value.params.data,
2✔
NEW
61
                )?)?,
×
62
            },
63
        })
64
    }
2✔
65
}
66

67
/// # MockPointSource
68
///
69
/// The [`MockPointSource`] is a source operator that provides mock vector point data for testing and development purposes.
70
///
71
/// ## Example JSON
72
/// ```json
73
/// {
74
///   "type": "MockPointSource",
75
///   "params": {
76
///     "points": [ { "x": 1.0, "y": 2.0 }, { "x": 3.0, "y": 4.0 } ]
77
///   }
78
/// }
79
/// ```
80
#[type_tag(value = "MockPointSource")]
81
#[derive(Debug, Serialize, Deserialize, Clone, PartialEq, ToSchema)]
82
#[serde(rename_all = "camelCase")]
83
pub struct MockPointSource {
84
    pub params: MockPointSourceParameters,
85
}
86

87
/// Parameters for the [`MockPointSource`] operator.
88
#[derive(Debug, Serialize, Deserialize, Clone, PartialEq, ToSchema)]
89
#[serde(rename_all = "camelCase")]
90
pub struct MockPointSourceParameters {
91
    /// Points to be output by the mock point source.
92
    ///
93
    /// ### Example
94
    /// `[{"x": 1.0, "y": 2.0}, {"x": 3.0, "y": 4.0}]`
95
    pub points: Vec<Coordinate2D>,
96
}
97

98
impl TryFrom<MockPointSource> for OperatorsMockPointSource {
99
    type Error = anyhow::Error;
100
    fn try_from(value: MockPointSource) -> Result<Self, Self::Error> {
2✔
101
        Ok(OperatorsMockPointSource {
2✔
102
            params: OperatorsMockPointSourceParameters {
2✔
103
                points: value.params.points.into_iter().map(Into::into).collect(),
2✔
104
            },
2✔
105
        })
2✔
106
    }
2✔
107
}
108

109
#[cfg(test)]
110
mod tests {
111
    use super::*;
112
    use crate::processes::{RasterOperator, TypedOperator, VectorOperator};
113
    use geoengine_operators::engine::TypedOperator as OperatorsTypedOperator;
114

115
    #[test]
116
    fn it_converts_into_gdal_source() {
1✔
117
        let api_operator = GdalSource {
1✔
118
            r#type: Default::default(),
1✔
119
            params: GdalSourceParameters {
1✔
120
                data: "example_dataset".to_string(),
1✔
121
            },
1✔
122
        };
1✔
123

124
        let operators_operator: OperatorsGdalSource =
1✔
125
            api_operator.try_into().expect("it should convert");
1✔
126

127
        assert_eq!(
1✔
128
            operators_operator.params.data,
129
            NamedData::with_system_name("example_dataset")
1✔
130
        );
131

132
        let typed_operator = TypedOperator::Raster(RasterOperator::GdalSource(GdalSource {
1✔
133
            r#type: Default::default(),
1✔
134
            params: GdalSourceParameters {
1✔
135
                data: "example_dataset".to_string(),
1✔
136
            },
1✔
137
        }));
1✔
138

139
        OperatorsTypedOperator::try_from(typed_operator).expect("it should convert");
1✔
140
    }
1✔
141

142
    #[test]
143
    fn it_converts_mock_point_source() {
1✔
144
        let api_operator = MockPointSource {
1✔
145
            r#type: Default::default(),
1✔
146
            params: MockPointSourceParameters {
1✔
147
                points: vec![
1✔
148
                    Coordinate2D { x: 1.0, y: 2.0 },
1✔
149
                    Coordinate2D { x: 3.0, y: 4.0 },
1✔
150
                ],
1✔
151
            },
1✔
152
        };
1✔
153

154
        let operators_operator: OperatorsMockPointSource =
1✔
155
            api_operator.try_into().expect("it should convert");
1✔
156

157
        assert_eq!(
1✔
158
            operators_operator.params.points,
159
            vec![
1✔
160
                geoengine_datatypes::primitives::Coordinate2D { x: 1.0, y: 2.0 },
1✔
161
                geoengine_datatypes::primitives::Coordinate2D { x: 3.0, y: 4.0 }
1✔
162
            ]
163
        );
164

165
        let typed_operator =
1✔
166
            TypedOperator::Vector(VectorOperator::MockPointSource(MockPointSource {
1✔
167
                r#type: Default::default(),
1✔
168
                params: MockPointSourceParameters {
1✔
169
                    points: vec![Coordinate2D { x: 1.0, y: 2.0 }],
1✔
170
                },
1✔
171
            }));
1✔
172

173
        OperatorsTypedOperator::try_from(typed_operator).expect("it should convert");
1✔
174
    }
1✔
175
}
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2026 Coveralls, Inc