raster3d_metadata_table.sql 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475
  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,
  22. max DOUBLE PRECISION,
  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,
  31. -- Uncommented due to performance issues
  32. -- A1.modification_time, A1.revision,
  33. A1.creator,
  34. A2.start_time, A2.end_time, A2.timezone,
  35. A3.north, A3.south, A3.east, A3.west, A3.proj,
  36. A4.datatype, A4.cols, A4.rows, A4.depths,
  37. A4.nsres, A4.ewres, A4.tbres,
  38. A4.min, A4.max,
  39. A4.str3ds_register,
  40. A4.number_of_cells
  41. FROM raster3d_base A1, raster3d_absolute_time A2,
  42. raster3d_spatial_extent A3, raster3d_metadata A4
  43. WHERE A1.id = A2.id AND A1.id = A3.id AND A1.id = A4.id;
  44. CREATE VIEW raster3d_view_rel_time AS SELECT
  45. A1.id, A1.mapset,
  46. A1.name, A1.temporal_type,
  47. A1.creation_time,
  48. -- Uncommented due to performance issues
  49. -- A1.modification_time, A1.revision,
  50. A1.creator,
  51. A2.start_time, A2.end_time,
  52. A3.north, A3.south, A3.east, A3.west, A3.proj,
  53. A4.datatype, A4.cols, A4.rows, A4.depths,
  54. A4.nsres, A4.ewres, A4.tbres,
  55. A4.min, A4.max,
  56. A4.str3ds_register,
  57. A4.number_of_cells
  58. FROM raster3d_base A1, raster3d_relative_time A2,
  59. raster3d_spatial_extent A3, raster3d_metadata A4
  60. WHERE A1.id = A2.id AND A1.id = A3.id AND A1.id = A4.id;
  61. -- Create a trigger to update the modification time and revision number in case the metadata have been updated
  62. --CREATE TRIGGER update_raster3d_metadata AFTER UPDATE ON raster3d_metadata
  63. -- BEGIN
  64. -- UPDATE raster3d_base SET modification_time = datetime("NOW") WHERE id = old.id;
  65. -- UPDATE raster3d_base SET revision = (revision + 1) WHERE id = old.id;
  66. -- END;