Measurement (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
Measurement (native)
3 functionsST_* overloads for area, length, and perimeter computed directly on the integer delta stream (shoelace for area, accumulated in double precision). No WKB decode, no GEOS dependency surface for these calls. They follow spatial's semantics: area and perimeter count only polygonal parts, length only linear parts.
Signature
Arguments (Positional)
| Argument | Type | Mode | Description |
|---|---|---|---|
Argument
geom
|
Type
GEOSILO
|
Mode Positional | Description |
Description
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). Each polygon contributes its exterior ring minus its holes regardless of ring orientation; MULTIPOLYGONs and polygons inside a GEOMETRYCOLLECTION are summed; points and linestrings contribute 0. Matches spatial's ST_Area.
DuckDB 2.0 build: linestrings return 0 and holes are always subtracted (the Haybarn 1.5 build returns a non-zero area for a closed LINESTRING and mis-handles holes wound in the same direction as the shell); the sum is accumulated in double precision so large polygons at scale 1e7 cannot overflow.
SELECT ST_Area(ST_GeomFromText('POLYGON((0 0, 4 0, 4 3, 0 3, 0 0))')::GEOSILO);
-- 12.0
SELECT ST_Area(ST_GeomFromText('POLYGON((0 0, 10 0, 10 10, 0 10, 0 0), (2 2, 8 2, 8 8, 2 8, 2 2))')::GEOSILO);
-- 64.0
Related functions
- ST_Perimeter() — Native GEOSILO overload — perimeter of the polygonal parts, summed over every ring (holes included), computed on the integer delta stream without rehydrating a `GEOMETRY`
- 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 — total planar length of the linear parts (LINESTRING, MULTILINESTRING, and linestrings inside a GEOMETRYCOLLECTION), computed on the integer delta stream without rehydrating a GEOMETRY. Polygons and points return 0 — use ST_Perimeter for polygon boundaries. Matches spatial's ST_Length.
DuckDB 2.0 build: polygons return 0 (the Haybarn 1.5 build returns their perimeter), and segments that cross the antimeridian are measured correctly: LINESTRING(-179 0, 179 0) has length 358.
SELECT ST_Length(ST_GeomFromText('LINESTRING(0 0, 3 4)')::GEOSILO);
-- 5.0
SELECT ST_Length(ST_GeomFromText('LINESTRING(-179 0, 179 0)')::GEOSILO);
-- 358.0
Related functions
- ST_Perimeter() — Native GEOSILO overload — perimeter of the polygonal parts, summed over every ring (holes included), computed on the integer delta stream without rehydrating a `GEOMETRY`
- ST_Area() — Native GEOSILO overload — planar area of the polygonal parts, computed with the [shoelace formula](https://en
Signature
Arguments (Positional)
| Argument | Type | Mode | Description |
|---|---|---|---|
Argument
geom
|
Type
GEOSILO
|
Mode Positional | Description |
Description
Native GEOSILO overload — perimeter of the polygonal parts, summed over every ring (holes included), computed on the integer delta stream without rehydrating a GEOMETRY. Points and linestrings return 0. Matches spatial's ST_Perimeter.
DuckDB 2.0 build: linestrings return 0, and linestrings inside a GEOMETRYCOLLECTION are no longer added to the perimeter.
SELECT ST_Perimeter(ST_GeomFromText('POLYGON((0 0, 4 0, 4 3, 0 3, 0 0))')::GEOSILO);
-- 14.0
Related functions
- ST_Area() — Native GEOSILO overload — planar area of the polygonal parts, computed with the [shoelace formula](https://en
- 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`