raster_metadata_table.sql 2.9 KB

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