Search Shortcut cmd + k | ctrl + k
duck_geoarrow

DuckDB extension for converting GEOMETRY/WKB to and from GeoArrow native encodings, powered by geoarrow-c. Built against DuckDB v1.5.2

Maintainer(s): am2222

Installing and Loading

INSTALL duck_geoarrow FROM community;
LOAD duck_geoarrow;

Example

INSTALL duck_geoarrow FROM community;
LOAD duck_geoarrow;

-- Convert a WKB point to GeoArrow struct
SELECT st_asgeoarrow('\x01\x01\x00\x00\x00\x00\x00\x00\x00\x00\x00\xF0\x3F\x00\x00\x00\x00\x00\x00\x00\x40'::BLOB);
-- → {geometry_type: 1, xs: [1.0], ys: [2.0], ring_offsets: [], geom_offsets: []}

-- With the spatial extension loaded, use GEOMETRY directly
LOAD spatial;
SELECT st_asgeoarrow(ST_Point(1.0, 2.0)::GEOMETRY);

-- Convert back: GeoArrow struct → GEOMETRY (WKB)
SELECT st_geomfromgeoarrow(st_asgeoarrow(ST_Point(30, 10)::GEOMETRY));

-- Native-typed point extraction (returns STRUCT<x, y>)
SELECT st_asgeoarrowpoint(ST_Point(30, 10)::GEOMETRY);
-- → {x: 30.0, y: 10.0}

-- Native-typed linestring (returns List<Struct<x, y>>)
SELECT st_asgeoarrowlinestring(ST_GeomFromText('LINESTRING(0 0, 1 1, 2 2)')::GEOMETRY);

-- Native-typed polygon (returns List<List<Struct<x, y>>>)
SELECT st_asgeoarrowpolygon(ST_GeomFromText('POLYGON((0 0, 4 0, 4 4, 0 4, 0 0))')::GEOMETRY);

-- Version info
SELECT duck_geoarrow_version();

About duck_geoarrow

duck_geoarrow converts between DuckDB's WKB-based GEOMETRY/BLOB type and GeoArrow native struct encodings, powered by geoarrow-c.

Generic conversion functions (accept GEOMETRY or BLOB containing WKB):

  • st_asgeoarrow(geom) — WKB → GeoArrow struct with geometry_type, xs, ys, ring_offsets, geom_offsets
  • st_geomfromgeoarrow(struct) — GeoArrow struct → WKB GEOMETRY

Native-typed functions (return Arrow-native nested types for direct columnar use):

Function Arrow type
st_asgeoarrowpoint Struct<x: DOUBLE, y: DOUBLE>
st_asgeoarrowlinestring List<Struct<x, y>>
st_asgeoarrowpolygon List<List<Struct<x, y>>>
st_asgeoarrowmultipoint List<Struct<x, y>>
st_asgeoarrowmultilinestring List<List<Struct<x, y>>>
st_asgeoarrowmultipolygon List<List<List<Struct<x, y>>>>

Utility:

  • duck_geoarrow_version() — returns extension and geoarrow-c version info

All functions accept both GEOMETRY (from the spatial extension) and raw BLOB containing valid WKB. The native-typed functions validate that the input geometry matches the expected type and raise an error on mismatch.

Added Functions

function_name function_type description comment examples
duck_geoarrow_version scalar NULL NULL  
st_asgeoarrow scalar NULL NULL  
st_asgeoarrowlinestring scalar NULL NULL  
st_asgeoarrowmultilinestring scalar NULL NULL  
st_asgeoarrowmultipoint scalar NULL NULL  
st_asgeoarrowmultipolygon scalar NULL NULL  
st_asgeoarrowpoint scalar NULL NULL  
st_asgeoarrowpolygon scalar NULL NULL  
st_geomfromgeoarrow scalar NULL NULL  

Overloaded Functions

This extension does not add any function overloads.

Added Types

This extension does not add any types.

Added Settings

This extension does not add any settings.