Skip to content

Commit 8dcd257

Browse files
committed
feat(core): add item_assets to Collection
1 parent 67228d0 commit 8dcd257

File tree

4 files changed

+64
-2
lines changed

4 files changed

+64
-2
lines changed

core/CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
1616
- `object_store` ([#382](https://github.com/stac-utils/stac-rs/pull/382))
1717
- `stac::geoparquet::Compression`, even if geoparquet is not enabled ([#396](https://github.com/stac-utils/stac-rs/pull/396))
1818
- `Type` ([#397](https://github.com/stac-utils/stac-rs/pull/397))
19+
- `Collection::item_assets` and `ItemAsset` ([#404](https://github.com/stac-utils/stac-rs/pull/404))
1920

2021
### Changed
2122

core/src/collection.rs

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
use crate::{
2-
Asset, Assets, Bbox, Error, Extensions, Fields, Href, Item, Link, Links, Migrate, Result,
3-
Version, STAC_VERSION,
2+
Asset, Assets, Bbox, Error, Extensions, Fields, Href, Item, ItemAsset, Link, Links, Migrate,
3+
Result, Version, STAC_VERSION,
44
};
55
use chrono::{DateTime, Utc};
66
use serde::{Deserialize, Serialize};
@@ -87,6 +87,10 @@ pub struct Collection {
8787
#[serde(skip_serializing_if = "HashMap::is_empty", default)]
8888
pub assets: HashMap<String, Asset>,
8989

90+
/// A dictionary of assets that can be found in member Items.
91+
#[serde(skip_serializing_if = "HashMap::is_empty", default)]
92+
pub item_assets: HashMap<String, ItemAsset>,
93+
9094
/// Additional fields not part of the `Collection` specification.
9195
#[serde(flatten)]
9296
pub additional_fields: Map<String, Value>,
@@ -182,6 +186,7 @@ impl Collection {
182186
summaries: None,
183187
links: Vec::new(),
184188
assets: HashMap::new(),
189+
item_assets: HashMap::new(),
185190
additional_fields: Map::new(),
186191
href: None,
187192
}

core/src/item_asset.rs

Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
use serde::{Deserialize, Serialize};
2+
use serde_json::{Map, Value};
3+
4+
/// An item asset is an object that contains details about the datafiles that
5+
/// will be included in member items.
6+
///
7+
/// Assets included at the Collection level do not imply that all assets are
8+
/// available from all Items. However, it is recommended that the Asset
9+
/// Definition is a complete set of all assets that may be available from any
10+
/// member Items. So this should be the union of the available assets, not just
11+
/// the intersection of the available assets.
12+
///
13+
/// Other custom fields, or fields from other extensions may also be included in the Asset object.
14+
///
15+
/// Any property that exists for a Collection-level asset object must also exist
16+
/// in the corresponding assets object in each Item. If a collection's asset
17+
/// object contains properties that are not explicitly stated in the Item's
18+
/// asset object then that property does not apply to the item's asset. Item
19+
/// asset objects at the Collection-level can describe any of the properties of
20+
/// an asset, but those assets properties and values must also reside in the
21+
/// item's asset object. To consolidate item-level asset object properties in an
22+
/// API setting, consider storing the STAC Item objects without the larger
23+
/// properties internally as 'invalid' STAC items, and merge in the desired
24+
/// properties at serving time from the Collection-level.
25+
///
26+
/// At least two fields (e.g. title and type) are required to be provided, in
27+
/// order for it to adequately describe Item assets. The two fields must not
28+
/// necessarily be taken from the defined fields on this struct and may include
29+
/// any custom field.
30+
#[derive(Clone, Debug, Serialize, Deserialize, PartialEq)]
31+
pub struct ItemAsset {
32+
/// The displayed title for clients and users.
33+
#[serde(skip_serializing_if = "Option::is_none")]
34+
pub title: Option<String>,
35+
36+
/// A description of the Asset providing additional details, such as how it
37+
/// was processed or created.
38+
///
39+
/// CommonMark 0.29 syntax MAY be used for rich text representation.
40+
#[serde(skip_serializing_if = "Option::is_none")]
41+
pub description: Option<String>,
42+
43+
/// Media type of the asset.
44+
#[serde(skip_serializing_if = "Option::is_none")]
45+
pub r#type: Option<String>,
46+
47+
/// The semantic roles of the asset, similar to the use of rel in links.
48+
#[serde(skip_serializing_if = "Vec::is_empty", default)]
49+
pub roles: Vec<String>,
50+
51+
/// Additional fields.
52+
#[serde(flatten)]
53+
pub additional_fields: Map<String, Value>,
54+
}

core/src/lib.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -168,6 +168,7 @@ pub mod geoparquet;
168168
mod href;
169169
pub mod io;
170170
pub mod item;
171+
mod item_asset;
171172
mod item_collection;
172173
mod json;
173174
pub mod link;
@@ -193,6 +194,7 @@ pub use {
193194
href::Href,
194195
io::{read, write},
195196
item::{FlatItem, Item, Properties, ITEM_TYPE},
197+
item_asset::ItemAsset,
196198
item_collection::{ItemCollection, ITEM_COLLECTION_TYPE},
197199
json::{FromJson, ToJson},
198200
link::{Link, Links},

0 commit comments

Comments
 (0)