Introspection (native) functions in the GeoSilo DuckDB extension
Sample data for the examples
Each browser example starts with these sample tables; sample files are shared across examples on this page. Run this setup first when trying the examples in your own DuckDB session.
-- check-fixtures.sql for geosilo
-- spatial is needed for ST_GeomFromText, ST_AsText, etc.
INSTALL spatial;
LOAD spatial;
-- raw GEOMETRY source for INSERT INTO parcels SELECT ... FROM raw_parcels;
CREATE OR REPLACE TABLE raw_parcels AS
SELECT * FROM (VALUES
(1, 'a', ST_GeomFromText('POLYGON((0 0,1 0,1 1,0 1,0 0))')),
(2, 'b', ST_GeomFromText('POLYGON((2 2,3 2,3 3,2 3,2 2))'))
) t(id, name, geom);
-- roads(geom) for ST_Length aggregate
CREATE OR REPLACE TABLE roads AS
SELECT * FROM (VALUES
(ST_GeomFromText('LINESTRING(0 0, 1 1, 2 2)')),
(ST_GeomFromText('LINESTRING(0 0, 0 1, 0 2)'))
) t(geom);
-- stations(id, geom) — point geometries for ST_X/ST_Y
CREATE OR REPLACE TABLE stations AS
SELECT * FROM (VALUES
(1, ST_GeomFromText('POINT(-77.0 39.0)')),
(2, ST_GeomFromText('POINT(-76.5 40.5)'))
) t(id, geom);
-- mixed_geom_table(geom) — mixed geometry types
CREATE OR REPLACE TABLE mixed_geom_table AS
SELECT * FROM (VALUES
(ST_GeomFromText('POINT(0 0)')),
(ST_GeomFromText('LINESTRING(0 0, 1 1)')),
(ST_GeomFromText('POLYGON((0 0,1 0,1 1,0 1,0 0))'))
) t(geom);
-- compact_table(silo_blob) — geosilo blobs for geosilo_metadata example
CREATE OR REPLACE TABLE compact_table AS
SELECT geosilo_encode(ST_GeomFromText('POLYGON((0 0,1 0,1 1,0 1,0 0))')) AS silo_blob
UNION ALL
SELECT geosilo_encode(ST_GeomFromText('POINT(1 2)')) AS silo_blob;
-- utm_data(geom) — projected meters geometry source
CREATE OR REPLACE TABLE utm_data AS
SELECT ST_GeomFromText('POINT(500000 4500000)') AS geom;
-- mm_precision_data(geom) and millimeter_data(geom)
CREATE OR REPLACE TABLE mm_precision_data AS
SELECT ST_GeomFromText('POINT(0.001 0.002)') AS geom;
CREATE OR REPLACE TABLE millimeter_data AS
SELECT ST_GeomFromText('POINT(0.001 0.002)') AS geom;
-- parcels_geometry(id, geom) — GEOMETRY-typed parcels for export example
CREATE OR REPLACE TABLE parcels_geometry AS
SELECT id, geom FROM raw_parcels;
-- parcels(id, name, geom GEOSILO) — the table the cookbook defines and fills
-- in earlier blocks. Each in-browser example runs on its own, so it needs to
-- exist up front. The polygons sit inside the cookbook's -78..-76 longitude,
-- 39..41 latitude band, so its bounding-box filters return rows.
CREATE OR REPLACE TABLE parcels (
id INTEGER,
name VARCHAR,
geom GEOSILO('EPSG:4326') USING COMPRESSION zstd
);
INSERT INTO parcels
SELECT * FROM (VALUES
(1, 'north lot', ST_GeomFromText('POLYGON((-77.2 39.8,-77.1 39.8,-77.1 39.9,-77.2 39.9,-77.2 39.8))')),
(2, 'river parcel', ST_GeomFromText('POLYGON((-76.9 40.1,-76.8 40.1,-76.8 40.2,-76.9 40.2,-76.9 40.1))')),
(3, 'west field', ST_GeomFromText('POLYGON((-79.5 38.0,-79.4 38.0,-79.4 38.1,-79.5 38.1,-79.5 38.0))'))
) t(id, name, geom);
-- Source table and input files the cookbook's load examples read.
CREATE OR REPLACE TABLE raw_data AS SELECT id, geom FROM raw_parcels;
COPY (SELECT id, name, ST_AsText(geom) AS wkt FROM raw_parcels)
TO 'parcels.csv' (HEADER true);
COPY (SELECT id, name, ST_AsWKB(geom) AS geom_wkb FROM raw_parcels)
TO 'parcels.parquet' (FORMAT PARQUET);
Function category
Introspection (native)
9 functionsST_* overloads with native GEOSILO implementations — type, emptiness, point count, X/Y, and the four bounding-box accessors. They read the silo header / delta stream directly without round-tripping through WKB, which is where the speed-up on bounding-box prefilters and per-row coordinate access comes from.
Signature
Arguments (Positional)
| Argument | Type | Mode | Description |
|---|---|---|---|
Argument
geom
|
Type
GEOSILO
|
Mode Positional | Description |
Description
Native GEOSILO overload — returns the geometry type (e.g. POINT, POLYGON) by reading a single byte of the silo header. No WKB decode.
SELECT ST_GeometryType(ST_Point(1, 2)::GEOSILO);
-- POINT
Related functions
- ST_IsEmpty() — Native GEOSILO overload — `TRUE` if the encoded geometry has no vertices, including polygons, multi-geometries and collections made only of empty parts (`GEOMETRYCOLLECTION(POINT EMPTY)` is empty)
- ST_NPoints() — Native GEOSILO overload — total vertex count, walking the encoded geometry: every ring and sub-geometry is counted, polygon rings include their closing vertex (as in WKB), and empty points count as 0
- geosilo_metadata() — Read a GEOSILO blob's header **without decoding the geometry**
Signature
Arguments (Positional)
| Argument | Type | Mode | Description |
|---|---|---|---|
Argument
geom
|
Type
GEOSILO
|
Mode Positional | Description |
Description
Native GEOSILO overload — TRUE if the encoded geometry has no vertices, including polygons, multi-geometries and collections made only of empty parts (GEOMETRYCOLLECTION(POINT EMPTY) is empty).
SELECT ST_IsEmpty(ST_GeomFromText('POINT EMPTY')::GEOSILO);
-- true
Related functions
Signature
Arguments (Positional)
| Argument | Type | Mode | Description |
|---|---|---|---|
Argument
geom
|
Type
GEOSILO
|
Mode Positional | Description |
Description
Native GEOSILO overload — total vertex count, walking the encoded geometry: every ring and sub-geometry is counted, polygon rings include their closing vertex (as in WKB), and empty points count as 0. Matches spatial's ST_NPoints.
DuckDB 2.0 build: MULTI* geometries and GEOMETRYCOLLECTIONs are counted correctly (the Haybarn 1.5 build returns 0 for them and 1 for POINT EMPTY).
SELECT ST_NPoints(ST_GeomFromText('LINESTRING(0 0, 1 1, 2 2)')::GEOSILO);
-- 3
Related functions
- ST_IsEmpty() — Native GEOSILO overload — `TRUE` if the encoded geometry has no vertices, including polygons, multi-geometries and collections made only of empty parts (`GEOMETRYCOLLECTION(POINT EMPTY)` is empty)
- ST_Length() — Native GEOSILO overload — total planar length of the linear parts (`LINESTRING`, `MULTILINESTRING`, and linestrings inside a `GEOMETRYCOLLECTION`), computed on the integer delta stream without rehydrating a `GEOMETRY`
Signature
Arguments (Positional)
| Argument | Type | Mode | Description |
|---|---|---|---|
Argument
geom
|
Type
GEOSILO
|
Mode Positional | Description |
Description
Native GEOSILO overload — X coordinate of a POINT, read straight from the silo bytes without materializing a GEOMETRY. Returns NULL for POINT EMPTY and raises an error for any other geometry type, like spatial's ST_X.
DuckDB 2.0 build: POINT EMPTY gives NULL (the Haybarn 1.5 build returns NaN).
SELECT ST_X(ST_Point(1.5, 2.5)::GEOSILO);
-- 1.5
Related functions
- ST_Y() — Native GEOSILO overload — Y coordinate of a POINT, read straight from the silo bytes without materializing a `GEOMETRY`
- ST_XMin() — Native GEOSILO overload — minimum X across the geometry, computed by walking the integer delta stream
- ST_XMax() — Native GEOSILO overload — maximum X across the geometry
Signature
Arguments (Positional)
| Argument | Type | Mode | Description |
|---|---|---|---|
Argument
geom
|
Type
GEOSILO
|
Mode Positional | Description |
Description
Native GEOSILO overload — maximum X across the geometry. Walks the integer delta stream; no WKB decode. Returns NULL for an empty geometry.
DuckDB 2.0 build: empty geometries return NULL instead of NaN, and coordinates on both sides of the antimeridian are handled exactly.
SELECT ST_XMax(ST_GeomFromText('LINESTRING(0 0, 5 5)')::GEOSILO);
-- 5.0
Signature
Arguments (Positional)
| Argument | Type | Mode | Description |
|---|---|---|---|
Argument
geom
|
Type
GEOSILO
|
Mode Positional | Description |
Description
Native GEOSILO overload — minimum X across the geometry, computed by walking the integer delta stream. Pair with ST_XMax / ST_YMin / ST_YMax for native bounding-box prefilters. Returns NULL for an empty geometry.
DuckDB 2.0 build: empty geometries return NULL instead of NaN, and coordinates on both sides of the antimeridian are handled exactly.
SELECT ST_XMin(ST_GeomFromText('LINESTRING(0 0, 5 5)')::GEOSILO);
-- 0.0
Signature
Arguments (Positional)
| Argument | Type | Mode | Description |
|---|---|---|---|
Argument
geom
|
Type
GEOSILO
|
Mode Positional | Description |
Description
Native GEOSILO overload — Y coordinate of a POINT, read straight from the silo bytes without materializing a GEOMETRY. Returns NULL for POINT EMPTY and raises an error for any other geometry type, like spatial's ST_Y.
DuckDB 2.0 build: POINT EMPTY gives NULL (the Haybarn 1.5 build returns NaN).
SELECT ST_Y(ST_Point(1.5, 2.5)::GEOSILO);
-- 2.5
Signature
Arguments (Positional)
| Argument | Type | Mode | Description |
|---|---|---|---|
Argument
geom
|
Type
GEOSILO
|
Mode Positional | Description |
Description
Native GEOSILO overload — maximum Y across the geometry. Walks the integer delta stream; no WKB decode. Returns NULL for an empty geometry.
DuckDB 2.0 build: empty geometries return NULL instead of NaN, and coordinates on both sides of the antimeridian are handled exactly.
SELECT ST_YMax(ST_GeomFromText('LINESTRING(0 0, 5 5)')::GEOSILO);
-- 5.0
Signature
Arguments (Positional)
| Argument | Type | Mode | Description |
|---|---|---|---|
Argument
geom
|
Type
GEOSILO
|
Mode Positional | Description |
Description
Native GEOSILO overload — minimum Y across the geometry. Walks the integer delta stream; no WKB decode. Returns NULL for an empty geometry.
DuckDB 2.0 build: empty geometries return NULL instead of NaN, and coordinates on both sides of the antimeridian are handled exactly.
SELECT ST_YMin(ST_GeomFromText('LINESTRING(0 0, 5 5)')::GEOSILO);
-- 0.0