raster3d_metadata_table.sql 3.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182
  1. --#############################################################################
  2. -- This SQL script generates the raster3d metadata table to store
  3. -- and metadata for SQL queries and temporal GIS support. Additionally two views
  4. -- are created to access all map specific tables
  5. --
  6. -- Author: Soeren Gebbert soerengebbert <at> googlemail <dot> com
  7. --#############################################################################
  8. PRAGMA foreign_keys = ON;
  9. -- The metadata table reflects most of the raster3d metadata available in grass
  10. CREATE TABLE raster3d_metadata (
  11. id VARCHAR NOT NULL, -- The id (PFK) is the unique identifier for all tables, it is based on name and mapset (name@mapset) and is used as primary foreign key
  12. str3ds_register VARCHAR, -- The name of the table storing all space-time raster3d datasets in which this map is registered
  13. datatype VARCHAR NOT NULL,
  14. cols INTEGER NOT NULL,
  15. rows INTEGER NOT NULL,
  16. depths INTEGER NOT NULL,
  17. number_of_cells INTEGER NOT NULL,
  18. nsres DOUBLE PRECISION NOT NULL,
  19. ewres DOUBLE PRECISION NOT NULL,
  20. tbres DOUBLE PRECISION NOT NULL,
  21. min DOUBLE PRECISION NOT NULL,
  22. max DOUBLE PRECISION NOT NULL,
  23. PRIMARY KEY (id),
  24. FOREIGN KEY (id) REFERENCES raster3d_base (id) ON DELETE CASCADE
  25. );
  26. -- Create the views to access all cols for the absolute and relative time
  27. CREATE VIEW raster3d_view_abs_time AS SELECT
  28. A1.id, A1.mapset,
  29. A1.name, A1.temporal_type,
  30. A1.creation_time, A1.modification_time,
  31. A1.revision, A1.creator,
  32. A2.start_time, A2.end_time,
  33. A3.north, A3.south, A3.east, A3.west,
  34. A4.datatype, A4.cols, A4.rows, A4.depths,
  35. A4.nsres, A4.ewres, A4.tbres,
  36. A4.min, A4.max,
  37. A4.str3ds_register,
  38. A4.number_of_cells
  39. FROM raster3d_base A1, raster3d_absolute_time A2,
  40. raster3d_spatial_extent A3, raster3d_metadata A4
  41. WHERE A1.id = A2.id AND A1.id = A3.id AND A1.id = A4.id;
  42. CREATE VIEW raster3d_view_rel_time AS SELECT
  43. A1.id, A1.mapset,
  44. A1.name, A1.temporal_type,
  45. A1.creation_time, A1.modification_time,
  46. A1.revision, A1.creator,
  47. A2.interval,
  48. A3.north, A3.south, A3.east, A3.west,
  49. A4.datatype, A4.cols, A4.rows, A4.depths,
  50. A4.nsres, A4.ewres, A4.tbres,
  51. A4.min, A4.max,
  52. A4.str3ds_register,
  53. A4.number_of_cells
  54. FROM raster3d_base A1, raster3d_relative_time A2,
  55. raster3d_spatial_extent A3, raster3d_metadata A4
  56. WHERE A1.id = A2.id AND A1.id = A3.id AND A1.id = A4.id;
  57. -- Create a trigger to update the modification time and revision number in case the metadata have been updated
  58. CREATE TRIGGER update_raster3d_metadata AFTER UPDATE ON raster3d_metadata
  59. BEGIN
  60. UPDATE raster3d_base SET modification_time = datetime("NOW") WHERE id = old.id;
  61. UPDATE raster3d_base SET revision = (revision + 1) WHERE id = old.id;
  62. END;
  63. -- Create trigger for automated deletion of dependent rows, this should normally be done using foreign keys
  64. CREATE TRIGGER delete_raster3d_base AFTER DELETE ON raster3d_base
  65. BEGIN
  66. DELETE FROM raster3d_absolute_time WHERE id = old.id;
  67. DELETE FROM raster3d_relative_time WHERE id = old.id;
  68. DELETE FROM raster3d_spatial_extent WHERE id = old.id;
  69. DELETE FROM raster3d_metadata WHERE id = old.id;
  70. END;