pystac
These functions are only available if pystac is available on your system. To install pystac and stacrs:
stacrs.pystac.migrate
migrate(value: STACObject, version: Optional[str] = None, *, include_self_link: bool = True, transform_hrefs: bool = False) -> dict[str, Any]
Migrates a STAC dictionary to another version.
Because pystac doesn't store the STAC version on the STACObject, this function returns a dictionary to ensure the version is preserved.
Migration can be as simple as updating the stac_version
attribute, but
sometimes can be more complicated. For example, when migrating to v1.1.0,
eo:bands and raster:bands should be consolidated to the new bands
structure.
See the stac-rs documentation for supported versions.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
value |
STACObject
|
The STAC value to migrate |
required |
version |
str | None
|
The version to migrate to. If not provided, the value will be migrated to the latest stable version. |
None
|
include_self_link |
bool
|
Whether to include a self link when serializing this object to a dictionary. |
True
|
transform_hrefs |
bool
|
Whether to transform this object's hrefs when serializing it to a dictionary. While pystac defaults to true, this function defaults to false (https://github.com/stac-utils/pystac/issues/960) |
False
|
Returns:
Type | Description |
---|---|
dict[str, Any]
|
dict[str, Any]: The migrated object |
Examples:
>>> item = pystac.read_file("old-item.json")
>>> item = stacrs.pystac.migrate(item, "1.1.0")
>>> assert item["stac_version"] == "1.1.0"
Source code in stacrs/pystac.py
stacrs.pystac.read
read(href: str, *, format: str | None = None, options: list[tuple[str, str]] | None = None, root: Catalog | None = None) -> STACObject | ItemCollection
Reads STAC from a href.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
href |
str
|
The href to write to |
required |
format |
str | None
|
The output format to write. If not provided, will be inferred from the href's extension. |
None
|
options |
list[tuple[str, str]] | None
|
Options for configuring an object store, e.g. your AWS credentials. |
None
|
root |
Catalog | None
|
Optional root of the catalog for this object. If provided, the root's resolved object cache can be used to search for previously resolved instances of the STAC object. |
None
|
Returns:
Type | Description |
---|---|
STACObject | ItemCollection
|
STACObject | ItemCollection: The STAC value |
Examples:
Source code in stacrs/pystac.py
stacrs.pystac.search
search(href: str, *, intersects: Optional[str | dict[str, Any]] = None, ids: Optional[str | list[str]] = None, collections: Optional[str | list[str]] = None, max_items: Optional[int] = None, limit: Optional[int] = None, bbox: Optional[list[float]] = None, datetime: Optional[str] = None, include: Optional[str | list[str]] = None, exclude: Optional[str | list[str]] = None, sortby: Optional[str | list[str]] = None, filter: Optional[str | dict[str, Any]] = None, query: Optional[dict[str, Any]] = None) -> Iterable[Item]
Searches a STAC API server.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
href |
str
|
The STAC API to search. |
required |
intersects |
str | dict[str, Any] | GeoInterface | None
|
Searches items by performing intersection between their geometry and provided GeoJSON geometry. |
None
|
ids |
list[str] | None
|
Array of Item ids to return. |
None
|
collections |
list[str] | None
|
Array of one or more Collection IDs that each matching Item must be in. |
None
|
max_items |
int | None
|
The maximum number of items to iterate through. |
None
|
limit |
int | None
|
The page size returned from the server. Use
|
None
|
bbox |
list[float] | None
|
Requested bounding box. |
None
|
datetime |
str | None
|
Single date+time, or a range ('/' separator), formatted to RFC 3339, section 5.6. Use double dots .. for open date ranges. |
None
|
include |
list[str]] | None
|
fields to include in the response (see the extension docs) for more on the semantics). |
None
|
exclude |
list[str]] | None
|
fields to exclude from the response (see the extension docs) for more on the semantics). |
None
|
sortby |
list[str] | None
|
Fields by which to sort results (use |
None
|
filter |
str | dict[str, Any] | none
|
CQL2 filter expression. Strings will be interpreted as cql2-text, dictionaries as cql2-json. query (dict[str, Any] | None): Additional filtering based on properties. It is recommended to use filter instead, if possible. |
None
|
Returns:
Type | Description |
---|---|
Iterable[Item]
|
Iterable[Item]: A iterable of pystac items. |
Examples:
>>> items = list(stacrs.search(
... "https://landsatlook.usgs.gov/stac-server",
... collections=["landsat-c2l2-sr"],
... intersects={"type": "Point", "coordinates": [-105.119, 40.173]},
... sortby="-properties.datetime",
... max_items=1,
... ))
Source code in stacrs/pystac.py
stacrs.pystac.validate
validate(value: STACObject, *, include_self_link: bool = True, transform_hrefs: bool = False) -> None
Validates a STAC dictionary with json-schema.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
value |
STACObject
|
The STAC value to validate |
required |
include_self_link |
bool
|
Whether to include a self link when serializing this object to a dictionary. |
True
|
transform_hrefs |
bool
|
Whether to transform this object's hrefs when serializing it to a dictionary. While pystac defaults to true, this function defaults to false (https://github.com/stac-utils/pystac/issues/960) |
False
|
Raises:
Type | Description |
---|---|
Exception
|
On a validation error |
Examples:
Source code in stacrs/pystac.py
stacrs.pystac.write
write(href: str, value: STACObject | list[Item], *, format: str | None = None, options: list[tuple[str, str]] | None = None, include_self_link: bool = True, transform_hrefs: bool = False) -> dict[str, str] | None
Writes STAC to a href.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
href |
str
|
The href to write to |
required |
value |
dict[str, Any] | list[dict[str, Any]]
|
The value to write. This can be a STAC dictionary or a list of items. |
required |
format |
str | None
|
The output format to write. If not provided, will be inferred from the href's extension. |
None
|
options |
list[tuple[str, str]] | None
|
Options for configuring an object store, e.g. your AWS credentials. |
None
|
include_self_link |
bool
|
Whether to include a self link when serializing this object to a dictionary. |
True
|
transform_hrefs |
bool
|
Whether to transform this object's hrefs when serializing it to a dictionary. While pystac defaults to true, this function defaults to false (https://github.com/stac-utils/pystac/issues/960) |
False
|
Returns:
Type | Description |
---|---|
dict[str, str] | None
|
dict[str, str] | None: The result of putting data into an object store, e.g. the e_tag and the version. None is returned if the file was written locally. |
Examples:
>>> with open("simple-item.json") as f:
... item = json.load(f)
>>> stacrs.write("out.parquet", [item])