Description
Step purpose
Purpose: produce a STAC Catalog with a STAC Item describing the detected water body result.
This step is highlighted below:
Code
The stac
script is a command-line tool for creating a SpatioTemporal Asset Catalog (STAC) catalog containing detected water bodies.
It takes the STAC Item URLs and corresponding water body GeoTIFFs as input, creates STAC Items for each water body, and organizes them into a STAC Catalog.
The script utilizes the click
, pystac
, rio_stac
, and loguru
libraries.
Here's an overview of what the script does:
-
It defines a command-line interface using the
click
library. The script expects multiple input STAC Item URLs and corresponding water body GeoTIFFs as arguments. -
The
to_stac
function is the main entry point. It creates a new STAC catalog and iterates through the provided STAC Item URLs and water body GeoTIFFs. -
For each input pair (STAC Item URL and GeoTIFF), it reads the STAC Item, creates a directory with the same name as the item's ID, and copies the water body GeoTIFF into that directory.
-
It uses the
rio_stac
library to create a STAC Item for the water body. This includes specifying the source GeoTIFF, input date/time, asset roles, asset href, and more. -
The created STAC Items are added to the STAC catalog.
-
After processing all input pairs, it saves the STAC catalog to the root directory, specifying it as a self-contained catalog with the catalog type set to
pystac.CatalogType.SELF_CONTAINED
.
The script will create a STAC catalog containing the detected water bodies and save it in the current directory.
The script is executable as a command-line tool as its usage is:
Usage: app.py [OPTIONS]
Creates a STAC catalog with the water bodies
Options:
--input-item TEXT STAC Item URL [required]
--water-body TEXT Water body geotiff [required]
--help Show this message and exit.
The Python code is provided here:
water-bodies/command-line-tools/stac/app.py | |
---|---|
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 |
|