strds_metadata_table.sql 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778
  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. command VARCHAR, -- The command that was used to create the space time raster dataset
  23. PRIMARY KEY (id),
  24. FOREIGN KEY (id) REFERENCES strds_base (id) ON DELETE CASCADE
  25. );
  26. -- Create the views to access all cols for absolute or relative time
  27. CREATE VIEW strds_view_abs_time AS SELECT
  28. A1.id, A1.name, A1.mapset, A1.temporal_type,
  29. A1.semantic_type,
  30. A1.creation_time,
  31. -- Uncommented due to performance issues
  32. -- A1.modification_time, A1.revision,
  33. A1.creator,
  34. A2.start_time, A2.end_time, A2.timezone, A2.granularity,
  35. A3.north, A3.south, A3.east, A3.west, A3.proj,
  36. A4.raster_register,
  37. A4.number_of_maps,
  38. A4.nsres_min, A4.ewres_min,
  39. A4.nsres_max, A4.ewres_max,
  40. A4.min_min, A4.min_max,
  41. A4.max_min, A4.max_max,
  42. A4.title, A4.description, A4.command
  43. FROM strds_base A1, strds_absolute_time A2,
  44. strds_spatial_extent A3, strds_metadata A4 WHERE A1.id = A2.id AND
  45. A1.id = A3.id AND A1.id = A4.id;
  46. CREATE VIEW strds_view_rel_time AS SELECT
  47. A1.id, A1.name, A1.mapset, A1.temporal_type,
  48. A1.semantic_type,
  49. A1.creation_time,
  50. -- Uncommented due to performance issues
  51. -- A1.modification_time, A1.revision,
  52. A1.creator,
  53. A2.start_time, A2.end_time, A2.granularity,
  54. A3.north, A3.south, A3.east, A3.west, A3.proj,
  55. A4.raster_register,
  56. A4.number_of_maps,
  57. A4.nsres_min, A4.ewres_min,
  58. A4.nsres_max, A4.ewres_max,
  59. A4.min_min, A4.min_max,
  60. A4.max_min, A4.max_max,
  61. A4.title, A4.description, A4.command
  62. FROM strds_base A1, strds_relative_time A2,
  63. strds_spatial_extent A3, strds_metadata A4 WHERE A1.id = A2.id AND
  64. A1.id = A3.id AND A1.id = A4.id;
  65. -- Create a trigger to update the modification time and revision number in case the metadata or timestanps have been updated
  66. -- Uncommented due to performance issues
  67. --CREATE TRIGGER update_strds_metadata AFTER UPDATE ON strds_metadata
  68. -- BEGIN
  69. -- UPDATE strds_base SET modification_time = datetime("NOW") WHERE id = old.id;
  70. -- UPDATE strds_base SET revision = (revision + 1) WHERE id = old.id;
  71. -- END;