map_tables_template.sql 4.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485
  1. --#############################################################################
  2. -- This SQL script generates the grass map tables to store time stamps, revision
  3. -- and spatial extent for SQL queries and temporal GIS support.
  4. -- Additionally several triggers are created for convenient functions
  5. -- The grass map metadata is map specific (raster, raster3d and vector maps are
  6. -- supported)
  7. --
  8. -- The placeholder GRASS_MAP will be replaced by raster, raster3d and vector
  9. --
  10. -- Author: Soeren Gebbert soerengebbert <at> googlemail <dot> com
  11. --#############################################################################
  12. -- GRASS_MAP is a placeholder for specific map type: raster, raster3d or vector
  13. --PRAGMA foreign_keys = ON;
  14. CREATE TABLE GRASS_MAP_base (
  15. id VARCHAR NOT NULL, -- The id (PK) is the unique identifier for all tables, it is based on name and mapset (name@mapset) and is used as primary key
  16. name VARCHAR NOT NULL, -- name of the grass map
  17. mapset VARCHAR NOT NULL, -- mapset of the grass map
  18. creator VARCHAR NOT NULL,
  19. temporal_type VARCHAR, -- The temporal type of the grass map "absolute" or "relative" or NULL in case no time stamp is available
  20. creation_time TIMESTAMP NOT NULL, -- The time of creation of the grass map
  21. -- Uncommented due to performance issues
  22. -- modification_time TIMESTAMP NOT NULL, -- The time of the last modification of the grass map
  23. -- revision SMALLINT NOT NULL, -- The revision number
  24. PRIMARY KEY (id)
  25. );
  26. -- Relative valid time interval with start and end time
  27. CREATE TABLE GRASS_MAP_relative_time (
  28. 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
  29. start_time INTEGER, -- The relative valid start time in
  30. end_time INTEGER, -- The relative valid end time in
  31. unit VARCHAR, -- The relative time unit, available are "years, months, days, minutes, seconds"
  32. PRIMARY KEY (id),
  33. FOREIGN KEY (id) REFERENCES GRASS_MAP_base (id) ON DELETE CASCADE
  34. );
  35. CREATE TABLE GRASS_MAP_absolute_time (
  36. 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
  37. start_time TIMESTAMP, -- Start of the valid time, can be NULL if no time information is available
  38. end_time TIMESTAMP, -- End of the valid time, can be NULL if no time information is available or valid time is a single point in time
  39. timezone VARCHAR, -- The timezone of the valid time stored as string. This is currently not in use. Instead the timezone is set in the datetime strings
  40. PRIMARY KEY (id),
  41. FOREIGN KEY (id) REFERENCES GRASS_MAP_base (id) ON DELETE CASCADE
  42. );
  43. -- The spatial extent of a raster map
  44. CREATE TABLE GRASS_MAP_spatial_extent (
  45. 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 foreigen key
  46. -- below is the spatial extent of the map
  47. north DOUBLE PRECISION NOT NULL,
  48. south DOUBLE PRECISION NOT NULL,
  49. east DOUBLE PRECISION NOT NULL,
  50. west DOUBLE PRECISION NOT NULL,
  51. top DOUBLE PRECISION NOT NULL,
  52. bottom DOUBLE PRECISION NOT NULL,
  53. proj VARCHAR,
  54. PRIMARY KEY (id),
  55. FOREIGN KEY (id) REFERENCES GRASS_MAP_base (id) ON DELETE CASCADE
  56. );
  57. -- Create a trigger to update the modification time and revision number in case the metadata or timestanps have been updated
  58. --CREATE TRIGGER update_GRASS_MAP_absolute_time AFTER UPDATE ON GRASS_MAP_absolute_time
  59. -- BEGIN
  60. -- UPDATE GRASS_MAP_base SET modification_time = datetime("NOW") WHERE id = old.id;
  61. -- UPDATE GRASS_MAP_base SET revision = (revision + 1) WHERE id = old.id;
  62. -- END;
  63. --CREATE TRIGGER update_GRASS_MAP_relative_time AFTER UPDATE ON GRASS_MAP_relative_time
  64. -- BEGIN
  65. -- UPDATE GRASS_MAP_base SET modification_time = datetime("NOW") WHERE id = old.id;
  66. -- UPDATE GRASS_MAP_base SET revision = (revision + 1) WHERE id = old.id;
  67. -- END;
  68. --CREATE TRIGGER update_GRASS_MAP_spatial_extent AFTER UPDATE ON GRASS_MAP_spatial_extent
  69. -- BEGIN
  70. -- UPDATE GRASS_MAP_base SET modification_time = datetime("NOW") WHERE id = old.id;
  71. -- UPDATE GRASS_MAP_base SET revision = (revision + 1) WHERE id = old.id;
  72. -- END;