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

geo-engine / geoengine / 7006568925

27 Nov 2023 02:07PM UTC coverage: 89.651% (+0.2%) from 89.498%
7006568925

push

github

web-flow
Merge pull request #888 from geo-engine/raster_stacks

raster stacking

4032 of 4274 new or added lines in 107 files covered. (94.34%)

12 existing lines in 8 files now uncovered.

113020 of 126066 relevant lines covered (89.65%)

59901.79 hits per line

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

93.55
/datatypes/src/primitives/query_rectangle.rs
1
use super::{
2
    AxisAlignedRectangle, BoundingBox2D, SpatialPartition2D, SpatialPartitioned, SpatialResolution,
3
    TimeInterval,
4
};
5
use serde::{Deserialize, Serialize};
6

7
/// A spatio-temporal rectangle with a specified resolution and the selected bands
8
#[derive(Clone, Debug, PartialEq, Serialize, Deserialize)]
1,102✔
9
#[serde(rename_all = "camelCase")]
10
pub struct QueryRectangle<
11
    SpatialBounds: AxisAlignedRectangle,
12
    AttributeSelection: QueryAttributeSelection,
13
> {
14
    pub spatial_bounds: SpatialBounds,
15
    pub time_interval: TimeInterval,
16
    pub spatial_resolution: SpatialResolution,
17
    pub attributes: AttributeSelection,
18
}
19

20
pub trait QueryAttributeSelection: Clone + Send + Sync {}
21

22
#[derive(Clone, Debug, PartialEq, Serialize, Deserialize)]
734✔
23
// TODO: custom deserializer that checks for duplicates (at least in API)
24
pub struct BandSelection(Vec<usize>);
25

26
impl BandSelection {
27
    pub fn new(mut bands: Vec<usize>) -> Self {
23✔
28
        fn has_no_duplicates<T: std::hash::Hash + std::cmp::Eq>(vec: &[T]) -> bool {
23✔
29
            let set: std::collections::HashSet<_> = vec.iter().collect();
23✔
30
            set.len() == vec.len()
23✔
31
        }
23✔
32
        // TODO: `ensure` instead of `debug_assert`?
33
        debug_assert!(has_no_duplicates(&bands), "Input bands have duplicates");
23✔
34
        debug_assert!(!bands.is_empty(), "Input bands empty");
23✔
35

36
        bands.sort_unstable(); // TODO: should order of bands matter? Or: introduce a restacking operation?
23✔
37
        Self(bands)
23✔
38
    }
23✔
39

40
    pub fn first() -> Self {
242✔
41
        Self(vec![0])
242✔
42
    }
242✔
43

44
    pub fn first_n(n: usize) -> Self {
7✔
45
        Self((0..n).collect())
7✔
46
    }
7✔
47

NEW
48
    pub fn new_single(band: usize) -> Self {
×
NEW
49
        Self(vec![band])
×
NEW
50
    }
×
51

52
    pub fn count(&self) -> usize {
178✔
53
        self.0.len()
178✔
54
    }
178✔
55

56
    pub fn as_slice(&self) -> &[usize] {
156✔
57
        &self.0
156✔
58
    }
156✔
59

60
    pub fn as_vec(&self) -> Vec<usize> {
31✔
61
        self.0.clone()
31✔
62
    }
31✔
63
}
64

65
impl From<usize> for BandSelection {
66
    fn from(value: usize) -> Self {
188✔
67
        Self(vec![value])
188✔
68
    }
188✔
69
}
70

71
impl From<Vec<usize>> for BandSelection {
NEW
72
    fn from(value: Vec<usize>) -> Self {
×
NEW
73
        Self::new(value)
×
NEW
74
    }
×
75
}
76

77
impl<const N: usize> From<[usize; N]> for BandSelection {
78
    fn from(value: [usize; N]) -> Self {
6✔
79
        Self::new(value.to_vec())
6✔
80
    }
6✔
81
}
82

83
impl QueryAttributeSelection for BandSelection {}
84

85
#[derive(Copy, Clone, Debug, PartialEq, Serialize, Deserialize)]
363✔
86
pub struct ColumnSelection {}
87

88
impl ColumnSelection {
89
    pub fn all() -> Self {
156✔
90
        Self {}
156✔
91
    }
156✔
92
}
93

94
impl QueryAttributeSelection for ColumnSelection {}
95

96
#[derive(Copy, Clone, Debug, PartialEq, Serialize, Deserialize)]
18✔
97
pub struct PlotSeriesSelection {}
98

99
impl PlotSeriesSelection {
100
    pub fn all() -> Self {
52✔
101
        Self {}
52✔
102
    }
52✔
103
}
104

105
impl QueryAttributeSelection for PlotSeriesSelection {}
106

107
pub type VectorQueryRectangle = QueryRectangle<BoundingBox2D, ColumnSelection>;
108
pub type RasterQueryRectangle = QueryRectangle<SpatialPartition2D, BandSelection>;
109
pub type PlotQueryRectangle = QueryRectangle<BoundingBox2D, PlotSeriesSelection>;
110

111
impl RasterQueryRectangle {
112
    pub fn from_qrect_and_bands<A>(
46✔
113
        query: &QueryRectangle<BoundingBox2D, A>,
46✔
114
        bands: BandSelection,
46✔
115
    ) -> Self
46✔
116
    where
46✔
117
        A: QueryAttributeSelection,
46✔
118
        QueryRectangle<BoundingBox2D, A>: SpatialPartitioned,
46✔
119
    {
46✔
120
        Self {
46✔
121
            spatial_bounds: query.spatial_partition(),
46✔
122
            time_interval: query.time_interval,
46✔
123
            spatial_resolution: query.spatial_resolution,
46✔
124
            attributes: bands,
46✔
125
        }
46✔
126
    }
46✔
127
}
128

129
impl SpatialPartitioned for QueryRectangle<BoundingBox2D, ColumnSelection> {
130
    fn spatial_partition(&self) -> SpatialPartition2D {
19✔
131
        SpatialPartition2D::with_bbox_and_resolution(self.spatial_bounds, self.spatial_resolution)
19✔
132
    }
19✔
133
}
134

135
impl SpatialPartitioned for QueryRectangle<BoundingBox2D, PlotSeriesSelection> {
136
    fn spatial_partition(&self) -> SpatialPartition2D {
27✔
137
        SpatialPartition2D::with_bbox_and_resolution(self.spatial_bounds, self.spatial_resolution)
27✔
138
    }
27✔
139
}
140

141
impl SpatialPartitioned for QueryRectangle<SpatialPartition2D, BandSelection> {
142
    fn spatial_partition(&self) -> SpatialPartition2D {
468✔
143
        self.spatial_bounds
468✔
144
    }
468✔
145
}
146

147
impl From<QueryRectangle<BoundingBox2D, ColumnSelection>>
148
    for QueryRectangle<BoundingBox2D, PlotSeriesSelection>
149
{
150
    fn from(value: QueryRectangle<BoundingBox2D, ColumnSelection>) -> Self {
2✔
151
        Self {
2✔
152
            spatial_bounds: value.spatial_bounds,
2✔
153
            time_interval: value.time_interval,
2✔
154
            spatial_resolution: value.spatial_resolution,
2✔
155
            attributes: value.attributes.into(),
2✔
156
        }
2✔
157
    }
2✔
158
}
159

160
impl From<QueryRectangle<BoundingBox2D, PlotSeriesSelection>>
161
    for QueryRectangle<BoundingBox2D, ColumnSelection>
162
{
163
    fn from(value: QueryRectangle<BoundingBox2D, PlotSeriesSelection>) -> Self {
33✔
164
        Self {
33✔
165
            spatial_bounds: value.spatial_bounds,
33✔
166
            time_interval: value.time_interval,
33✔
167
            spatial_resolution: value.spatial_resolution,
33✔
168
            attributes: value.attributes.into(),
33✔
169
        }
33✔
170
    }
33✔
171
}
172

173
impl From<ColumnSelection> for PlotSeriesSelection {
174
    fn from(_: ColumnSelection) -> Self {
2✔
175
        Self {}
2✔
176
    }
2✔
177
}
178

179
impl From<PlotSeriesSelection> for ColumnSelection {
180
    fn from(_: PlotSeriesSelection) -> Self {
33✔
181
        Self {}
33✔
182
    }
33✔
183
}
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