Skip to content

DuckDB Extension

GeoSilo

Store compact geometry values with the GEOSILO type in DuckDB. Encode coordinates on insert and query them with geometry functions.

31,614
extension loads Β· last 90 days
On this page
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);

Store geometry with controlled coordinate precision

GeoSilo adds a compact geometry type that stores scaled integer coordinates and the differences between nearby vertices. You choose the coordinate scale, which determines the precision retained by the encoding.

Use it when storing large geometry datasets and controlling their size matters. The extension supplies native operations for its GEOSILO values and converts to GEOMETRY for other spatial operations. Check the precision and resulting storage size on your own data before adopting the format.

Example

Store and read a point

Load GeoSilo before spatial for compatibility with older builds. The sample supplies its own geometry and uses a temporary table.

Tested with DuckDB 1.5.6. Browser examples use Haybarn-Wasm 2.0.0-rc12.

SET allow_extension_repositories = 'allowed';
CREATE EXTENSION REPOSITORY IF NOT EXISTS query_farm
  WITH PREFIX 'https://duckdb-extensions.query.farm';
INSTALL geosilo FROM query_farm;
LOAD geosilo FROM query_farm;

INSTALL spatial;
LOAD spatial;

CREATE OR REPLACE TEMP TABLE qf_points (
  id INTEGER,
  geom GEOSILO('EPSG:4326')
);
INSERT INTO qf_points VALUES (1, ST_Point(-74.0060, 40.7128));
SELECT id, ST_X(geom) AS longitude, ST_Y(geom) AS latitude
FROM qf_points;

Expected result

id longitude latitude
1 -74.006 40.7128

For persistent tables, see the compression and coordinate-scale guidance. The temporary table above demonstrates the type; it does not measure storage savings.

Common tasks

Deep Dive

Technical Details

Reference

Extension Contents

Quick reference to all available functions and settings organized by category.

Encoding
geosilo_decode() Object type: Scalar function Decode a GEOSILO blob back into a standard GEOMETRY.
geosilo_encode() Object type: Scalar function Encode a GEOMETRY into the compact GEOSILO format and return a BLOB.
geosilo_metadata() Object type: Scalar function Read a GEOSILO blob's header without decoding the geometry.
Introspection (native)
ST_GeometryType() Object type: Scalar function Native GEOSILO overload β€” returns the geometry type (e.g.
ST_IsEmpty() Object type: Scalar function 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() Object type: Scalar function 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.
ST_X() Object type: Scalar function Native GEOSILO overload β€” X coordinate of a POINT, read straight from the silo bytes without materializing a GEOMETRY.
ST_XMax() Object type: Scalar function Native GEOSILO overload β€” maximum X across the geometry.
ST_XMin() Object type: Scalar function Native GEOSILO overload β€” minimum X across the geometry, computed by walking the integer delta stream.
ST_Y() Object type: Scalar function Native GEOSILO overload β€” Y coordinate of a POINT, read straight from the silo bytes without materializing a GEOMETRY.
ST_YMax() Object type: Scalar function Native GEOSILO overload β€” maximum Y across the geometry.
ST_YMin() Object type: Scalar function Native GEOSILO overload β€” minimum Y across the geometry.
Measurement (native)
ST_Area() Object type: Scalar function Native GEOSILO overload β€” planar area of the polygonal parts, computed with the shoelace formula directly on the integer coordinates rebuilt from the delta stream (no WKB decode).
ST_Length() Object type: Scalar function 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.
ST_Perimeter() Object type: Scalar function Native GEOSILO overload β€” perimeter of the polygonal parts, summed over every ring (holes included), computed on the integer delta stream without rehydrating a GEOMETRY.
Types
GEOSILO Object type: Logical type Logical type registered by this extension.
Validation
geosilo_is_valid() Object type: Scalar function DuckDB 2.0 build only. Returns TRUE when the value is a structurally valid GEOSILO blob β€” a known header, element counts consistent with the data, nesting of at most 16 levels and no trailing bytes β€” and FALSE otherwise.
geosilo_validate() Object type: Scalar function DuckDB 2.0 build only. Validates a GEOSILO blob and returns NULL when it is valid, otherwise a message describing the first problem found β€” truncated data, a bad magic byte, an unsupported version, an element count larger than the data, excessive nesting or trailing bytes.
try_geosilo_decode() Object type: Scalar function DuckDB 2.0 build only. Decodes a GEOSILO blob into a GEOMETRY like geosilo_decode, but returns NULL instead of raising an error when the blob is malformed.

API Reference

Function Reference

Data model

Registered Types

Logical types this extension adds to DuckDB. Functions in the reference may accept or return these names directly.

  • GEOSILO

    Logical type registered by this extension.

Practical Examples

Cookbook

Real-world recipes and patterns for common use cases.

Platform Support

Compatibility

Extension availability may vary by platform and DuckDB version. Check below to ensure this extension supports your environment before installation.

Quick Facts

Release status Stable
Software License MIT
Pricing Free
Written In C++
Source Available Yes
View on GitHub
Usage
31,614
loads Β· last 90 days

Platforms

DuckDB 2.0.0

  • Linux x86_64aarch64
  • Linux (musl) Not available
  • macOS Apple Silicon
  • Windows x86_64x86_64 (MinGW)
  • WASM Not available
Compiled binary sizes
Platform Architecture Size
Linux x86_64 4.69 MB
Linux aarch64 3.96 MB
macOS Apple Silicon 3.32 MB
Windows x86_64 10.23 MB
Windows x86_64 (MinGW) 17.85 MB

Compressed download sizes for the release shown above.

DuckDB & Haybarn

Release calendar
  • DuckDB v2.0.0 Query.Farm repository Supported
  • Haybarn v1.5.6 Built-in community repository Supported

Browser examples use Haybarn-Wasm 2.0.0-rc12.

Checked .

Learn and explore

Tutorials and articles

Writing about GeoSilo: how it works, what changed, and why.