map_tables_template.sql 4.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990
  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 (layer) and mapset (name(:layer)@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. layer VARCHAR, -- The layer id of the map, this is currently only in use by vector maps
  19. creator VARCHAR NOT NULL,
  20. temporal_type VARCHAR, -- The temporal type of the grass map "absolute" or "relative" or NULL in case no time stamp is available
  21. creation_time TIMESTAMP NOT NULL, -- The time of creation of the grass map
  22. -- Uncommented due to performance issues
  23. -- modification_time TIMESTAMP NOT NULL, -- The time of the last modification of the grass map
  24. -- revision SMALLINT NOT NULL, -- The revision number
  25. PRIMARY KEY (id)
  26. );
  27. -- Relative valid time interval with start and end time
  28. CREATE TABLE GRASS_MAP_relative_time (
  29. 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
  30. start_time INTEGER, -- The relative valid start time in
  31. end_time INTEGER, -- The relative valid end time in
  32. unit VARCHAR, -- The relative time unit, available are "years, months, days, minutes, seconds"
  33. PRIMARY KEY (id),
  34. FOREIGN KEY (id) REFERENCES GRASS_MAP_base (id) ON DELETE CASCADE
  35. );
  36. CREATE INDEX GRASS_MAP_relative_time_index ON GRASS_MAP_relative_time (start_time, end_time);
  37. CREATE TABLE GRASS_MAP_absolute_time (
  38. 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
  39. start_time TIMESTAMP, -- Start of the valid time, can be NULL if no time information is available
  40. 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
  41. 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
  42. PRIMARY KEY (id),
  43. FOREIGN KEY (id) REFERENCES GRASS_MAP_base (id) ON DELETE CASCADE
  44. );
  45. CREATE INDEX GRASS_MAP_absolute_time_index ON GRASS_MAP_absolute_time (start_time, end_time);
  46. -- The spatial extent of a raster map
  47. CREATE TABLE GRASS_MAP_spatial_extent (
  48. 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
  49. -- below is the spatial extent of the map
  50. north DOUBLE PRECISION NOT NULL,
  51. south DOUBLE PRECISION NOT NULL,
  52. east DOUBLE PRECISION NOT NULL,
  53. west DOUBLE PRECISION NOT NULL,
  54. top DOUBLE PRECISION NOT NULL,
  55. bottom DOUBLE PRECISION NOT NULL,
  56. proj VARCHAR,
  57. PRIMARY KEY (id),
  58. FOREIGN KEY (id) REFERENCES GRASS_MAP_base (id) ON DELETE CASCADE
  59. );
  60. -- Create a trigger to update the modification time and revision number in case the metadata or timestanps have been updated
  61. --CREATE TRIGGER update_GRASS_MAP_absolute_time AFTER UPDATE ON GRASS_MAP_absolute_time
  62. -- BEGIN
  63. -- UPDATE GRASS_MAP_base SET modification_time = datetime("NOW") WHERE id = old.id;
  64. -- UPDATE GRASS_MAP_base SET revision = (revision + 1) WHERE id = old.id;
  65. -- END;
  66. --CREATE TRIGGER update_GRASS_MAP_relative_time AFTER UPDATE ON GRASS_MAP_relative_time
  67. -- BEGIN
  68. -- UPDATE GRASS_MAP_base SET modification_time = datetime("NOW") WHERE id = old.id;
  69. -- UPDATE GRASS_MAP_base SET revision = (revision + 1) WHERE id = old.id;
  70. -- END;
  71. --CREATE TRIGGER update_GRASS_MAP_spatial_extent AFTER UPDATE ON GRASS_MAP_spatial_extent
  72. -- BEGIN
  73. -- UPDATE GRASS_MAP_base SET modification_time = datetime("NOW") WHERE id = old.id;
  74. -- UPDATE GRASS_MAP_base SET revision = (revision + 1) WHERE id = old.id;
  75. -- END;