class STAC::Collection
Represents STAC collection.
STAC Collection Specification: github.com/radiantearth/stac-spec/tree/master/collection-spec
Attributes
assets[R]
extent[RW]
keywords[RW]
license[RW]
providers[RW]
summaries[RW]
Public Class Methods
from_hash(hash)
click to toggle source
Calls superclass method
# File lib/stac/collection.rb, line 16 def from_hash(hash) h = hash.transform_keys(&:to_sym) h[:extent] = Extent.from_hash(h.fetch(:extent)) h[:providers] = h[:providers]&.map { |provider| Provider.from_hash(provider) } h[:summaries] = h[:summaries]&.transform_keys(&:to_s) h[:assets] = h[:assets]&.to_h { |k, v| [k.to_s, Asset.from_hash(v)] } super(h) rescue KeyError => e raise ArgumentError, "required field not found: #{e.key}" end
new( id:, description:, license:, extent:, links: [], title: nil, keywords: nil, providers: nil, summaries: nil, assets: nil, stac_extensions: [], **extra )
click to toggle source
Calls superclass method
STAC::Catalog::new
# File lib/stac/collection.rb, line 32 def initialize( id:, description:, license:, extent:, links: [], title: nil, keywords: nil, providers: nil, summaries: nil, assets: nil, stac_extensions: [], **extra ) @license = license @extent = extent @keywords = keywords @providers = providers @summaries = summaries @assets = assets super(id: id, description: description, links: links, title: title, stac_extensions: stac_extensions, **extra) end
Public Instance Methods
add_asset(key:, href:, title: nil, description: nil, type: nil, roles: nil, **extra)
click to toggle source
Adds an asset with the given key.
When the item has extendable stac_extensions, make the asset extend the extension modules.
# File lib/stac/collection.rb, line 72 def add_asset(key:, href:, title: nil, description: nil, type: nil, roles: nil, **extra) asset = Asset.new(href: href, title: title, description: description, type: type, roles: roles, **extra) extensions.each do |extension| asset.extend(extension::Asset) if extension.const_defined?(:Asset) end if assets assets[key] = asset else @assets = { key => asset } end self end
add_item(item, href: "
click to toggle source
Adds a rel=“item” link to self and adds “self”, “root”, “parent”, and “collection” links to the given item.
Calls superclass method
STAC::Catalog#add_item
# File lib/stac/collection.rb, line 86 def add_item(item, href: "#{item.id}.json", title: item.properties.title) super item.collection = self self end
to_h()
click to toggle source
Serializes self to a Hash.
Calls superclass method
STAC::Catalog#to_h
# File lib/stac/collection.rb, line 56 def to_h super.merge( { 'license' => license, 'keywords' => keywords, 'extent' => extent.to_h, 'providers' => providers&.map(&:to_h), 'summaries' => summaries, 'assets' => assets&.transform_values(&:to_h), }.compact, ) end