Skip to content

Commit

Permalink
Merge pull request #332 from geo-engine/sentinel_config
Browse files Browse the repository at this point in the history
make bands and zones configurable
  • Loading branch information
ChristianBeilschmidt authored Aug 30, 2021
2 parents 372b41c + f207fbb commit 2b0810e
Show file tree
Hide file tree
Showing 2 changed files with 68 additions and 50 deletions.
62 changes: 13 additions & 49 deletions services/src/pro/datasets/external/sentinel_s2_l2a_cogs.rs
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,8 @@ pub struct SentinelS2L2ACogsProviderDefinition {
name: String,
id: DatasetProviderId,
api_url: String,
bands: Vec<Band>,
zones: Vec<Zone>,
}

#[typetag::serde]
Expand All @@ -51,6 +53,8 @@ impl DatasetProviderDefinition for SentinelS2L2ACogsProviderDefinition {
Ok(Box::new(SentinelS2L2aCogsDataProvider::new(
self.id,
self.api_url,
&self.bands,
&self.zones,
)))
}

Expand All @@ -67,41 +71,20 @@ impl DatasetProviderDefinition for SentinelS2L2ACogsProviderDefinition {
}
}

#[derive(Debug, Clone)]
#[derive(Debug, Clone, Deserialize, Serialize)]
#[serde(rename_all = "camelCase")]
pub struct Band {
pub name: String,
pub no_data_value: Option<f64>,
pub data_type: RasterDataType,
}

impl Band {
pub fn new(name: String, no_data_value: Option<f64>, data_type: RasterDataType) -> Self {
Self {
name,
no_data_value,
data_type,
}
}
}

#[derive(Debug, Clone)]
#[derive(Debug, Clone, Deserialize, Serialize)]
pub struct Zone {
pub name: String,
pub epsg: u32,
}

impl Zone {
pub fn new(name: String, epsg: u32) -> Self {
Self { name, epsg }
}
}

#[derive(Debug, Clone)]
pub struct SentinelMetaData {
bands: Vec<Band>,
zones: Vec<Zone>,
}

#[derive(Debug, Clone)]
pub struct SentinelDataset {
band: Band,
Expand All @@ -116,41 +99,22 @@ pub struct SentinelS2L2aCogsDataProvider {
}

impl SentinelS2L2aCogsDataProvider {
pub fn new(id: DatasetProviderId, api_url: String) -> Self {
let meta_data = Self::load_metadata();
pub fn new(id: DatasetProviderId, api_url: String, bands: &[Band], zones: &[Zone]) -> Self {
Self {
api_url,
datasets: Self::create_datasets(&id, &meta_data),
}
}

fn load_metadata() -> SentinelMetaData {
// TODO: fetch dataset metadata from config or remote
SentinelMetaData {
bands: vec![
Band::new("B01".to_owned(), Some(0.), RasterDataType::U16),
Band::new("B02".to_owned(), Some(0.), RasterDataType::U16),
Band::new("B03".to_owned(), Some(0.), RasterDataType::U16),
Band::new("B04".to_owned(), Some(0.), RasterDataType::U16),
Band::new("B08".to_owned(), Some(0.), RasterDataType::U16),
Band::new("SCL".to_owned(), Some(0.), RasterDataType::U8),
],
zones: vec![
Zone::new("UTM32N".to_owned(), 32632),
Zone::new("UTM36S".to_owned(), 32736),
],
datasets: Self::create_datasets(&id, bands, zones),
}
}

fn create_datasets(
id: &DatasetProviderId,
meta_data: &SentinelMetaData,
bands: &[Band],
zones: &[Zone],
) -> HashMap<DatasetId, SentinelDataset> {
meta_data
.zones
zones
.iter()
.flat_map(|zone| {
meta_data.bands.iter().map(move |band| {
bands.iter().map(move |band| {
let dataset_id: DatasetId = ExternalDatasetId {
provider_id: *id,
dataset_id: format!("{}:{}", zone.name, band.name),
Expand Down
56 changes: 55 additions & 1 deletion services/test-data/provider_defs/pro/sentinel_s2_l2a_cogs.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,59 @@
"type": "SentinelS2L2ACogsProviderDefinition",
"id": "5779494c-f3a2-48b3-8a2d-5fbba8c5b6c5",
"name": "Element 84 AWS STAC",
"apiUrl": "https://earth-search.aws.element84.com/v0/collections/sentinel-s2-l2a-cogs/items"
"apiUrl": "https://earth-search.aws.element84.com/v0/collections/sentinel-s2-l2a-cogs/items",
"bands": [
{
"name": "B01",
"noDataValue": 0,
"dataType": "U16"
},
{
"name": "B02",
"noDataValue": 0,
"dataType": "U16"
},
{
"name": "B03",
"noDataValue": 0,
"dataType": "U16"
},
{
"name": "B04",
"noDataValue": 0,
"dataType": "U16"
},
{
"name": "B08",
"noDataValue": 0,
"dataType": "U16"
},
{
"name": "SCL",
"noDataValue": 0,
"dataType": "U8"
}
],
"zones": [
{
"name": "UTM32N",
"epsg": 32632
},
{
"name": "UTM36N",
"epsg": 32636
},
{
"name": "UTM36S",
"epsg": 32736
},
{
"name": "UTM37N",
"epsg": 32637
},
{
"name": "UTM37S",
"epsg": 32737
}
]
}

0 comments on commit 2b0810e

Please sign in to comment.