Skip to main content

No project description provided

Project description

pygeofilter-duckdb

This repo is an evolution of https://github.com/DLR-terrabyte/pygeofilter-duckdb.

We have changed the orginal implementation to:

  • make it a standalone library
  • updated it to support duckdb newer releases (no support for 1.2.0 yet)
  • added more examples to cover the process STAC Items -> geoparquet -> Duckdb
  • use hatch

Introduction

This is an extension for pygeofilter to support SQL queries in DuckDB based on Geoparquet files.

pygeofilter allows to parse several filter encoding standards (e.g., CQL JSON, CQL Text) and to convert them to queries for several backends (e.g., SQL, Django, Pandas).

In DuckDB the geometry is currently stored as BLOB, which needs to be considered in the filter conversion. This extension is based on the following issue: https://github.com/geopython/pygeofilter/issues/90.

Example

Run the notebooks in the folder example:

  • hatch shell
  • pip install folium ipykernel

Usage

from pygeofilter.parsers.cql2_json import parse as json_parse
from pygeofilter_duckdb import to_sql_where
from pygeofilter.util import IdempotentDict

start = '2023-02-01T00:00:00Z'
end = '2023-02-28T23:59:59Z'

cql2_filter = {
  "op": "and",
  "args": [
    {
      "op": "between",
      "args": [
        {
          "property": "eo:cloud_cover"
        },
        [0, 21]
      ]
    },
      {
      "op": "between",
      "args": [
        {
          "property": "datetime"
        },
        [start, end]
      ]
    },
    {
        "op": "s_intersects",
        "args": [
          { "property": "geometry" } ,
          {
            "type": "Polygon", # Baden-Württemberg
            "coordinates": [[
                [7.5113934084, 47.5338000528],
    			[10.4918239143, 47.5338000528],
    			[10.4918239143, 49.7913749328],
    			[7.5113934084, 49.7913749328],
    			[7.5113934084, 47.5338000528]
            ]]
          }
        ]
      }
  ]
}

sql_where = to_sql_where(json_parse(cql2_filter), IdempotentDict())
print(sql_where)

This results in the following output

((("eo:cloud_cover" BETWEEN 0 AND 21) AND ("datetime" BETWEEN '2023-02-01T00:00:00Z' AND '2023-02-28T23:59:59Z')) AND ST_Intersects("geometry",ST_GeomFromHEXEWKB('0103000000010000000500000034DFB1B6AA0B1E4085B0648F53C44740509E1658D0FB244085B0648F53C44740509E1658D0FB244006A017C64BE5484034DFB1B6AA0B1E4006A017C64BE5484034DFB1B6AA0B1E4085B0648F53C44740')))

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

pygeofilter_duckdb-0.1.0.tar.gz (77.7 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

pygeofilter_duckdb-0.1.0-py3-none-any.whl (4.3 kB view details)

Uploaded Python 3

File details

Details for the file pygeofilter_duckdb-0.1.0.tar.gz.

File metadata

  • Download URL: pygeofilter_duckdb-0.1.0.tar.gz
  • Upload date:
  • Size: 77.7 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.7

File hashes

Hashes for pygeofilter_duckdb-0.1.0.tar.gz
Algorithm Hash digest
SHA256 c6967a0a2cd2a269a89b168b4ebc19abe254ebdf957e2e78863b9527e5b9e92c
MD5 c66e8745bf4eac90aa7b84db6c1e5dce
BLAKE2b-256 99022cedb31628621afc1398d08d74b53b7cf5ae2ccfee4101341535c9d34f99

See more details on using hashes here.

Provenance

The following attestation bundles were made for pygeofilter_duckdb-0.1.0.tar.gz:

Publisher: package.yaml on Terradue/pygeofilter-duckdb

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file pygeofilter_duckdb-0.1.0-py3-none-any.whl.

File metadata

File hashes

Hashes for pygeofilter_duckdb-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 6bd225f6bbb8b8f6b3a3202861b61af3cef2eddfd456a36b69102d8f6088e50e
MD5 f683e308d294674390c297b1d5581474
BLAKE2b-256 137e21491be9795e0e0b1b06c34d69ab455822b7fb07fde65acace74f4203787

See more details on using hashes here.

Provenance

The following attestation bundles were made for pygeofilter_duckdb-0.1.0-py3-none-any.whl:

Publisher: package.yaml on Terradue/pygeofilter-duckdb

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page