st_isempty.sql 1.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243
  1. -- The CREATE TABLE statement below creates the empty_test table
  2. -- with geotype, which stores the data type of the subclasses
  3. -- that are stored in the g1 ST_Geometry column.
  4. CREATE TABLE empty_test (geotype varchar(20),
  5. g1 ST_Geometry);
  6. -- The INSERT statements insert two records for the geometry subclasses
  7. -- point, linestring, and polygon: one that is empty and one that is not.
  8. INSERT INTO empty_test VALUES(
  9. 'Point', ST_PointFromText('point (10.02 20.01)',1000)
  10. );
  11. INSERT INTO empty_test VALUES(
  12. 'Point', ST_PointFromText('point empty',1000)
  13. );
  14. INSERT INTO empty_test VALUES(
  15. 'Linestring',
  16. ST_LineFromText('linestring (10.02 20.01,10.32 23.98,11.92 25.64)',1000)
  17. );
  18. INSERT INTO empty_test VALUES(
  19. 'Linestring',
  20. ST_LineFromText('linestring empty',1000)
  21. );
  22. INSERT INTO empty_test VALUES(
  23. 'Polygon',
  24. ST_PolyFromText('polygon ((10.02 20.01,11.92 35.64,25.02 34.15,19.15 33.94,10.02 20.01))',1000)
  25. );
  26. INSERT INTO empty_test VALUES(
  27. 'Polygon',
  28. ST_PolyFromText('polygon empty',1000)
  29. );
  30. -- The query returns the geometry type from the geotype column and
  31. -- the results of the ST_IsEmpty function.
  32. SELECT geotype, ST_IsEmpty(g1) Is_it_empty
  33. FROM empty_test