pystac.item#
- class pystac.item.Item(id: str, geometry: Optional[Dict[str, Any]], bbox: Optional[List[float]], datetime: Optional[datetime.datetime], properties: Dict[str, Any], stac_extensions: Optional[List[str]] = None, href: Optional[str] = None, collection: Optional[Union[str, pystac.collection.Collection]] = None, extra_fields: Optional[Dict[str, Any]] = None, assets: Optional[Dict[str, pystac.asset.Asset]] = None)[source]
An Item is the core granular entity in a STAC, containing the core metadata that enables any client to search or crawl online catalogs of spatial ‘assets’ - satellite imagery, derived data, DEM’s, etc.
- Parameters
id – Provider identifier. Must be unique within the STAC.
geometry – Defines the full footprint of the asset represented by this item, formatted according to RFC 7946, section 3.1 (GeoJSON).
bbox – Bounding Box of the asset represented by this item using either 2D or 3D geometries. The length of the array must be 2*n where n is the number of dimensions. Could also be None in the case of a null geometry.
datetime – Datetime associated with this item. If None, a start_datetime and end_datetime must be supplied in the properties.
properties – A dictionary of additional metadata for the item.
stac_extensions – Optional list of extensions the Item implements.
href – Optional HREF for this item, which be set as the item’s self link’s HREF.
collection – The Collection or Collection ID that this item belongs to.
extra_fields – Extra fields that are part of the top-level JSON properties of the Item.
assets – A dictionary mapping string keys to
Asset
objects. AllAsset
values in the dictionary will have theirowner
attribute set to the created Item.
- STAC_OBJECT_TYPE: pystac.stac_object.STACObjectType = 'Feature'
- add_asset(key: str, asset: pystac.asset.Asset) None [source]
Adds an Asset to this item.
- Parameters
key – The unique key of this asset.
asset – The Asset to add.
- assets: Dict[str, pystac.asset.Asset]
Dictionary of
Asset
objects, each with a unique key.
- bbox: Optional[List[float]]
Bounding Box of the asset represented by this item using either 2D or 3D geometries. The length of the array is 2*n where n is the number of dimensions. Could also be None in the case of a null geometry.
- clone() pystac.item.Item [source]
Clones this object.
Cloning an object will make a copy of all properties and links of the object; however, it will not make copies of the targets of links (i.e. it is not a deep copy). To copy a STACObject fully, with all linked elements also copied, use
STACObject.full_copy
.- Returns
The clone of this object.
- Return type
- collection: Optional[pystac.collection.Collection]
Collection
to which this Item belongs, if any.
- collection_id: Optional[str]
The Collection ID that this item belongs to, if any.
- property common_metadata: pystac.common_metadata.CommonMetadata
Access the item’s common metadata fields as a
CommonMetadata
object.
- datetime: Optional[datetime.datetime]
Datetime associated with this item. If
None
, thenstart_datetime
andend_datetime
incommon_metadata
will supply the datetime range of the Item.
- extra_fields: Dict[str, Any]
Extra fields that are part of the top-level JSON fields the Item.
- classmethod from_dict(d: Dict[str, Any], href: Optional[str] = None, root: Optional[pystac.catalog.Catalog] = None, migrate: bool = False, preserve_dict: bool = True) pystac.item.Item [source]
Parses this STACObject from the passed in dictionary.
- Parameters
d – The dict to parse.
href – Optional href that is the file location of the object being parsed.
root – Optional root catalog for this object. If provided, the root of the returned STACObject will be set to this parameter.
migrate – Use True if this dict represents JSON from an older STAC object, so that migrations are run against it.
preserve_dict – If False, the dict parameter
d
may be modified during this method call. Otherwise the dict is not mutated. Defaults to True, which results results in a deepcopy of the parameter. Set to False when possible to avoid the performance hit of a deepcopy.
- Returns
The STACObject parsed from this dict.
- Return type
- classmethod from_file(href: str, stac_io: Optional[pystac.stac_io.StacIO] = None) pystac.item.Item [source]
Reads a STACObject implementation from a file.
- Parameters
href – The HREF to read the object from.
stac_io – Optional instance of StacIO to use. If not provided, will use the default instance.
- Returns
The specific STACObject implementation class that is represented by the JSON read from the file located at HREF.
- full_copy(root: Optional[pystac.catalog.Catalog] = None, parent: Optional[pystac.catalog.Catalog] = None) pystac.item.Item [source]
Create a full copy of this STAC object and any stac objects linked to by this object.
- Parameters
root – Optional root to set as the root of the copied object, and any other copies that are contained by this object.
parent – Optional parent to set as the parent of the copy of this object.
- Returns
- A full copy of this object, as well as any objects this object
links to.
- Return type
- geometry: Optional[Dict[str, Any]]
Defines the full footprint of the asset represented by this item, formatted according to RFC 7946, section 3.1 (GeoJSON).
- get_assets() Dict[str, pystac.asset.Asset] [source]
Get this item’s assets.
- get_collection() Optional[pystac.collection.Collection] [source]
Gets the collection of this item, if one exists.
- Returns
If this item belongs to a collection, returns a reference to the collection. Otherwise returns None.
- Return type
Collection or None
- get_datetime(asset: Optional[pystac.asset.Asset] = None) Optional[datetime.datetime] [source]
Gets an Item or an Asset datetime.
If an Asset is supplied and the Item property exists on the Asset, returns the Asset’s value. Otherwise returns the Item’s value.
- Returns
datetime or None
- id: str
Provider identifier. Unique within the STAC.
- links: List[pystac.link.Link]
A list of
Link
objects representing all links associated with this Item.
- make_asset_hrefs_absolute() pystac.item.Item [source]
Modify each asset’s HREF to be absolute.
Any asset HREFs that are relative will be modified to absolute based on this item’s self HREF.
- Returns
self
- Return type
- make_asset_hrefs_relative() pystac.item.Item [source]
Modify each asset’s HREF to be relative to this item’s self HREF.
- Returns
self
- Return type
- classmethod matches_object_type(d: Dict[str, Any]) bool [source]
Returns a boolean indicating whether the given dictionary represents a valid instance of this
STACObject
sub-class.- Parameters
d – A dictionary to identify
- properties: Dict[str, Any]
A dictionary of additional metadata for the Item.
- set_collection(collection: Optional[pystac.collection.Collection]) pystac.item.Item [source]
Set the collection of this item.
This method will replace any existing Collection link and attribute for this item.
- Parameters
collection – The collection to set as this item’s collection. If None, will clear the collection.
- Returns
self
- Return type
- set_datetime(datetime: datetime.datetime, asset: Optional[pystac.asset.Asset] = None) None [source]
Set an Item or an Asset datetime.
If an Asset is supplied, sets the property on the Asset. Otherwise sets the Item’s value.
- set_self_href(href: Optional[str]) None [source]
Sets the absolute HREF that is represented by the
rel == 'self'
Link
.Changing the self HREF of the item will ensure that all asset HREFs remain valid. If asset HREFs are relative, the HREFs will change to point to the same location based on the new item self HREF, either by making them relative to the new location or making them absolute links if the new location does not share the same protocol as the old location.
- Parameters
href – The absolute HREF of this object. If the given HREF is not absolute, it will be transformed to an absolute HREF based on the current working directory. If this is None the call will clear the self HREF link.
- stac_extensions: List[str]
List of extensions the Item implements.
- to_dict(include_self_link: bool = True, transform_hrefs: bool = True) Dict[str, Any] [source]
Generate a dictionary representing the JSON of this serialized object.
- Parameters
include_self_link – If True, the dict will contain a self link to this object. If False, the self link will be omitted.
transform_hrefs – If True, transform the HREF of hierarchical links based on the type of catalog this object belongs to (if any). I.e. if this object belongs to a root catalog that is RELATIVE_PUBLISHED or SELF_CONTAINED, hierarchical link HREFs will be transformed to be relative to the catalog root.
dict – A serialization of the object that can be written out as JSON.