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

geo-engine / geoengine / 7142165995

08 Dec 2023 01:12PM UTC coverage: 89.675% (+0.01%) from 89.665%
7142165995

push

github

web-flow
Merge pull request #895 from geo-engine/raster_colorizer_bands

add raster colorizer for bands

722 of 783 new or added lines in 33 files covered. (92.21%)

13 existing lines in 10 files now uncovered.

113148 of 126176 relevant lines covered (89.67%)

59847.82 hits per line

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

96.88
/datatypes/src/primitives/query_rectangle.rs
1
use super::{
2
    AxisAlignedRectangle, BoundingBox2D, SpatialPartition2D, SpatialPartitioned, SpatialResolution,
3
    TimeInterval,
4
};
5
use crate::{
6
    error::{DuplicateBandInQueryBandSelection, QueryBandSelectionMustNotBeEmpty},
7
    util::Result,
8
};
9
use serde::{Deserialize, Serialize};
10
use snafu::ensure;
11

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

25
pub trait QueryAttributeSelection: Clone + Send + Sync {}
26

27
#[derive(Clone, Debug, PartialEq, Serialize)]
734✔
28

29
pub struct BandSelection(Vec<u32>);
30

31
impl BandSelection {
32
    pub fn new(bands: Vec<u32>) -> Result<Self> {
6✔
33
        fn has_no_duplicates<T: std::hash::Hash + std::cmp::Eq>(vec: &[T]) -> bool {
6✔
34
            let set: std::collections::HashSet<_> = vec.iter().collect();
6✔
35
            set.len() == vec.len()
6✔
36
        }
6✔
37

6✔
38
        ensure!(has_no_duplicates(&bands), DuplicateBandInQueryBandSelection);
6✔
39
        ensure!(!bands.is_empty(), QueryBandSelectionMustNotBeEmpty);
6✔
40

41
        Ok(Self(bands))
6✔
42
    }
6✔
43

44
    pub fn new_unchecked(bands: Vec<u32>) -> Self {
17✔
45
        Self(bands)
17✔
46
    }
17✔
47

48
    pub fn first() -> Self {
226✔
49
        Self(vec![0])
226✔
50
    }
226✔
51

52
    pub fn first_n(n: u32) -> Self {
7✔
53
        Self((0..n).collect())
7✔
54
    }
7✔
55

56
    pub fn new_single(band: u32) -> Self {
16✔
57
        Self(vec![band])
16✔
58
    }
16✔
59

60
    pub fn count(&self) -> u32 {
178✔
61
        self.0.len() as u32
178✔
62
    }
178✔
63

64
    pub fn as_slice(&self) -> &[u32] {
156✔
65
        &self.0
156✔
66
    }
156✔
67

68
    pub fn as_vec(&self) -> Vec<u32> {
31✔
69
        self.0.clone()
31✔
70
    }
31✔
71
}
72

73
impl From<u32> for BandSelection {
74
    fn from(value: u32) -> Self {
188✔
75
        Self(vec![value])
188✔
76
    }
188✔
77
}
78

79
impl TryFrom<Vec<u32>> for BandSelection {
80
    type Error = crate::error::Error;
81

NEW
82
    fn try_from(value: Vec<u32>) -> Result<Self, Self::Error> {
×
83
        Self::new(value)
×
84
    }
×
85
}
86

87
impl<const N: usize> TryFrom<[u32; N]> for BandSelection {
88
    type Error = crate::error::Error;
89

90
    fn try_from(value: [u32; N]) -> Result<Self, Self::Error> {
6✔
91
        Self::new(value.to_vec())
6✔
92
    }
6✔
93
}
94

95
impl QueryAttributeSelection for BandSelection {}
96

97
#[derive(Copy, Clone, Debug, PartialEq, Serialize, Deserialize)]
363✔
98
pub struct ColumnSelection {}
99

100
impl ColumnSelection {
101
    pub fn all() -> Self {
156✔
102
        Self {}
156✔
103
    }
156✔
104
}
105

106
impl QueryAttributeSelection for ColumnSelection {}
107

108
#[derive(Copy, Clone, Debug, PartialEq, Serialize, Deserialize)]
18✔
109
pub struct PlotSeriesSelection {}
110

111
impl PlotSeriesSelection {
112
    pub fn all() -> Self {
52✔
113
        Self {}
52✔
114
    }
52✔
115
}
116

117
impl QueryAttributeSelection for PlotSeriesSelection {}
118

119
pub type VectorQueryRectangle = QueryRectangle<BoundingBox2D, ColumnSelection>;
120
pub type RasterQueryRectangle = QueryRectangle<SpatialPartition2D, BandSelection>;
121
pub type PlotQueryRectangle = QueryRectangle<BoundingBox2D, PlotSeriesSelection>;
122

123
impl RasterQueryRectangle {
124
    pub fn from_qrect_and_bands<A>(
46✔
125
        query: &QueryRectangle<BoundingBox2D, A>,
46✔
126
        bands: BandSelection,
46✔
127
    ) -> Self
46✔
128
    where
46✔
129
        A: QueryAttributeSelection,
46✔
130
        QueryRectangle<BoundingBox2D, A>: SpatialPartitioned,
46✔
131
    {
46✔
132
        Self {
46✔
133
            spatial_bounds: query.spatial_partition(),
46✔
134
            time_interval: query.time_interval,
46✔
135
            spatial_resolution: query.spatial_resolution,
46✔
136
            attributes: bands,
46✔
137
        }
46✔
138
    }
46✔
139
}
140

141
impl SpatialPartitioned for QueryRectangle<BoundingBox2D, ColumnSelection> {
142
    fn spatial_partition(&self) -> SpatialPartition2D {
19✔
143
        SpatialPartition2D::with_bbox_and_resolution(self.spatial_bounds, self.spatial_resolution)
19✔
144
    }
19✔
145
}
146

147
impl SpatialPartitioned for QueryRectangle<BoundingBox2D, PlotSeriesSelection> {
148
    fn spatial_partition(&self) -> SpatialPartition2D {
27✔
149
        SpatialPartition2D::with_bbox_and_resolution(self.spatial_bounds, self.spatial_resolution)
27✔
150
    }
27✔
151
}
152

153
impl SpatialPartitioned for QueryRectangle<SpatialPartition2D, BandSelection> {
154
    fn spatial_partition(&self) -> SpatialPartition2D {
468✔
155
        self.spatial_bounds
468✔
156
    }
468✔
157
}
158

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

172
impl From<QueryRectangle<BoundingBox2D, PlotSeriesSelection>>
173
    for QueryRectangle<BoundingBox2D, ColumnSelection>
174
{
175
    fn from(value: QueryRectangle<BoundingBox2D, PlotSeriesSelection>) -> Self {
33✔
176
        Self {
33✔
177
            spatial_bounds: value.spatial_bounds,
33✔
178
            time_interval: value.time_interval,
33✔
179
            spatial_resolution: value.spatial_resolution,
33✔
180
            attributes: value.attributes.into(),
33✔
181
        }
33✔
182
    }
33✔
183
}
184

185
impl From<ColumnSelection> for PlotSeriesSelection {
186
    fn from(_: ColumnSelection) -> Self {
2✔
187
        Self {}
2✔
188
    }
2✔
189
}
190

191
impl From<PlotSeriesSelection> for ColumnSelection {
192
    fn from(_: PlotSeriesSelection) -> Self {
33✔
193
        Self {}
33✔
194
    }
33✔
195
}
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