SQLiteGIS
PostGIS-style spatial functions for SQLite in pure Rust, primarily a Diesel ORM integration. Geometries travel as EWKB BLOBs, matching the PostGIS wire format so queries port between SQLite and PostGIS without rewriting. The same functions are also exposed as a SQLite loadable extension (native and WebAssembly) for non-Rust consumers like the SQLite CLI. Try the live demo to run spatial SQL against 68k cities entirely in the browser.
Quick start (Diesel)
use *;
use st_point;
use *;
// Register the spatial functions on every new SqliteConnection.
register_on_every_new_connection;
table!
let mut conn = establish.unwrap;
let nearby = table
.filter
.select;
CreateSpatialIndex and DropSpatialIndex are DDL helpers without typed wrappers, called through diesel::sql_query. R-tree-backed queries run 50 to 60x faster than the non-indexed equivalents (see Benchmarks).
Without Diesel: pure-Rust geometry
If you only need the geometry algebra without SQL, the core functions are callable from regular Rust without any database at all.
use st_point;
use st_distance;
let a = st_point.unwrap;
let b = st_point.unwrap;
assert!;
As a SQLite loadable extension
For non-Rust consumers (SQLite CLI, Datasette, the WebAssembly browser path) the same functions are available as a load_extension-style cdylib. Build it yourself with the sqlite-extension feature.
SELECT load_extension('./target/release/libsqlitegis');
SELECT ST_AsText(ST_Buffer(ST_Point(0, 0), 1.0));
SELECT ST_Distance(ST_GeomFromText('POINT(0 0)'), ST_GeomFromText('POINT(3 4)'));
Notes
Geodesic functions (ST_DistanceSphere, ST_DistanceSpheroid, ST_LengthSphere, ST_Azimuth, ST_Project, ST_DWithinSphere, ST_DWithinSpheroid) require SRID=4326 non-empty Point inputs and reject anything else. ST_GeomFromGeoJSON defaults to SRID=4326. ST_DWithin* predicates require a finite, non-negative distance.
Benchmarks
See BENCHMARKS.md for the full R-tree and SpatiaLite comparison reports. Headline: on a 50k-row dataset across 31 head-to-head workloads, sqlitegis wins 20 (geodesic family 3.7x to 8.6x faster, binary predicates 1.2x to 1.7x via an MBR-only fastpath, I/O parse paths 2x faster) and loses 9 (ST_Envelope, ST_AsBinary, and the per-row scalar accessors ST_X/ST_Y/ST_Area/ST_Perimeter go through full EWKB decode where SpatiaLite has thin-C-wrapper shortcuts).
Contributing
See CONTRIBUTING.md.
License
MIT OR Apache-2.0