stac

DuckDB-Erweiterung zum Lesen von Daten aus SpatioTemporal Asset Catalogs (STAC) mit SQL.

Maintainer: ahuarte47

Installation und Laden

INSTALL stac FROM community;
LOAD stac;

Beispiel

-- Read the content of a static STAC catalog and return the first 2 items:
SELECT
collection, id
FROM
STAC_Read('https://raw.githubusercontent.com/radiantearth/stac-spec/refs/heads/master/examples/catalog.json')
LIMIT 2
;
┌───────────────┬────────────────────────────────────────────────────────────────┬─────────────────────────────────┐
collection │ id │ bbox │
varcharvarchar │ stac_bbox │
├───────────────┼────────────────────────────────────────────────────────────────┼─────────────────────────────────┤
│ sentinel2_l2a │ S2A_OPER_MSI_L2A_TL_EPAE_20190527T094026_A020508_T46VCQ_N02.12 │ { │
│ │ │ 'minx': 90.63571493952938, │
│ │ │ 'miny': 91.27015715015226, │
│ │ │ 'maxx': 62.12379856857608, │
│ │ │ 'maxy': 62.96338922674105
│ │ │ } │
├───────────────┼────────────────────────────────────────────────────────────────┼─────────────────────────────────┤
│ sentinel2_l2a │ S2A_OPER_MSI_L2A_TL_MTI__20190518T203951_A020386_T24XWM_N02.12 │ { │
│ │ │ 'minx': -39.0008444956852, │
│ │ │ 'miny': -34.13214411127818, │
│ │ │ 'maxx': 77.42853163431232, │
│ │ │ 'maxy': 78.37301671070006
│ │ │ } │
└───────────────┴────────────────────────────────────────────────────────────────┴─────────────────────────────────┘
-- Search for items in a STAC catalog using the STAC API - Item Search endpoint:
SELECT
collection, id, bbox
FROM
STAC_Search(
'https://earth-search.aws.element84.com/v0/search',
collections := ['sentinel-s2-l2a-cogs'],
datetime := '2021-09-30/2021-10-30',
bbox := [-1.695007724869786, 42.788757186108654, -1.604482013650674, 42.84244150196227]
)
;
┌──────────────────────┬──────────────────────────┬───────────────────────────────────────────────────────────────────────────────────────────────────────────────────┐
collection │ id │ bbox │
varcharvarchar │ stac_bbox │
├──────────────────────┼──────────────────────────┼───────────────────────────────────────────────────────────────────────────────────────────────────────────────────┤
│ sentinel-s2-l2a-cogs │ S2B_30TWN_20211030_0_L2A │ {'minx': -3.0002344509650487, 'miny': 42.356331534440834, 'maxx': -1.6455652046460576, 'maxy': 43.35284638738093} │
│ sentinel-s2-l2a-cogs │ S2B_30TXN_20211030_0_L2A │ {'minx': -1.7857005522228677, 'miny': 42.335791505536065, 'maxx': -0.4124765189393069, 'maxy': 43.3461908738427} │
│ sentinel-s2-l2a-cogs │ S2A_30TWN_20211025_0_L2A │ {'minx': -3.0002344509650487, 'miny': 42.356331534440834, 'maxx': -1.6455652046460576, 'maxy': 43.35284638738093} │
│ sentinel-s2-l2a-cogs │ S2A_30TXN_20211025_0_L2A │ {'minx': -1.7857005522228677, 'miny': 42.335791505536065, 'maxx': -0.4124765189393069, 'maxy': 43.3461908738427} │
│ sentinel-s2-l2a-cogs │ S2B_30TWN_20211020_0_L2A │ {'minx': -3.0002344509650487, 'miny': 42.356331534440834, 'maxx': -1.6455652046460576, 'maxy': 43.35284638738093} │
│ sentinel-s2-l2a-cogs │ S2A_30TXN_20211015_0_L2A │ {'minx': -1.7857005522228677, 'miny': 42.335791505536065, 'maxx': -0.4124765189393069, 'maxy': 43.3461908738427} │
│ sentinel-s2-l2a-cogs │ S2B_30TXN_20210930_0_L2A │ {'minx': -1.7857005522228677, 'miny': 42.335791505536065, 'maxx': -0.4124765189393069, 'maxy': 43.3461908738427} │
└──────────────────────┴──────────────────────────┴───────────────────────────────────────────────────────────────────────────────────────────────────────────────────┘

Über stac

Eine DuckDB-Erweiterung zum Lesen von Daten aus SpatioTemporal Asset Catalogs (STAC) mit SQL.

Die Erweiterung stellt STAC-Kataloge als relationale Tabellen bereit und folgt der GeoParquet-STAC-Spezifikation.

Jede Zeile entspricht einem einzelnen STAC-Item. Fast alle Item-Felder werden auf Spalten abgebildet; verschachtelte JSON-Strukturen bleiben nach Möglichkeit als Parquet-Structs erhalten, Item-Properties werden jedoch auf die oberste Ebene gehoben, um Filterung und Abfragen zu erleichtern.

Die Erweiterung stellt zwei Tabellenfunktionen zum Lesen von STAC-Katalogen bereit:

  • STAC_Read: Liest den Inhalt eines SpatioTemporal-Asset-Catalog-(STAC-)Katalogs von der angegebenen URL oder JSON-Datei und gibt ihn als Tabelle zurück.

    SELECT * FROM STAC_Read('https://example.com/stac/collection.json');
  • STAC_Search:

    Durchsucht den Inhalt eines SpatioTemporal-Asset-Catalog-(STAC-)Katalogs anhand der Filterkriterien von STAC API - Item Search (https://api.stacspec.org/v1.0.0/item-search/) und gibt passende Items als Tabelle zurück.

    Der Parameter url gibt die Basis-URL des STAC-API-Item-Search-Endpunkts an.

    Optionale Parameter erlauben das Filtern nach verschiedenen Kriterien:

    • collections: Liste von Collection-IDs zur Filterung der Suchergebnisse.
    • ids: Liste von Item-IDs zur Filterung der Suchergebnisse.
    • bbox: Bounding Box zur räumlichen Schnittfilterung, als Array von vier Floats für minimale Länge, minimale Breite, maximale Länge und maximale Breite.
    • intersects: Geometrieobjekt (EPSG:4326) zur räumlichen Schnittfilterung.
    • datetime: Zeichenkette für einen zeitlichen Bereich im Format “start_datetime/end_datetime” (z. B. “2021-01-01T00:00:00Z/2021-12-31T23:59:59Z”).
    • max_items: Ganzzahl für die maximale Anzahl von Items pro Ergebnisseite.
    SELECT
    *
    FROM
    STAC_Search(
    'https://earth-search.aws.element84.com/v0/search',
    collections := ['sentinel-s2-l2a-cogs'],
    datetime := '2021-09-30/2021-10-30',
    intersects := ST_MakeEnvelope(-1.695007724869786, 42.788757186108654, -1.604482013650674, 42.84244150196227)::GEOMETRY('EPSG::4326')
    )
    ;
    SELECT
    *
    FROM
    STAC_Search(
    'https://earth-search.aws.element84.com/v0/search',
    collections := ['sentinel-s2-l2a-cogs'],
    datetime := '2021-09-30/2021-10-30',
    bbox := [-1.695007724869786, 42.788757186108654, -1.604482013650674, 42.84244150196227]
    )
    ;

Hinzugefügte Funktionen

function_name function_type description comment examples
STAC_Read table NULL [
SELECT * FROM STAC_Read('https://example.com/stac/collection.json');
] |

| STAC_Search | table | | NULL | [ SELECT * FROM STAC_Search(‘https://example.com/stac/collection.json’, collections:=‘my_collection’, bbox:=[-180, -90, 180, 90], max_items:=10); ] |

Überladene Funktionen

Diese Erweiterung fügt keine Funktionsüberladungen hinzu.

Hinzugefügte Typen

type_name type_size logical_type type_category internal
STAC_ASSET 0 STRUCT COMPOSITE true
STAC_BBOX 0 STRUCT COMPOSITE true
STAC_LINK 0 STRUCT COMPOSITE true

Hinzugefügte Einstellungen

Diese Erweiterung fügt keine Einstellungen hinzu.