Skip to content

Instantly share code, notes, and snippets.

@smithdc1
Created August 18, 2025 10:01
Show Gist options
  • Select an option

  • Save smithdc1/edefd6d95483ecae2a56cc5790605bac to your computer and use it in GitHub Desktop.

Select an option

Save smithdc1/edefd6d95483ecae2a56cc5790605bac to your computer and use it in GitHub Desktop.
sqlite> .load /usr/local/lib/mod_spatialite.so
sqlite> CREATE TABLE test_geometries (
id INTEGER PRIMARY KEY,
name TEXT,
geom GEOMETRY
);
sqlite> INSERT INTO test_geometries (id, name, geom) VALUES
(1, 'Valid Point', GeomFromText('POINT(1 1)', 4326)),
(2, 'Valid Polygon', GeomFromText('POLYGON((0 0, 1 0, 1 1, 0 1, 0 0))', 4326)),
(3, 'Empty Point', GeomFromText('POINT EMPTY', 4326)),
(4, 'Empty Polygon', GeomFromText('POLYGON EMPTY', 4326)),
(5, 'Valid LineString', GeomFromText('LINESTRING(0 0, 1 1, 2 2)', 4326)),
(6, 'Empty LineString', GeomFromText('LINESTRING EMPTY', 4326)),
(7, 'NULL Geometry', NULL),
(100, 'Nowhere', GeomFromText(NULL, 4326));
sqlite> SELECT *, ST_IsEmpty(geom), IsEmpty(geom) from test_geometries;
1|Valid Point||0|0
2|Valid Polygon||0|0
3|Empty Point||-1|-1
4|Empty Polygon||-1|-1
5|Valid LineString||0|0
6|Empty LineString||-1|-1
7|NULL Geometry||-1|-1
100|Nowhere||-1|-1
sqlite> SELECT *, IsEmpty(geom) as isempty FROM test_geometries WHERE IsEmpty(geom);
3|Empty Point||-1
4|Empty Polygon||-1
6|Empty LineString||-1
7|NULL Geometry||-1
100|Nowhere||-1
sqlite> SELECT *, IsEmpty(geom) as isempty FROM test_geometries WHERE ST_IsEmpty(geom);
3|Empty Point||-1
4|Empty Polygon||-1
6|Empty LineString||-1
7|NULL Geometry||-1
100|Nowhere||-1
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment