gedih3.sqlutils#

Functions#

init_duckdb([threads, memory_limit, temp_directory, ...])

attach_ducklake_db(con[, name, dir])

Attach existing ducklake database

geoseries_to_cells(shp[, resolution, expand_ring])

Convert a region to a list of overlapping H3 cells at resolution.

geoseries_to_filter(shp[, resolution, expand_ring])

Convert a region to an H3 partition filter at the given resolution.

duck_to_gdf(→ geopandas.GeoDataFrame)

Convert a DuckDB table to a GeoDataFrame.

gdf_to_duck(→ duckdb.DuckDBPyRelation)

Load a GeoDataFrame into a DuckDB table.

Module Contents#

gedih3.sqlutils.init_duckdb(threads=None, memory_limit=None, temp_directory=None, max_temp_size=None, extension_directory=None)[source]#
gedih3.sqlutils.attach_ducklake_db(con, name='gedi_dl', dir=None)[source]#

Attach existing ducklake database If dir is not specified, it will be located in GH3_DEFAULT_H3_DIR.

Once this function is called, the gedi data can be queried using

SELECT … FROM {name}.data

gedih3.sqlutils.geoseries_to_cells(shp, resolution: int = 3, expand_ring: int = 1)[source]#

Convert a region to a list of overlapping H3 cells at resolution.

Accepts every region form the loaders accept (vector-file path, "W,S,E,N" string, [W, S, E, N] list, GeoDataFrame/GeoSeries in any CRS, shapely geometry) via region_to_geometry(), so the DuckDB pre-query selection cannot drift from gh3_load’s — previously a GeoSeries in a projected CRS was fed to h3 as if it were lat/lng degrees.

gedih3.sqlutils.geoseries_to_filter(shp, resolution: int = 3, expand_ring: int = 1)[source]#

Convert a region to an H3 partition filter at the given resolution.

'overlap' coverage is exact w.r.t. the cell polygons, but shots are stored under their hierarchy partition, which can overhang the polygon by ~0.18 x edge length (see intersect_h3_geometries). expand_ring adds grid_disk neighbors so boundary shots stored in a non-overlapping neighbor partition are not silently filtered out; pass 0 to disable.

The filter column follows resolution (h3_03 for the default partition level 3) — pass the database’s h3_partition_level when it differs.

gedih3.sqlutils.duck_to_gdf(table, geometry_columns=['geometry'], crs='EPSG:4326') geopandas.GeoDataFrame[source]#

Convert a DuckDB table to a GeoDataFrame. If multiple geometry columns are specified, the first will be set as the active geometry.

gedih3.sqlutils.gdf_to_duck(con, gdf: geopandas.GeoDataFrame, geometry_columns: List[str] = ['geometry']) duckdb.DuckDBPyRelation[source]#

Load a GeoDataFrame into a DuckDB table.