map_tables_template.sql 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384
  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 DOUBLE PRECISION, -- The relative valid start time in [days]
  30. end_time DOUBLE PRECISION, -- The relative valid end time in [days]
  31. PRIMARY KEY (id),
  32. FOREIGN KEY (id) REFERENCES GRASS_MAP_base (id) ON DELETE CASCADE
  33. );
  34. CREATE TABLE GRASS_MAP_absolute_time (
  35. 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
  36. start_time TIMESTAMP, -- Start of the valid time, can be NULL if no time information is available
  37. 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
  38. timezone SMALLINT, -- The timezone of the valid time
  39. PRIMARY KEY (id),
  40. FOREIGN KEY (id) REFERENCES GRASS_MAP_base (id) ON DELETE CASCADE
  41. );
  42. -- The spatial extent of a raster map
  43. CREATE TABLE GRASS_MAP_spatial_extent (
  44. 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
  45. -- below is the spatial extent of the map
  46. north DOUBLE PRECISION NOT NULL,
  47. south DOUBLE PRECISION NOT NULL,
  48. east DOUBLE PRECISION NOT NULL,
  49. west DOUBLE PRECISION NOT NULL,
  50. top DOUBLE PRECISION NOT NULL,
  51. bottom DOUBLE PRECISION NOT NULL,
  52. proj VARCHAR,
  53. PRIMARY KEY (id),
  54. FOREIGN KEY (id) REFERENCES GRASS_MAP_base (id) ON DELETE CASCADE
  55. );
  56. -- Create a trigger to update the modification time and revision number in case the metadata or timestanps have been updated
  57. --CREATE TRIGGER update_GRASS_MAP_absolute_time AFTER UPDATE ON GRASS_MAP_absolute_time
  58. -- BEGIN
  59. -- UPDATE GRASS_MAP_base SET modification_time = datetime("NOW") WHERE id = old.id;
  60. -- UPDATE GRASS_MAP_base SET revision = (revision + 1) WHERE id = old.id;
  61. -- END;
  62. --CREATE TRIGGER update_GRASS_MAP_relative_time AFTER UPDATE ON GRASS_MAP_relative_time
  63. -- BEGIN
  64. -- UPDATE GRASS_MAP_base SET modification_time = datetime("NOW") WHERE id = old.id;
  65. -- UPDATE GRASS_MAP_base SET revision = (revision + 1) WHERE id = old.id;
  66. -- END;
  67. --CREATE TRIGGER update_GRASS_MAP_spatial_extent AFTER UPDATE ON GRASS_MAP_spatial_extent
  68. -- BEGIN
  69. -- UPDATE GRASS_MAP_base SET modification_time = datetime("NOW") WHERE id = old.id;
  70. -- UPDATE GRASS_MAP_base SET revision = (revision + 1) WHERE id = old.id;
  71. -- END;