Skip to content

Validation 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

Validation

3 functions

geosilo_is_valid

Scalar function Validation
Signature
2 overloaded forms · click to inspect
Arguments (Positional)
Argument blob Type BLOB Mode Positional Description
Description
1 A valid blob and a corrupt one
SELECT geosilo_is_valid(geosilo_encode(ST_Point(1, 2))) AS good,
       geosilo_is_valid('\x54\xff\xff\xff\x7f'::BLOB) AS truncated;

geosilo_validate

Scalar function Validation
Signature
2 overloaded forms · click to inspect
Arguments (Positional)
Argument blob Type BLOB Mode Positional Description
Description
1 Explain why blobs are rejected
SELECT b, geosilo_validate(b) AS problem
FROM (VALUES (geosilo_encode(ST_Point(1, 2))), ('\x47\x01'::BLOB), ('\x54\xff\xff\xff\x7f'::BLOB)) t(b);

try_geosilo_decode

Scalar function Validation
Signature
2 overloaded forms · click to inspect
Arguments (Positional)
Argument blob Type BLOB Mode Positional Description
Description
1 Decode a column that may contain corrupt values
SELECT ST_AsText(try_geosilo_decode(b)) AS wkt
FROM (VALUES (geosilo_encode(ST_Point(1, 2))), ('\x54\xff'::BLOB)) t(b);