Skip to content

Commit 1aa0225

Browse files
committed
Add STACIT driver examples
1 parent d9b7a5f commit 1aa0225

2 files changed

Lines changed: 63 additions & 4 deletions

File tree

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
from osgeo import gdal
2+
3+
gdal.UseExceptions()
4+
5+
stac_url = "https://planetarycomputer.microsoft.com/api/stac/v1/search"
6+
bbox = "-100,40,-99,41"
7+
datetime = "2019-01-01T00:00:00Z%2F.."
8+
collections = "naip"
9+
url = f"{stac_url}?collections={collections}&bbox={bbox}&datetime={datetime}"
10+
11+
ds = gdal.OpenEx(
12+
url, allowed_drivers=["STACIT"]
13+
) # force the STACIT driver or it opens as GeoJSON
14+
15+
print(gdal.Info(ds, format="json"))
16+
17+
# subdatasets
18+
19+
subdatasets = ds.GetSubDatasets()
20+
# get the first subdataset properties
21+
sds_properties = subdatasets[0]
22+
subdataset_url = sds_properties[0] # a tuple of URL and description
23+
subdataset = gdal.OpenEx(subdataset_url, allowed_drivers=["STACIT"])
24+
25+
print(gdal.Info(subdataset, format="json"))

doc/source/drivers/raster/stacit.rst

Lines changed: 38 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -10,13 +10,17 @@ STACIT - Spatio-Temporal Asset Catalog Items
1010

1111
.. built_in_by_default::
1212

13-
This driver supports opening STAC API ItemCollections, with the input usually being a `STAC API search query <https://github.com/radiantearth/stac-api-spec/tree/main/item-search>`_ or the results saved as a JSON file. Items in the response must include projection information following the `Projection Extension Specification <https://github.com/stac-extensions/projection/>`_.
13+
This driver supports opening STAC API ItemCollections, with the input usually being a `STAC API search query <https://github.com/radiantearth/stac-api-spec/tree/main/item-search>`_
14+
or the results saved as a JSON file. Items in the response must include projection information following the
15+
`Projection Extension Specification <https://github.com/stac-extensions/projection/>`_.
1416
It builds a virtual mosaic from the items.
1517

1618
A STACIT dataset which has no subdatasets is actually a :ref:`raster.vrt` dataset.
1719
Thus, translating it into VRT will result in a VRT file that directly references the items.
1820

19-
Note that `STAC API ItemCollections <https://github.com/radiantearth/stac-api-spec/blob/main/fragments/itemcollection/README.md>`_ are not the same as `STAC Collections <https://github.com/radiantearth/stac-spec/tree/master/collection-spec>`_. STAC API ItemCollections are GeoJSON FeatureCollections enhanced with STAC entities.
21+
Note that `STAC API ItemCollections <https://github.com/radiantearth/stac-api-spec/blob/main/fragments/itemcollection/README.md>`_
22+
are not the same as `STAC Collections <https://github.com/radiantearth/stac-spec/tree/master/collection-spec>`_.
23+
STAC API ItemCollections are GeoJSON FeatureCollections enhanced with STAC entities.
2024

2125
Open syntax
2226
-----------
@@ -108,17 +112,47 @@ Examples
108112
List the subdatasets associated to a `STAC search <https://github.com/radiantearth/stac-api-spec/tree/master/item-search>`_
109113
on a given collection, bbox and starting from a datetime:
110114

111-
::
115+
.. tabs::
116+
117+
.. code-tab:: bash
112118

113119
gdalinfo "STACIT:\"https://planetarycomputer.microsoft.com/api/stac/v1/search?collections=naip&bbox=-100,40,-99,41&datetime=2019-01-01T00:00:00Z%2F..\""
120+
# from GDAL 3.11+
121+
gdal raster info "STACIT:\"https://planetarycomputer.microsoft.com/api/stac/v1/search?collections=naip&bbox=-100,40,-99,41&datetime=2019-01-01T00:00:00Z%2F..\""
122+
123+
124+
.. code-tab:: ps1
125+
126+
gdalinfo 'STACIT:\"https://planetarycomputer.microsoft.com/api/stac/v1/search?collections=naip&bbox=-100,40,-99,41&datetime=2019-01-01T00:00:00Z%2F..\"'
127+
# from GDAL 3.11+
128+
gdal raster info 'STACIT:\"https://planetarycomputer.microsoft.com/api/stac/v1/search?collections=naip&bbox=-100,40,-99,41&datetime=2019-01-01T00:00:00Z%2F..\"'
129+
130+
.. tab:: Python
114131

132+
.. literalinclude :: examples/stacit.py
133+
:language: python
134+
:end-before: # subdatasets
115135
116136
Open a subdataset returned by the above request:
117137

118-
::
138+
.. tabs::
139+
140+
.. code-tab:: bash
119141

120142
gdalinfo "STACIT:\"https://planetarycomputer.microsoft.com/api/stac/v1/search?collections=naip&bbox=-100,40,-99,41&datetime=2019-01-01T00:00:00Z%2F..\":asset=image"
143+
gdal raster info "STACIT:\"https://planetarycomputer.microsoft.com/api/stac/v1/search?collections=naip&bbox=-100,40,-99,41&datetime=2019-01-01T00:00:00Z%2F..\":asset=image"
144+
145+
.. code-tab:: ps1
146+
147+
gdalinfo 'STACIT:\"https://planetarycomputer.microsoft.com/api/stac/v1/search?collections=naip&bbox=-100,40,-99,41&datetime=2019-01-01T00:00:00Z%2F..\":asset=image'
148+
# from GDAL 3.11+
149+
gdal raster info 'STACIT:\"https://planetarycomputer.microsoft.com/api/stac/v1/search?collections=naip&bbox=-100,40,-99,41&datetime=2019-01-01T00:00:00Z%2F..\":asset=image'
150+
151+
.. tab:: Python
121152

153+
.. literalinclude :: examples/stacit.py
154+
:language: python
155+
:start-after: # subdatasets
122156
123157
See Also
124158
--------

0 commit comments

Comments
 (0)