Skip to content

Commit a0eb0b4

Browse files
committed
fix(core): don't add bands if they're all empty
1 parent 660e77e commit a0eb0b4

File tree

3 files changed

+120
-4
lines changed

3 files changed

+120
-4
lines changed

core/CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,10 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
1414
- 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))
1515
- Public `stac::io` module ([#319](https://github.com/stac-utils/stac-rs/pull/319))
1616

17+
### Fixed
18+
19+
- Don't add a `bands` attribute if all bands are empty when migrating ([#351](https://github.com/stac-utils/stac-rs/pull/351))
20+
1721
### Changed
1822

1923
- 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))

core/data/20201211_223832_CS2.json

Lines changed: 101 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,101 @@
1+
{
2+
"type": "Feature",
3+
"stac_version": "1.0.0",
4+
"stac_extensions": [
5+
"https://stac-extensions.github.io/projection/v1.1.0/schema.json",
6+
"https://stac-extensions.github.io/raster/v1.1.0/schema.json"
7+
],
8+
"id": "20201211_223832_CS2",
9+
"geometry": {
10+
"type": "Polygon",
11+
"coordinates": [
12+
[
13+
[
14+
172.9117367,
15+
1.3438852
16+
],
17+
[
18+
172.9546961,
19+
1.3438852
20+
],
21+
[
22+
172.9546961,
23+
90.0
24+
],
25+
[
26+
172.9117367,
27+
90.0
28+
],
29+
[
30+
172.9117367,
31+
1.3438852
32+
]
33+
]
34+
],
35+
"bbox": [
36+
172.9117367,
37+
1.3438852,
38+
172.9546961,
39+
90.0
40+
]
41+
},
42+
"bbox": [
43+
172.9117367,
44+
1.3438852,
45+
172.9546961,
46+
90.0
47+
],
48+
"properties": {
49+
"datetime": "2024-09-05T22:33:45.900997Z",
50+
"proj:epsg": 32659,
51+
"proj:bbox": [
52+
712710.0,
53+
148627.0,
54+
717489.5,
55+
151406.0
56+
],
57+
"proj:centroid": {
58+
"lat": 1.3564664,
59+
"lon": 172.9332164
60+
},
61+
"proj:shape": [
62+
5558,
63+
9559
64+
],
65+
"proj:transform": [
66+
0.5,
67+
0.0,
68+
712710.0,
69+
0.0,
70+
-0.5,
71+
151406.0
72+
]
73+
},
74+
"links": [],
75+
"assets": {
76+
"data": {
77+
"href": "/Users/gadomski/Downloads/20201211_223832_CS2.tif",
78+
"roles": [
79+
"data"
80+
],
81+
"raster:bands": [
82+
{
83+
"data_type": "uint8",
84+
"spatial_resolution": 0.5
85+
},
86+
{
87+
"data_type": "uint8",
88+
"spatial_resolution": 0.5
89+
},
90+
{
91+
"data_type": "uint8",
92+
"spatial_resolution": 0.5
93+
},
94+
{
95+
"data_type": "uint8",
96+
"spatial_resolution": 0.5
97+
}
98+
]
99+
}
100+
}
101+
}

core/src/migrate.rs

Lines changed: 15 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -164,10 +164,12 @@ fn migrate_bands(asset: &mut Map<String, Value>) -> Result<()> {
164164
}
165165
}
166166
}
167-
let _ = asset.insert(
168-
"bands".into(),
169-
Value::Array(bands.into_iter().map(Value::Object).collect()),
170-
);
167+
if bands.iter().any(|band| !band.is_empty()) {
168+
let _ = asset.insert(
169+
"bands".into(),
170+
Value::Array(bands.into_iter().map(Value::Object).collect()),
171+
);
172+
}
171173
Ok(())
172174
}
173175

@@ -235,4 +237,13 @@ mod tests {
235237
let item = item.migrate(Version::v1_1_0_beta_1).unwrap();
236238
assert_eq!(item.link("self").unwrap().href, "file:///an/absolute/href");
237239
}
240+
241+
#[test]
242+
fn remove_empty_bands() {
243+
// https://github.com/stac-utils/stac-rs/issues/350
244+
let item: Item = crate::read("data/20201211_223832_CS2.json").unwrap();
245+
let item = item.migrate(Version::v1_1_0_beta_1).unwrap();
246+
let asset = &item.assets["data"];
247+
assert!(asset.bands.is_empty());
248+
}
238249
}

0 commit comments

Comments
 (0)