#geospatial #raster #metadata #geo

stac

Rust library for the SpatioTemporal Asset Catalog (STAC) specification

20 releases

0.7.0 Apr 29, 2024
0.5.3 Apr 7, 2024
0.5.2 Oct 18, 2023
0.5.0 Jun 27, 2023
0.0.4 Mar 9, 2022

#40 in Science

Download history 4/week @ 2024-01-28 29/week @ 2024-02-04 57/week @ 2024-02-11 65/week @ 2024-02-18 59/week @ 2024-02-25 90/week @ 2024-03-03 77/week @ 2024-03-10 64/week @ 2024-03-17 69/week @ 2024-03-24 111/week @ 2024-03-31 302/week @ 2024-04-07 52/week @ 2024-04-14 35/week @ 2024-04-21 276/week @ 2024-04-28 16/week @ 2024-05-05

403 downloads per month
Used in 6 crates

MIT/Apache

1.5MB
2.5K SLoC

stac

GitHub Workflow Status docs.rs Crates.io Crates.io Contributor Covenant

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

Usage

To use the library in your project:

[dependencies]
stac = "0.7"

Examples

use stac::Item;

// Creates an item from scratch.
let item = Item::new("an-id");

// Reads an item from the filesystem.
let item: Item = stac::read("data/simple-item.json").unwrap();

Please see the documentation for more usage examples.

Features

There are a few opt-in features.

reqwest

reqwest enables blocking remote reads:

[dependencies]
stac = { version = "0.7", features = ["reqwest"]}

Then:

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

If reqwest is not enabled, stac::read will throw an error if you try to read from a url.

let href = "https://raw.githubusercontent.com/radiantearth/stac-spec/master/examples/simple-item.json";
#[cfg(not(feature = "reqwest"))]
let err = stac::read::<stac::Item>(href).unwrap_err();

For non-blocking IO, use the stac-async crate.

gdal

To use GDAL to create items with projection and raster band information, you'll need GDAL installed on your system:

[dependencies]
stac = { version = "0.7", features = ["gdal"] }

Then, items created from rasters will include the projection and raster extensions:

#[cfg(feature = "gdal")]
{
    use stac::{extensions::{Raster, Projection}, Extensions, item::Builder};
    let item = Builder::new("an-id").asset("data", "assets/dataset_geo.tif").into_item().unwrap();
    assert!(item.has_extension::<Projection>());
    assert!(item.has_extension::<Raster>());
}

geo

To use geojson and geo to add some extra geo-enabled methods:

[dependencies]
stac = { version = "0.7", features = ["geo"] }

Then, you can set an item's geometry and bounding box at the same time:

#[cfg(feature = "geo")]
{
    use stac::Item;
    use geojson::{Geometry, Value};

    let geometry = Geometry::new(Value::Point(vec![
        -105.1, 41.1,
    ]));
    let mut item = Item::new("an-id");

    item.set_geometry(geometry).unwrap();
    assert!(item.bbox.is_some());
}

Other info

This crate is part of the stac-rs monorepo, see its README for contributing and license information.

Dependencies

~5–18MB
~286K SLoC