str3ds_metadata_table.sql 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081
  1. --#############################################################################
  2. -- This SQL script generates the space time raster3d 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 str3ds_metadata (
  9. id VARCHAR NOT NULL, -- Id of the space-time raster3d dataset, this is the primary foreign key
  10. raster3d_register VARCHAR, -- The id of the table in which the raster3d maps are registered for this dataset
  11. number_of_maps INTEGER, -- The number of registered raster3d maps
  12. max_min DOUBLE PRECISION, -- The minimal maximum of the registered raster3d maps
  13. min_min DOUBLE PRECISION, -- The minimal minimum of the registered raster3d maps
  14. max_max DOUBLE PRECISION, -- The maximal maximum of the registered raster3d maps
  15. min_max DOUBLE PRECISION, -- The maximal minimum of the registered raster3d maps
  16. nsres_min DOUBLE PRECISION, -- The lowest north-south resolution of the registered raster3d maps
  17. nsres_max DOUBLE PRECISION, -- The highest north-south resolution of the registered raster3d maps
  18. ewres_min DOUBLE PRECISION, -- The lowest east-west resolution of the registered raster3d maps
  19. ewres_max DOUBLE PRECISION, -- The highest east-west resolution of the registered raster3d maps
  20. tbres_min DOUBLE PRECISION, -- The lowest top-bottom resolution of the registered raster3d maps
  21. tbres_max DOUBLE PRECISION, -- The highest top-bottom resolution of the registered raster3d maps
  22. title VARCHAR, -- Title of the space-time raster3d dataset
  23. description VARCHAR, -- Detailed description of the space-time raster3d dataset
  24. PRIMARY KEY (id),
  25. FOREIGN KEY (id) REFERENCES str3ds_base (id) ON DELETE CASCADE
  26. );
  27. -- Create the views to access all cols for absolute or relative time
  28. CREATE VIEW str3ds_view_abs_time AS SELECT
  29. A1.id, A1.name, A1.mapset, A1.temporal_type,
  30. A1.semantic_type,
  31. A1.creation_time,
  32. -- Uncommented due to performance issues
  33. -- A1.modification_time, A1.revision,
  34. A1.creator,
  35. A2.start_time, A2.end_time, A2.timezone, A2.granularity,
  36. A3.north, A3.south, A3.east, A3.west, A3.proj,
  37. A4.raster3d_register,
  38. A4.number_of_maps,
  39. A4.nsres_min, A4.ewres_min,
  40. A4.nsres_max, A4.ewres_max,
  41. A4.tbres_min, A4.tbres_max,
  42. A4.min_min, A4.min_max,
  43. A4.max_min, A4.max_max,
  44. A4.title, A4.description
  45. FROM str3ds_base A1, str3ds_absolute_time A2,
  46. str3ds_spatial_extent A3, str3ds_metadata A4 WHERE A1.id = A2.id AND
  47. A1.id = A3.id AND A1.id = A4.id;
  48. CREATE VIEW str3ds_view_rel_time AS SELECT
  49. A1.id, A1.name, A1.mapset, A1.temporal_type,
  50. A1.semantic_type,
  51. A1.creation_time,
  52. -- Uncommented due to performance issues
  53. -- A1.modification_time, A1.revision,
  54. A1.creator,
  55. A2.start_time, A2.end_time, A2.granularity,
  56. A3.north, A3.south, A3.east, A3.west, A3.proj,
  57. A4.raster3d_register,
  58. A4.number_of_maps,
  59. A4.nsres_min, A4.ewres_min,
  60. A4.nsres_max, A4.ewres_max,
  61. A4.tbres_min, A4.tbres_max,
  62. A4.min_min, A4.min_max,
  63. A4.max_min, A4.max_max,
  64. A4.title, A4.description
  65. FROM str3ds_base A1, str3ds_relative_time A2,
  66. str3ds_spatial_extent A3, str3ds_metadata A4 WHERE A1.id = A2.id AND
  67. A1.id = A3.id AND A1.id = A4.id;
  68. -- Create a trigger to update the modification time and revision number in case the metadata or timestanps have been updated
  69. -- Uncommented due to performance issues
  70. --CREATE TRIGGER update_str3ds_metadata AFTER UPDATE ON str3ds_metadata
  71. -- BEGIN
  72. -- UPDATE str3ds_base SET modification_time = datetime("NOW") WHERE id = old.id;
  73. -- UPDATE str3ds_base SET revision = (revision + 1) WHERE id = old.id;
  74. -- END;