strds_metadata_table.sql 3.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677
  1. --#############################################################################
  2. -- This SQL script generates the space time raster dataset metadata table,
  3. -- view and trigger
  4. --
  5. -- Author: Soeren Gebbert soerengebbert <at> googlemail <dot> com
  6. --#############################################################################
  7. --PRAGMA foreign_keys = ON;
  8. CREATE TABLE strds_metadata (
  9. id VARCHAR NOT NULL, -- Id of the space-time dataset, this is the primary foreign key
  10. raster_register VARCHAR, -- The id of the table in which the raster maps are registered for this dataset
  11. number_of_maps INTEGER, -- The number of registered raster maps
  12. max_min DOUBLE PRECISION, -- The minimal maximum of the registered raster maps
  13. min_min DOUBLE PRECISION, -- The minimal minimum of the registered raster maps
  14. max_max DOUBLE PRECISION, -- The maximal maximum of the registered raster maps
  15. min_max DOUBLE PRECISION, -- The maximal minimum of the registered raster maps
  16. nsres_min DOUBLE PRECISION, -- The lowest north-south resolution of the registered raster maps
  17. nsres_max DOUBLE PRECISION, -- The highest north-south resolution of the registered raster maps
  18. ewres_min DOUBLE PRECISION, -- The lowest east-west resolution of the registered raster maps
  19. ewres_max DOUBLE PRECISION, -- The highest east-west resolution of the registered raster maps
  20. title VARCHAR, -- Title of the space-time raster dataset
  21. description VARCHAR, -- Detailed description of the space-time raster dataset
  22. PRIMARY KEY (id),
  23. FOREIGN KEY (id) REFERENCES strds_base (id) ON DELETE CASCADE
  24. );
  25. -- Create the views to access all cols for absolute or relative time
  26. CREATE VIEW strds_view_abs_time AS SELECT
  27. A1.id, A1.name, A1.mapset, A1.temporal_type,
  28. A1.semantic_type,
  29. A1.creation_time,
  30. -- Uncommented due to performance issues
  31. -- A1.modification_time, A1.revision,
  32. A1.creator,
  33. A2.start_time, A2.end_time, A2.timezone, A2.granularity,
  34. A3.north, A3.south, A3.east, A3.west, A3.proj,
  35. A4.raster_register,
  36. A4.number_of_maps,
  37. A4.nsres_min, A4.ewres_min,
  38. A4.nsres_max, A4.ewres_max,
  39. A4.min_min, A4.min_max,
  40. A4.max_min, A4.max_max,
  41. A4.title, A4.description
  42. FROM strds_base A1, strds_absolute_time A2,
  43. strds_spatial_extent A3, strds_metadata A4 WHERE A1.id = A2.id AND
  44. A1.id = A3.id AND A1.id = A4.id;
  45. CREATE VIEW strds_view_rel_time AS SELECT
  46. A1.id, A1.name, A1.mapset, A1.temporal_type,
  47. A1.semantic_type,
  48. A1.creation_time,
  49. -- Uncommented due to performance issues
  50. -- A1.modification_time, A1.revision,
  51. A1.creator,
  52. A2.start_time, A2.end_time, A2.granularity,
  53. A3.north, A3.south, A3.east, A3.west, A3.proj,
  54. A4.raster_register,
  55. A4.number_of_maps,
  56. A4.nsres_min, A4.ewres_min,
  57. A4.nsres_max, A4.ewres_max,
  58. A4.min_min, A4.min_max,
  59. A4.max_min, A4.max_max,
  60. A4.title, A4.description
  61. FROM strds_base A1, strds_relative_time A2,
  62. strds_spatial_extent A3, strds_metadata A4 WHERE A1.id = A2.id AND
  63. A1.id = A3.id AND A1.id = A4.id;
  64. -- Create a trigger to update the modification time and revision number in case the metadata or timestanps have been updated
  65. -- Uncommented due to performance issues
  66. --CREATE TRIGGER update_strds_metadata AFTER UPDATE ON strds_metadata
  67. -- BEGIN
  68. -- UPDATE strds_base SET modification_time = datetime("NOW") WHERE id = old.id;
  69. -- UPDATE strds_base SET revision = (revision + 1) WHERE id = old.id;
  70. -- END;