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

geo-engine / geoengine / 3929938005

pending completion
3929938005

push

github

GitHub
Merge #713

84930 of 96741 relevant lines covered (87.79%)

79640.1 hits per line

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

81.32
/operators/src/util/input/multi_raster_or_vector.rs
1
use crate::engine::{OperatorData, RasterOperator, VectorOperator};
2
use geoengine_datatypes::dataset::DataId;
3
use serde::{Deserialize, Serialize};
4

5
/// It is either a set of `RasterOperator` or a single `VectorOperator`
6
#[derive(Debug, Clone, Serialize, Deserialize)]
15✔
7
#[serde(untagged)]
8
pub enum MultiRasterOrVectorOperator {
9
    Raster(Vec<Box<dyn RasterOperator>>),
10
    Vector(Box<dyn VectorOperator>),
11
}
12

13
impl MultiRasterOrVectorOperator {
14
    pub fn is_raster(&self) -> bool {
2✔
15
        match self {
2✔
16
            Self::Raster(_) => true,
1✔
17
            Self::Vector(_) => false,
1✔
18
        }
19
    }
2✔
20

21
    pub fn is_vector(&self) -> bool {
2✔
22
        match self {
2✔
23
            Self::Raster(_) => false,
1✔
24
            Self::Vector(_) => true,
1✔
25
        }
26
    }
2✔
27
}
28

29
impl From<Box<dyn RasterOperator>> for MultiRasterOrVectorOperator {
30
    fn from(operator: Box<dyn RasterOperator>) -> Self {
×
31
        Self::Raster(vec![operator])
×
32
    }
×
33
}
34

35
impl From<Vec<Box<dyn RasterOperator>>> for MultiRasterOrVectorOperator {
36
    fn from(operators: Vec<Box<dyn RasterOperator>>) -> Self {
×
37
        Self::Raster(operators)
×
38
    }
×
39
}
40

41
impl From<Box<dyn VectorOperator>> for MultiRasterOrVectorOperator {
42
    fn from(operator: Box<dyn VectorOperator>) -> Self {
×
43
        Self::Vector(operator)
×
44
    }
×
45
}
46

47
impl OperatorData for MultiRasterOrVectorOperator {
48
    fn data_ids_collect(&self, data_ids: &mut Vec<DataId>) {
×
49
        match self {
×
50
            Self::Raster(rs) => {
×
51
                for r in rs {
×
52
                    r.data_ids_collect(data_ids);
×
53
                }
×
54
            }
55
            Self::Vector(v) => v.data_ids_collect(data_ids),
×
56
        }
57
    }
×
58
}
59

60
#[cfg(test)]
61
mod tests {
62
    use crate::source::{GdalSource, GdalSourceParameters};
63
    use geoengine_datatypes::dataset::DatasetId;
64
    use std::str::FromStr;
65

66
    use super::*;
67

68
    #[test]
1✔
69
    fn it_serializes() {
1✔
70
        let operator = MultiRasterOrVectorOperator::Raster(vec![GdalSource {
1✔
71
            params: GdalSourceParameters {
1✔
72
                data: DatasetId::from_str("fc734022-61e0-49da-b327-257ba9d602a7")
1✔
73
                    .unwrap()
1✔
74
                    .into(),
1✔
75
            },
1✔
76
        }
1✔
77
        .boxed()]);
1✔
78

1✔
79
        assert_eq!(
1✔
80
            serde_json::to_value(&operator).unwrap(),
1✔
81
            serde_json::json!([{
1✔
82
                "type": "GdalSource",
1✔
83
                "params": {
1✔
84
                    "data": {
1✔
85
                        "type": "internal",
1✔
86
                        "datasetId": "fc734022-61e0-49da-b327-257ba9d602a7"
1✔
87
                    }
1✔
88
                }
1✔
89
            }])
1✔
90
        );
1✔
91
    }
1✔
92

93
    #[test]
1✔
94
    fn it_deserializes_raster_ops() {
1✔
95
        let workflow = serde_json::json!([{
1✔
96
            "type": "GdalSource",
1✔
97
            "params": {
1✔
98
                "data": {
1✔
99
                    "type": "internal",
1✔
100
                    "datasetId":  "fc734022-61e0-49da-b327-257ba9d602a7"
1✔
101
                }
1✔
102
            }
1✔
103
        }])
1✔
104
        .to_string();
1✔
105

1✔
106
        let raster_or_vector_operator: MultiRasterOrVectorOperator =
1✔
107
            serde_json::from_str(&workflow).unwrap();
1✔
108

1✔
109
        assert!(raster_or_vector_operator.is_raster());
1✔
110
        assert!(!raster_or_vector_operator.is_vector());
1✔
111
    }
1✔
112

113
    #[test]
1✔
114
    fn it_deserializes_vector_ops() {
1✔
115
        let workflow = serde_json::json!({
1✔
116
            "type": "OgrSource",
1✔
117
            "params": {
1✔
118
                "data": {
1✔
119
                    "type": "internal",
1✔
120
                    "datasetId":  "fc734022-61e0-49da-b327-257ba9d602a7"
1✔
121
                },
1✔
122
                "attribute_projection": null,
1✔
123
            }
1✔
124
        })
1✔
125
        .to_string();
1✔
126

1✔
127
        let raster_or_vector_operator: MultiRasterOrVectorOperator =
1✔
128
            serde_json::from_str(&workflow).unwrap();
1✔
129

1✔
130
        assert!(raster_or_vector_operator.is_vector());
1✔
131
        assert!(!raster_or_vector_operator.is_raster());
1✔
132
    }
1✔
133
}
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