Skip to content

Commit

Permalink
fix(core): don't add bands if they're all empty
Browse files Browse the repository at this point in the history
  • Loading branch information
gadomski committed Sep 5, 2024
1 parent 660e77e commit a0eb0b4
Show file tree
Hide file tree
Showing 3 changed files with 120 additions and 4 deletions.
4 changes: 4 additions & 0 deletions core/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,10 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
- Experimental GeoParquet and GeoArrow support ([#316](https://github.com/stac-utils/stac-rs/pull/316), [#319](https://github.com/stac-utils/stac-rs/pull/319), [#328](https://github.com/stac-utils/stac-rs/pull/328))
- Public `stac::io` module ([#319](https://github.com/stac-utils/stac-rs/pull/319))

### Fixed

- Don't add a `bands` attribute if all bands are empty when migrating ([#351](https://github.com/stac-utils/stac-rs/pull/351))

### Changed

- Use `DateTime<Utc>` instead of `String` for datetimes ([#297](https://github.com/stac-utils/stac-rs/pull/297), [#304](https://github.com/stac-utils/stac-rs/pull/304))
Expand Down
101 changes: 101 additions & 0 deletions core/data/20201211_223832_CS2.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,101 @@
{
"type": "Feature",
"stac_version": "1.0.0",
"stac_extensions": [
"https://stac-extensions.github.io/projection/v1.1.0/schema.json",
"https://stac-extensions.github.io/raster/v1.1.0/schema.json"
],
"id": "20201211_223832_CS2",
"geometry": {
"type": "Polygon",
"coordinates": [
[
[
172.9117367,
1.3438852
],
[
172.9546961,
1.3438852
],
[
172.9546961,
90.0
],
[
172.9117367,
90.0
],
[
172.9117367,
1.3438852
]
]
],
"bbox": [
172.9117367,
1.3438852,
172.9546961,
90.0
]
},
"bbox": [
172.9117367,
1.3438852,
172.9546961,
90.0
],
"properties": {
"datetime": "2024-09-05T22:33:45.900997Z",
"proj:epsg": 32659,
"proj:bbox": [
712710.0,
148627.0,
717489.5,
151406.0
],
"proj:centroid": {
"lat": 1.3564664,
"lon": 172.9332164
},
"proj:shape": [
5558,
9559
],
"proj:transform": [
0.5,
0.0,
712710.0,
0.0,
-0.5,
151406.0
]
},
"links": [],
"assets": {
"data": {
"href": "/Users/gadomski/Downloads/20201211_223832_CS2.tif",
"roles": [
"data"
],
"raster:bands": [
{
"data_type": "uint8",
"spatial_resolution": 0.5
},
{
"data_type": "uint8",
"spatial_resolution": 0.5
},
{
"data_type": "uint8",
"spatial_resolution": 0.5
},
{
"data_type": "uint8",
"spatial_resolution": 0.5
}
]
}
}
}
19 changes: 15 additions & 4 deletions core/src/migrate.rs
Original file line number Diff line number Diff line change
Expand Up @@ -164,10 +164,12 @@ fn migrate_bands(asset: &mut Map<String, Value>) -> Result<()> {
}
}
}
let _ = asset.insert(
"bands".into(),
Value::Array(bands.into_iter().map(Value::Object).collect()),
);
if bands.iter().any(|band| !band.is_empty()) {
let _ = asset.insert(
"bands".into(),
Value::Array(bands.into_iter().map(Value::Object).collect()),
);
}
Ok(())
}

Expand Down Expand Up @@ -235,4 +237,13 @@ mod tests {
let item = item.migrate(Version::v1_1_0_beta_1).unwrap();
assert_eq!(item.link("self").unwrap().href, "file:///an/absolute/href");
}

#[test]
fn remove_empty_bands() {
// https://github.com/stac-utils/stac-rs/issues/350
let item: Item = crate::read("data/20201211_223832_CS2.json").unwrap();
let item = item.migrate(Version::v1_1_0_beta_1).unwrap();
let asset = &item.assets["data"];
assert!(asset.bands.is_empty());
}
}

0 comments on commit a0eb0b4

Please sign in to comment.