PyStac¶
Description:
- PySTAC is a library for working with SpatioTemporal Asset Catalogs (STAC) in Python 3.
Resources:
Example 1¶
Write a STAC catalog to a file and read it back
In [ ]:
Copied!
import json
from pathlib import Path
from pystac import Catalog
tmp = "/tmp/demo_notebooks"
Path(tmp).mkdir(exist_ok=True)
# Example stac catalog
example_catalog = {
"type": "Catalog",
"stac_version": "1.0.0",
"stac_extensions": [],
"id": "landsat-stac-collection-catalog",
"title": "STAC for Landsat data",
"description": "STAC for Landsat data",
"links": [
{
"href": "./catalog.json",
"rel": "self"
},
{
"href": "./catalog.json",
"rel": "root"
},
{
"href": "./landsat-8-l1/collection.json",
"rel": "child"
}
]
}
# Create a json file locally with the dict
with open(f"{tmp}/stac_catalog.json", 'w') as f:
json.dump(example_catalog, f)
# Print attrs from the catalog
root_catalog = Catalog.from_file(f"{tmp}/stac_catalog.json")
print(f"ID: {root_catalog.id}")
print(f"Title: {root_catalog.title or 'N/A'}")
print(f"Description: {root_catalog.description or 'N/A'}")
import json
from pathlib import Path
from pystac import Catalog
tmp = "/tmp/demo_notebooks"
Path(tmp).mkdir(exist_ok=True)
# Example stac catalog
example_catalog = {
"type": "Catalog",
"stac_version": "1.0.0",
"stac_extensions": [],
"id": "landsat-stac-collection-catalog",
"title": "STAC for Landsat data",
"description": "STAC for Landsat data",
"links": [
{
"href": "./catalog.json",
"rel": "self"
},
{
"href": "./catalog.json",
"rel": "root"
},
{
"href": "./landsat-8-l1/collection.json",
"rel": "child"
}
]
}
# Create a json file locally with the dict
with open(f"{tmp}/stac_catalog.json", 'w') as f:
json.dump(example_catalog, f)
# Print attrs from the catalog
root_catalog = Catalog.from_file(f"{tmp}/stac_catalog.json")
print(f"ID: {root_catalog.id}")
print(f"Title: {root_catalog.title or 'N/A'}")
print(f"Description: {root_catalog.description or 'N/A'}")