Skip to content

Commit 2b0810e

Browse files
Merge pull request #332 from geo-engine/sentinel_config
make bands and zones configurable
2 parents 372b41c + f207fbb commit 2b0810e

File tree

2 files changed

+68
-50
lines changed

2 files changed

+68
-50
lines changed

services/src/pro/datasets/external/sentinel_s2_l2a_cogs.rs

Lines changed: 13 additions & 49 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,8 @@ pub struct SentinelS2L2ACogsProviderDefinition {
4040
name: String,
4141
id: DatasetProviderId,
4242
api_url: String,
43+
bands: Vec<Band>,
44+
zones: Vec<Zone>,
4345
}
4446

4547
#[typetag::serde]
@@ -51,6 +53,8 @@ impl DatasetProviderDefinition for SentinelS2L2ACogsProviderDefinition {
5153
Ok(Box::new(SentinelS2L2aCogsDataProvider::new(
5254
self.id,
5355
self.api_url,
56+
&self.bands,
57+
&self.zones,
5458
)))
5559
}
5660

@@ -67,41 +71,20 @@ impl DatasetProviderDefinition for SentinelS2L2ACogsProviderDefinition {
6771
}
6872
}
6973

70-
#[derive(Debug, Clone)]
74+
#[derive(Debug, Clone, Deserialize, Serialize)]
75+
#[serde(rename_all = "camelCase")]
7176
pub struct Band {
7277
pub name: String,
7378
pub no_data_value: Option<f64>,
7479
pub data_type: RasterDataType,
7580
}
7681

77-
impl Band {
78-
pub fn new(name: String, no_data_value: Option<f64>, data_type: RasterDataType) -> Self {
79-
Self {
80-
name,
81-
no_data_value,
82-
data_type,
83-
}
84-
}
85-
}
86-
87-
#[derive(Debug, Clone)]
82+
#[derive(Debug, Clone, Deserialize, Serialize)]
8883
pub struct Zone {
8984
pub name: String,
9085
pub epsg: u32,
9186
}
9287

93-
impl Zone {
94-
pub fn new(name: String, epsg: u32) -> Self {
95-
Self { name, epsg }
96-
}
97-
}
98-
99-
#[derive(Debug, Clone)]
100-
pub struct SentinelMetaData {
101-
bands: Vec<Band>,
102-
zones: Vec<Zone>,
103-
}
104-
10588
#[derive(Debug, Clone)]
10689
pub struct SentinelDataset {
10790
band: Band,
@@ -116,41 +99,22 @@ pub struct SentinelS2L2aCogsDataProvider {
11699
}
117100

118101
impl SentinelS2L2aCogsDataProvider {
119-
pub fn new(id: DatasetProviderId, api_url: String) -> Self {
120-
let meta_data = Self::load_metadata();
102+
pub fn new(id: DatasetProviderId, api_url: String, bands: &[Band], zones: &[Zone]) -> Self {
121103
Self {
122104
api_url,
123-
datasets: Self::create_datasets(&id, &meta_data),
124-
}
125-
}
126-
127-
fn load_metadata() -> SentinelMetaData {
128-
// TODO: fetch dataset metadata from config or remote
129-
SentinelMetaData {
130-
bands: vec![
131-
Band::new("B01".to_owned(), Some(0.), RasterDataType::U16),
132-
Band::new("B02".to_owned(), Some(0.), RasterDataType::U16),
133-
Band::new("B03".to_owned(), Some(0.), RasterDataType::U16),
134-
Band::new("B04".to_owned(), Some(0.), RasterDataType::U16),
135-
Band::new("B08".to_owned(), Some(0.), RasterDataType::U16),
136-
Band::new("SCL".to_owned(), Some(0.), RasterDataType::U8),
137-
],
138-
zones: vec![
139-
Zone::new("UTM32N".to_owned(), 32632),
140-
Zone::new("UTM36S".to_owned(), 32736),
141-
],
105+
datasets: Self::create_datasets(&id, bands, zones),
142106
}
143107
}
144108

145109
fn create_datasets(
146110
id: &DatasetProviderId,
147-
meta_data: &SentinelMetaData,
111+
bands: &[Band],
112+
zones: &[Zone],
148113
) -> HashMap<DatasetId, SentinelDataset> {
149-
meta_data
150-
.zones
114+
zones
151115
.iter()
152116
.flat_map(|zone| {
153-
meta_data.bands.iter().map(move |band| {
117+
bands.iter().map(move |band| {
154118
let dataset_id: DatasetId = ExternalDatasetId {
155119
provider_id: *id,
156120
dataset_id: format!("{}:{}", zone.name, band.name),

services/test-data/provider_defs/pro/sentinel_s2_l2a_cogs.json

Lines changed: 55 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,5 +2,59 @@
22
"type": "SentinelS2L2ACogsProviderDefinition",
33
"id": "5779494c-f3a2-48b3-8a2d-5fbba8c5b6c5",
44
"name": "Element 84 AWS STAC",
5-
"apiUrl": "https://earth-search.aws.element84.com/v0/collections/sentinel-s2-l2a-cogs/items"
5+
"apiUrl": "https://earth-search.aws.element84.com/v0/collections/sentinel-s2-l2a-cogs/items",
6+
"bands": [
7+
{
8+
"name": "B01",
9+
"noDataValue": 0,
10+
"dataType": "U16"
11+
},
12+
{
13+
"name": "B02",
14+
"noDataValue": 0,
15+
"dataType": "U16"
16+
},
17+
{
18+
"name": "B03",
19+
"noDataValue": 0,
20+
"dataType": "U16"
21+
},
22+
{
23+
"name": "B04",
24+
"noDataValue": 0,
25+
"dataType": "U16"
26+
},
27+
{
28+
"name": "B08",
29+
"noDataValue": 0,
30+
"dataType": "U16"
31+
},
32+
{
33+
"name": "SCL",
34+
"noDataValue": 0,
35+
"dataType": "U8"
36+
}
37+
],
38+
"zones": [
39+
{
40+
"name": "UTM32N",
41+
"epsg": 32632
42+
},
43+
{
44+
"name": "UTM36N",
45+
"epsg": 32636
46+
},
47+
{
48+
"name": "UTM36S",
49+
"epsg": 32736
50+
},
51+
{
52+
"name": "UTM37N",
53+
"epsg": 32637
54+
},
55+
{
56+
"name": "UTM37S",
57+
"epsg": 32737
58+
}
59+
]
660
}

0 commit comments

Comments
 (0)