Skip to content

Commit

Permalink
feat(core): add item_assets to Collection
Browse files Browse the repository at this point in the history
  • Loading branch information
gadomski committed Sep 19, 2024
1 parent 67228d0 commit 8dcd257
Show file tree
Hide file tree
Showing 4 changed files with 64 additions and 2 deletions.
1 change: 1 addition & 0 deletions core/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
- `object_store` ([#382](https://github.com/stac-utils/stac-rs/pull/382))
- `stac::geoparquet::Compression`, even if geoparquet is not enabled ([#396](https://github.com/stac-utils/stac-rs/pull/396))
- `Type` ([#397](https://github.com/stac-utils/stac-rs/pull/397))
- `Collection::item_assets` and `ItemAsset` ([#404](https://github.com/stac-utils/stac-rs/pull/404))

### Changed

Expand Down
9 changes: 7 additions & 2 deletions core/src/collection.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
use crate::{
Asset, Assets, Bbox, Error, Extensions, Fields, Href, Item, Link, Links, Migrate, Result,
Version, STAC_VERSION,
Asset, Assets, Bbox, Error, Extensions, Fields, Href, Item, ItemAsset, Link, Links, Migrate,
Result, Version, STAC_VERSION,
};
use chrono::{DateTime, Utc};
use serde::{Deserialize, Serialize};
Expand Down Expand Up @@ -87,6 +87,10 @@ pub struct Collection {
#[serde(skip_serializing_if = "HashMap::is_empty", default)]
pub assets: HashMap<String, Asset>,

/// A dictionary of assets that can be found in member Items.
#[serde(skip_serializing_if = "HashMap::is_empty", default)]
pub item_assets: HashMap<String, ItemAsset>,

/// Additional fields not part of the `Collection` specification.
#[serde(flatten)]
pub additional_fields: Map<String, Value>,
Expand Down Expand Up @@ -182,6 +186,7 @@ impl Collection {
summaries: None,
links: Vec::new(),
assets: HashMap::new(),
item_assets: HashMap::new(),
additional_fields: Map::new(),
href: None,
}
Expand Down
54 changes: 54 additions & 0 deletions core/src/item_asset.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
use serde::{Deserialize, Serialize};
use serde_json::{Map, Value};

/// An item asset is an object that contains details about the datafiles that
/// will be included in member items.
///
/// Assets included at the Collection level do not imply that all assets are
/// available from all Items. However, it is recommended that the Asset
/// Definition is a complete set of all assets that may be available from any
/// member Items. So this should be the union of the available assets, not just
/// the intersection of the available assets.
///
/// Other custom fields, or fields from other extensions may also be included in the Asset object.
///
/// Any property that exists for a Collection-level asset object must also exist
/// in the corresponding assets object in each Item. If a collection's asset
/// object contains properties that are not explicitly stated in the Item's
/// asset object then that property does not apply to the item's asset. Item
/// asset objects at the Collection-level can describe any of the properties of
/// an asset, but those assets properties and values must also reside in the
/// item's asset object. To consolidate item-level asset object properties in an
/// API setting, consider storing the STAC Item objects without the larger
/// properties internally as 'invalid' STAC items, and merge in the desired
/// properties at serving time from the Collection-level.
///
/// At least two fields (e.g. title and type) are required to be provided, in
/// order for it to adequately describe Item assets. The two fields must not
/// necessarily be taken from the defined fields on this struct and may include
/// any custom field.
#[derive(Clone, Debug, Serialize, Deserialize, PartialEq)]
pub struct ItemAsset {
/// The displayed title for clients and users.
#[serde(skip_serializing_if = "Option::is_none")]
pub title: Option<String>,

/// A description of the Asset providing additional details, such as how it
/// was processed or created.
///
/// CommonMark 0.29 syntax MAY be used for rich text representation.
#[serde(skip_serializing_if = "Option::is_none")]
pub description: Option<String>,

/// Media type of the asset.
#[serde(skip_serializing_if = "Option::is_none")]
pub r#type: Option<String>,

/// The semantic roles of the asset, similar to the use of rel in links.
#[serde(skip_serializing_if = "Vec::is_empty", default)]
pub roles: Vec<String>,

/// Additional fields.
#[serde(flatten)]
pub additional_fields: Map<String, Value>,
}
2 changes: 2 additions & 0 deletions core/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -168,6 +168,7 @@ pub mod geoparquet;
mod href;
pub mod io;
pub mod item;
mod item_asset;
mod item_collection;
mod json;
pub mod link;
Expand All @@ -193,6 +194,7 @@ pub use {
href::Href,
io::{read, write},
item::{FlatItem, Item, Properties, ITEM_TYPE},
item_asset::ItemAsset,
item_collection::{ItemCollection, ITEM_COLLECTION_TYPE},
json::{FromJson, ToJson},
link::{Link, Links},
Expand Down

0 comments on commit 8dcd257

Please sign in to comment.