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

geo-engine / geoengine / 21680169493

04 Feb 2026 04:46PM UTC coverage: 88.33%. First build
21680169493

Pull #1116

github

web-flow
Merge ab9b2e6a0 into 078c12706
Pull Request #1116: feat: Operators in OpenAPI

267 of 378 new or added lines in 4 files covered. (70.63%)

116136 of 131480 relevant lines covered (88.33%)

493793.39 hits per line

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

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

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

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

52
    /// *Optional*: overview level to use.
53
    ///
54
    /// If not provided, the data source will determine the resolution, i.e., uses its native resolution.
55
    pub overview_level: Option<u32>,
56
}
57

58
impl TryFrom<GdalSource> for OperatorsGdalSource {
59
    type Error = anyhow::Error;
60
    fn try_from(value: GdalSource) -> Result<Self, Self::Error> {
4✔
61
        Ok(OperatorsGdalSource {
62
            params: OperatorsGdalSourceParameters {
63
                data: serde_json::from_str::<NamedData>(&serde_json::to_string(
4✔
64
                    &value.params.data,
4✔
NEW
65
                )?)?,
×
66
                overview_level: value.params.overview_level,
4✔
67
            },
68
        })
69
    }
4✔
70
}
71

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

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

102
    /// Defines how the spatial bounds of the source are derived.
103
    ///
104
    /// Defaults to `None`.
105
    pub spatial_bounds: SpatialBoundsDerive,
106
}
107

108
impl TryFrom<MockPointSource> for OperatorsMockPointSource {
109
    type Error = anyhow::Error;
110
    fn try_from(value: MockPointSource) -> Result<Self, Self::Error> {
3✔
111
        Ok(OperatorsMockPointSource {
112
            params: OperatorsMockPointSourceParameters {
113
                points: value.params.points.into_iter().map(Into::into).collect(),
3✔
114
                spatial_bounds: value.params.spatial_bounds.try_into()?,
3✔
115
            },
116
        })
117
    }
3✔
118
}
119

120
#[cfg(test)]
121
mod tests {
122
    use super::*;
123
    use crate::processes::{RasterOperator, TypedOperator, VectorOperator};
124
    use geoengine_operators::engine::TypedOperator as OperatorsTypedOperator;
125

126
    #[test]
127
    fn it_converts_into_gdal_source() {
1✔
128
        let api_operator = GdalSource {
1✔
129
            r#type: Default::default(),
1✔
130
            params: GdalSourceParameters {
1✔
131
                data: "example_dataset".to_string(),
1✔
132
                overview_level: None,
1✔
133
            },
1✔
134
        };
1✔
135

136
        let operators_operator: OperatorsGdalSource =
1✔
137
            api_operator.try_into().expect("it should convert");
1✔
138

139
        assert_eq!(
1✔
140
            operators_operator.params.data,
141
            NamedData::with_system_name("example_dataset")
1✔
142
        );
143

144
        let typed_operator = TypedOperator::Raster(RasterOperator::GdalSource(GdalSource {
1✔
145
            r#type: Default::default(),
1✔
146
            params: GdalSourceParameters {
1✔
147
                data: "example_dataset".to_string(),
1✔
148
                overview_level: None,
1✔
149
            },
1✔
150
        }));
1✔
151

152
        OperatorsTypedOperator::try_from(typed_operator).expect("it should convert");
1✔
153
    }
1✔
154

155
    #[test]
156
    fn it_converts_mock_point_source() {
1✔
157
        let api_operator = MockPointSource {
1✔
158
            r#type: Default::default(),
1✔
159
            params: MockPointSourceParameters {
1✔
160
                points: vec![
1✔
161
                    Coordinate2D { x: 1.0, y: 2.0 },
1✔
162
                    Coordinate2D { x: 3.0, y: 4.0 },
1✔
163
                ],
1✔
164
                spatial_bounds: SpatialBoundsDerive::Derive(Default::default()),
1✔
165
            },
1✔
166
        };
1✔
167

168
        let operators_operator: OperatorsMockPointSource =
1✔
169
            api_operator.try_into().expect("it should convert");
1✔
170

171
        assert_eq!(
1✔
172
            operators_operator.params.points,
173
            vec![
1✔
174
                geoengine_datatypes::primitives::Coordinate2D { x: 1.0, y: 2.0 },
1✔
175
                geoengine_datatypes::primitives::Coordinate2D { x: 3.0, y: 4.0 }
1✔
176
            ]
177
        );
178

179
        let typed_operator =
1✔
180
            TypedOperator::Vector(VectorOperator::MockPointSource(MockPointSource {
1✔
181
                r#type: Default::default(),
1✔
182
                params: MockPointSourceParameters {
1✔
183
                    points: vec![Coordinate2D { x: 1.0, y: 2.0 }],
1✔
184
                    spatial_bounds: SpatialBoundsDerive::Derive(Default::default()),
1✔
185
                },
1✔
186
            }));
1✔
187

188
        OperatorsTypedOperator::try_from(typed_operator).expect("it should convert");
1✔
189
    }
1✔
190
}
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