raster_metadata_table.sql 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778
  1. --#############################################################################
  2. -- This SQL script generates the raster 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 raster metadata available in grass
  10. CREATE TABLE raster_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. strds_register VARCHAR, -- The name of the table storing all space-time raster datasets in which this map is registered
  13. datatype VARCHAR NOT NULL,
  14. cols INTEGER NOT NULL,
  15. rows INTEGER NOT NULL,
  16. number_of_cells INTEGER NOT NULL,
  17. nsres DOUBLE PRECISION NOT NULL,
  18. ewres DOUBLE PRECISION NOT NULL,
  19. min DOUBLE PRECISION NOT NULL,
  20. max DOUBLE PRECISION NOT NULL,
  21. PRIMARY KEY (id),
  22. FOREIGN KEY (id) REFERENCES raster_base (id) ON DELETE CASCADE
  23. );
  24. -- Create the views to access all cols for the absolute and relative time
  25. CREATE VIEW raster_view_abs_time AS SELECT
  26. A1.id, A1.mapset,
  27. A1.name, A1.temporal_type,
  28. A1.creation_time, A1.modification_time,
  29. A1.revision, A1.creator,
  30. A2.start_time, A2.end_time,
  31. A3.north, A3.south, A3.east, A3.west, A3.proj,
  32. A4.datatype, A4.cols, A4.rows,
  33. A4.nsres, A4.ewres, A4.min, A4.max,
  34. A4.strds_register,
  35. A4.number_of_cells
  36. FROM raster_base A1, raster_absolute_time A2,
  37. raster_spatial_extent A3, raster_metadata A4
  38. WHERE A1.id = A2.id AND A1.id = A3.id AND A1.id = A4.id;
  39. CREATE VIEW raster_view_rel_time AS SELECT
  40. A1.id, A1.mapset,
  41. A1.name, A1.temporal_type,
  42. A1.creation_time, A1.modification_time,
  43. A1.revision, A1.creator,
  44. A2.interval,
  45. A3.north, A3.south, A3.east, A3.west, A3.proj,
  46. A4.datatype, A4.cols, A4.rows,
  47. A4.nsres, A4.ewres, A4.min, A4.max,
  48. A4.strds_register,
  49. A4.number_of_cells
  50. FROM raster_base A1, raster_relative_time A2,
  51. raster_spatial_extent A3, raster_metadata A4
  52. WHERE A1.id = A2.id AND A1.id = A3.id AND A1.id = A4.id;
  53. -- Create a trigger to update the modification time and revision number in case the metadata have been updated
  54. CREATE TRIGGER update_raster_metadata AFTER UPDATE ON raster_metadata
  55. BEGIN
  56. UPDATE raster_base SET modification_time = datetime("NOW") WHERE id = old.id;
  57. UPDATE raster_base SET revision = (revision + 1) WHERE id = old.id;
  58. END;
  59. -- Create trigger for automated deletion of dependent rows, this should normally be done using foreign keys
  60. CREATE TRIGGER delete_raster_base AFTER DELETE ON raster_base
  61. BEGIN
  62. DELETE FROM raster_absolute_time WHERE id = old.id;
  63. DELETE FROM raster_relative_time WHERE id = old.id;
  64. DELETE FROM raster_spatial_extent WHERE id = old.id;
  65. DELETE FROM raster_metadata WHERE id = old.id;
  66. END;