Crate stac

source ·
Expand description

Rust implementation of the SpatioTemporal Asset Catalog (STAC) specification.

The SpatioTemporal Asset Catalog (STAC) specification provides a common language to describe a range of geospatial information, so it can more easily be indexed and discovered. A ‘spatiotemporal asset’ is any file that represents information about the earth captured in a certain space and time.

This is a Rust implementation of the specification, with associated utilities. Similar projects in other languages include:

Data structures

STAC has three data structures:

  • Item is a GeoJSON Feature augmented with foreign members
  • Catalog represents a logical group of other Catalogs, Collections, and Items
  • Collection shares all fields with the Catalog (with different allowed values for type and stac_extensions) and adds fields to describe the whole dataset and the included set of Items

All three are provided as serde (de)serializable structures with public attributes. Each structure provides a new method that fills most of the object’s attributes with sensible defaults:

use stac::{Item, Catalog, Collection};
let item = Item::new("id");
let catalog = Catalog::new("id", "description");
let collection = Catalog::new("id", "description");

All attributes of STAC objects are accessible as public members:

use stac::{Item, Link};
let mut item = Item::new("id");
assert_eq!(item.id, "id");
assert!(item.geometry.is_none());
assert!(item.links.is_empty());
item.links.push(Link::new("an/href", "a-rel-type"));

Reading

Synchronous reads from the filesystem are supported via read. Read objects are returned as a Value, which implements TryInto for all three object types:

let value = stac::read("data/simple-item.json").unwrap();
assert!(value.is_item());
let item: stac::Item = value.try_into().unwrap();

If the reqwest feature is enabled, synchronous reads from urls are also supported:

#[cfg(feature = "reqwest")]
{
    let url = "https://raw.githubusercontent.com/radiantearth/stac-spec/master/examples/simple-item.json";
    let value = stac::read(url).unwrap();
}

If reqwest is not enabled, reading from a url will return an error:

#[cfg(not(feature = "reqwest"))]
{
    let url = "https://raw.githubusercontent.com/radiantearth/stac-spec/master/examples/simple-item.json";
    let error = stac::read(url).unwrap_err();
}

Hrefs

When objects are read from the filesystem or from a remote location, they store the href from which they were read. The href is accessible via the Href trait:

use stac::{Href, Item};
let value = stac::read("data/simple-item.json").unwrap();
assert!(value.href().as_deref().unwrap().ends_with("data/simple-item.json"));
let item: Item = value.clone().try_into().unwrap();
assert_eq!(value.href(), item.href());

Validation

If the jsonschema feature is enabled, objects can be validated against their json-schema definitions:

#[cfg(feature = "jsonschema")]
{
    use stac::{Item, Validate};
    let item = Item::new("an-id");
    item.validate().unwrap();
}

See the validate module for more examples.

Re-exports

pub use validate::Validate;
pub use validate::Validator;

Modules

Links.
Media Types are a key element that enables STAC to be a rich source of information for clients.
validatejsonschema
Validate STAC objects with json-schema.

Structs

An Asset is an object that contains a URI to data associated with the Item that can be downloaded or streamed.
A STAC Catalog object represents a logical group of other Catalog, Collection, and Item objects.
The STAC Collection Specification defines a set of common fields to describe a group of Items that share properties and metadata.
The object describes the spatio-temporal extents of the Collection.
An Item is a GeoJSON Feature augmented with foreign members relevant to a STAC object.
Additional metadata fields can be added to the GeoJSON Object Properties.
This object provides information about a provider.
The object describes the spatial extents of the Collection.
The object describes the temporal extents of the Collection.

Enums

Error enum for crate-specific errors.
An enum that can hold any STAC object type.

Constants

The type field for Catalogs.
The type field for Collections.
The type field for Items.
The default STAC version supported by this library.

Traits

A trait for objects that may have STAC extensions.
Implemented by all three STAC objects, the Href trait allows getting and setting an object’s href.

Functions

Reads any STAC object from an href.
Reads any JSON value from an href.

Type Definitions

Custom Result type for this crate.