Skip to content
DuckDB community extension

duck_dggs

DuckDB extension for discrete global grid systems (DGGS) powered by DGGRID v9.1.

01 / SETUP

Install and load

Run these commands in a Haybarn SQL session. The extension is available from the community repository.

Haybarn 2.0.0 · SQL
INSTALL duck_dggs FROM community;
LOAD duck_dggs FROM community;

Try it in a temporary SQL session with duck_dggs already loaded. Queries run in this tab; examples using files or services need their own setup.

Using upstream DuckDB? Follow the maintainer’s installation instructions.

02 / QUERY

Usage example

Geographic point → cell ID at resolution 5 (default ISEA4H grid)

SQL
-- Geographic point → cell ID at resolution 5 (default ISEA4H grid)
SELECT geo_to_seqnum('POINT(0.0 0.0)'::GEOMETRY, 5);
-- → 2380

-- Cell ID → cell centre point
SELECT seqnum_to_geo(2380, 5);
-- → POINT (-0.9020481122620776 1.4282740292403947e-09)

-- Cell ID → cell boundary polygon (requires the spatial extension)
LOAD spatial;
SELECT seqnum_to_boundary(2380, 5);
-- → POLYGON ((...))

-- Grid statistics
SELECT dggs_n_cells(5);
-- → 10242

-- Neighbors, parent, children
SELECT seqnum_neighbors(2380::UBIGINT, 5);
-- → [2412, 2413, 2381, 2348, 2347, 2379]

SELECT seqnum_parent(2380::UBIGINT, 5);
-- → 599

SELECT seqnum_children(599::UBIGINT, 4);
-- → [2380, 2412, 2413, 2381, 2348, 2347, 2379]

-- Use a custom grid (ISEA3H — aperture 3 hexagons)
SELECT geo_to_seqnum('POINT(0.0 0.0)'::GEOMETRY, 5,
    dggs_params('ISEA', 3, 'HEXAGON', 0.0, 58.28252559, 11.25));
-- → 572

-- Mixed-aperture sequence grid
SELECT dggs_n_cells(3,
    dggs_params('ISEA', 3, 'HEXAGON', 0.0, 58.28252559, 11.25, true, '3434'));
-- → 362

Provided by am2222. Not yet verified on Haybarn 2.0.0.

Sample data & setup

About this extension

duck_dggs transforms geographic coordinates (as GEOMETRY POINT) to and from DGGS cell identifiers across multiple coordinate reference frames, powered by DGGRID v9.

All transform functions accept a GEOMETRY POINT (x = longitude°, y = latitude°) and a resolution integer. Every function has a second overload that accepts an explicit dggs_params struct for full control over the grid configuration.

Project overview from the community descriptor.

Documentation and resources

Project and build details
Repository
am2222/duckdb-dggs
License
MIT
Maintainers
am2222
Written in
C++
Build source
5a297119d343
Build definition
Community descriptor