Skip to content

Commit 7b23766

Browse files
authored
add STAC API support (#221) (#2129)
1 parent 77a3776 commit 7b23766

File tree

12 files changed

+773
-35
lines changed

12 files changed

+773
-35
lines changed

docs/source/publishing/stac.rst

Lines changed: 119 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
.. _stac:
22

33
Publishing files to a SpatioTemporal Asset Catalog
4-
**************************************************
4+
==================================================
55

66
The `SpatioTemporal Asset Catalog (STAC)`_ family of specifications aim to standardize
77
the way geospatial asset metadata is structured and queried. A "spatiotemporal asset"
@@ -16,9 +16,11 @@ years, and is used in numerous production deployments.
1616

1717
pygeoapi built-in providers to browse STAC catalogs are described below:
1818

19+
Static catalog
20+
--------------
1921

2022
FileSystem Provider
21-
===================
23+
^^^^^^^^^^^^^^^^^^^
2224

2325
The FileSystem Provider implements STAC as a geospatial file browser through the server's file system,
2426
supporting any level of file/directory nesting/hierarchy.
@@ -27,7 +29,7 @@ Configuring STAC in pygeoapi is done by simply pointing the ``data`` provider pr
2729
to the given directory and specifying allowed file types:
2830

2931
Connection examples
30-
-------------------
32+
*******************
3133

3234
.. code-block:: yaml
3335
@@ -47,7 +49,7 @@ Connection examples
4749

4850

4951
pygeometa metadata control files
50-
--------------------------------
52+
********************************
5153

5254
pygeoapi's STAC filesystem functionality supports `pygeometa`_ MCF files residing
5355
in the same directory as data files. If an MCF file is found, it will be used
@@ -57,13 +59,13 @@ pygeometa will generate the STAC item metadata from configuration and by
5759
reading the data's properties.
5860

5961
Publishing ESRI Shapefiles
60-
--------------------------
62+
**************************
6163

6264
ESRI Shapefile publishing requires to specify all required component file extensions
6365
(``.shp``, ``.shx``, ``.dbf``) with the provider ``file_types`` option.
6466

6567
Data access examples
66-
--------------------
68+
********************
6769

6870
* STAC root page
6971

@@ -72,7 +74,7 @@ Data access examples
7274
From here, browse the filesystem accordingly.
7375

7476
Azure Blob Storage Provider
75-
===========================
77+
^^^^^^^^^^^^^^^^^^^^^^^^^^^
7678

7779
The AzureBlobStorage Provider implements STAC as a geospatial file browser through Azure Blob Storage,
7880
supporting any level of file/directory nesting/hierarchy.
@@ -81,7 +83,7 @@ Configuring STAC in pygeoapi is done by simply pointing the ``data`` provider pr
8183
to the given container and specifying allowed file types:
8284

8385
Connection examples
84-
-------------------
86+
*******************
8587

8688
.. code-block:: yaml
8789
@@ -104,7 +106,7 @@ Connection examples
104106

105107

106108
Hateoas Provider
107-
================
109+
^^^^^^^^^^^^^^^^
108110

109111
HATEOAS (Hypermedia as the Engine of Application State) is a way of implementing a REST
110112
application that allows the client to dynamically navigate to the appropriate resources
@@ -149,7 +151,7 @@ So, the following rules must be respected:
149151
-------------
150152

151153
File examples
152-
-------------
154+
*************
153155

154156
**Structure of the catalog.json file**
155157

@@ -213,7 +215,7 @@ The code above shows the root catalog. The sub-catalogs have an additional ``rel
213215
214216
-------------------------------------
215217

216-
**Structure of the collection.json file**
218+
**Structure of the ``collection.json`` file**
217219

218220
Collections are similar to Catalogs with extra fields.
219221

@@ -270,10 +272,9 @@ Collections are similar to Catalogs with extra fields.
270272
}
271273
272274
275+
**Structure of the Item ``<id>.json`` file**
273276

274-
**Structure of the Item <id>.json file**
275-
276-
The example below shows the content of a file named *arcticdem-frontiere-0.json*.
277+
The example below shows the content of a file named ``arcticdem-frontiere-0.json``:
277278

278279
.. code-block:: json
279280
@@ -351,14 +352,14 @@ The example below shows the content of a file named *arcticdem-frontiere-0.json*
351352
352353
353354
354-
HATEOAS Configuration
355-
---------------------
355+
HATEOAS configuration
356+
*********************
356357

357358
Configuring HATEOAS STAC Provider in pygeoapi is done by simply pointing the ``data`` provider property
358-
to the local directory or remote URL and specifying the root file name (catalog.json or collection.json) in the file_types property:
359+
to the local directory or remote URL and specifying the root file name (``catalog.json`` or ``collection.json``) in the ``file_types`` property:
359360

360361
Connection examples
361-
-------------------
362+
*******************
362363

363364
.. code-block:: yaml
364365
@@ -380,6 +381,106 @@ Connection examples
380381
data: tests/stac
381382
file_types: catalog.json
382383
384+
STAC API
385+
--------
386+
387+
`STAC API`_ support is provided as a wrapper on top of resources that have feature or record providers configured.
388+
389+
To enable STAC API support, configure a resource with a feature or record provider, and set the resource ``type`` to ``stac-collection``:
390+
391+
.. code-block:: yaml
392+
393+
canada-metadata:
394+
type: stac-collection
395+
title:
396+
en: Open Canada sample data
397+
fr: Exemple de donn\u00e9es Canada Ouvert
398+
description:
399+
en: Sample metadata records from open.canada.ca
400+
fr: Exemples d'enregistrements de m\u00e9tadonn\u00e9es sur ouvert.canada.ca
401+
keywords:
402+
en:
403+
- canada
404+
- open data
405+
fr:
406+
- canada
407+
- donn\u00e9es ouvertes
408+
links:
409+
- type: text/html
410+
rel: canonical
411+
title: information
412+
href: https://open.canada.ca/en/open-data
413+
hreflang: en-CA
414+
- type: text/html
415+
rel: alternate
416+
title: informations
417+
href: https://ouvert.canada.ca/fr/donnees-ouvertes
418+
hreflang: fr-CA
419+
extents:
420+
spatial:
421+
bbox: [-180,-90,180,90]
422+
crs: http://www.opengis.net/def/crs/OGC/1.3/CRS84
423+
providers:
424+
- type: record
425+
name: TinyDBCatalogue
426+
data: tests/data/open.canada.ca/sample-records.tinydb
427+
id_field: externalId
428+
time_field: created
429+
title_field: title
430+
431+
STAC API queries will search all feature or record based resources configured as ``stac-collection``. Results
432+
are decorated with the required STAC elements (unless they already exist).
433+
434+
.. note::
435+
436+
pygeoapi STAC API support is minimally designed to leverage the OGC API - Features and OGC API - Records
437+
implementations. A typical setup would be a features or records backend of STAC Items. pygeoapi does not
438+
add or implement any STAC Catalog/Item relationships beyond what is encoded in a STAC resource.
439+
440+
441+
Data access examples
442+
--------------------
443+
444+
* landing page
445+
446+
* http://localhost:5000/stac-api
447+
448+
* query all STAC resources
449+
450+
* http://localhost:5000/stac-api/search
451+
452+
* query features (spatial)
453+
454+
* http://localhost:5000/stac-api/search?bbox=-142,52,-140,55
455+
456+
* paging
457+
458+
* http://localhost:5000/stac-api/search?offset=10&limit=10
459+
460+
* query features (temporal)
461+
462+
* http://localhost:5000/stac-api/search?datetime=2019-11-11T11:11:11Z/..
463+
* http://localhost:5000/stac-api/search?datetime=2018-11-11T11:11:11Z/2019-11-11T11:11:11Z
464+
* http://localhost:5000/stac-api/search?datetime=../2019-11-11T11:11:11Z
465+
466+
.. code-block:: bash
467+
468+
# query features (spatial)
469+
curl -X POST http://localhost:5000/stac-api/search \
470+
-H "Content-Type: application/json" \
471+
-d "{\"bbox\": [-142, 52, -140, 55]}"
472+
473+
# paging
474+
curl -X POST http://localhost:5000/stac-api/search \
475+
-H "Content-Type: application/json" \
476+
-d "{\"offset\": 10, \"limit\": 10}"
477+
478+
# query features (temporal)
479+
curl -X POST http://localhost:5000/stac-api/search \
480+
-H "Content-Type: application/json" \
481+
-d "{\"datetime\": \"2019-11-11T11:11:11Z/..\"}"
482+
383483
384484
.. _`SpatioTemporal Asset Catalog (STAC)`: https://stacspec.org
385485
.. _`pygeometa`: https://geopython.github.io/pygeometa
486+
.. _`STAC API`: https://github.com/radiantearth/stac-api-spec

pygeoapi/api/__init__.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1667,7 +1667,11 @@ def evaluate_limit(requested: Union[None, int], server_limits: dict,
16671667
LOGGER.debug('no limit requested; returning default')
16681668
return default
16691669

1670-
requested2 = get_typed_value(requested)
1670+
if isinstance(requested, int):
1671+
requested2 = requested
1672+
else:
1673+
requested2 = get_typed_value(requested)
1674+
16711675
if not isinstance(requested2, int):
16721676
raise ValueError('limit value should be an integer')
16731677

0 commit comments

Comments
 (0)