duckdb-spatiallisted
Install: claude install-skill srimon12/duckdb-2-skills
# Spatial queries
Before calling spatial functions, install and load `spatial`, then configure coordinate order:
```sql
INSTALL spatial; LOAD spatial;
SET geometry_always_xy = true;
```
DuckDB does not autoload `spatial`. The session setting `geometry_always_xy` starts unset. While unset, CRS-sensitive functions (`ST_Transform`, `ST_Distance_Sphere`, `ST_Distance_Spheroid`, `ST_Area_Spheroid`, `ST_Length_Spheroid`) throw an `Invalid Configuration Error`. Always set `geometry_always_xy = true` to enforce `(longitude, latitude)` coordinate order. If set to `false`, CRS-sensitive operations interpret EPSG:4326 as `(latitude, longitude)`, causing silent calculation errors.
To inspect this setting, query `duckdb_settings()`; calling `current_setting('geometry_always_xy')` throws an error even after `LOAD spatial`.
## Measure
Construct points as `ST_Point(longitude, latitude)`. Longitude always precedes latitude. Select measurement functions by accuracy and cost:
| Goal | Function | Units and cost |
| --- | --- | --- |
| Same-CRS comparison | `ST_Distance` | CRS units (degrees on EPSG:4326); lowest cost |
| Fast meters on lon/lat | `ST_Distance_Sphere` | Meters (spherical approximation); low cost |
| Exact meters on lon/lat | `ST_Distance_Spheroid` | Meters (ellipsoidal calculation); highest cost |
| Radial containment | `ST_DWithin` plus bbox | Boolean; leverages R-tree index |
All spherical and spheroidal calculations rely on session `geometry_always_xy`; only `ST_Transfor