map_tables_template.sql 3.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970
  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. CREATE INDEX GRASS_MAP_base_index ON GRASS_MAP_base (id);
  28. -- Relative valid time interval with start and end time
  29. CREATE TABLE GRASS_MAP_relative_time (
  30. 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
  31. start_time INTEGER, -- The relative valid start time in
  32. end_time INTEGER, -- The relative valid end time in
  33. unit VARCHAR, -- The relative time unit, available are "years, months, days, minutes, seconds"
  34. FOREIGN KEY (id) REFERENCES GRASS_MAP_base (id) ON DELETE CASCADE ON UPDATE CASCADE
  35. );
  36. CREATE INDEX GRASS_MAP_relative_time_index ON GRASS_MAP_relative_time (id, 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. FOREIGN KEY (id) REFERENCES GRASS_MAP_base (id) ON DELETE CASCADE ON UPDATE CASCADE
  43. );
  44. CREATE INDEX GRASS_MAP_absolute_time_index ON GRASS_MAP_absolute_time (id, start_time, end_time);
  45. -- The spatial extent of a raster map
  46. CREATE TABLE GRASS_MAP_spatial_extent (
  47. 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
  48. -- below is the spatial extent of the map
  49. north DOUBLE PRECISION NOT NULL,
  50. south DOUBLE PRECISION NOT NULL,
  51. east DOUBLE PRECISION NOT NULL,
  52. west DOUBLE PRECISION NOT NULL,
  53. top DOUBLE PRECISION NOT NULL,
  54. bottom DOUBLE PRECISION NOT NULL,
  55. proj VARCHAR,
  56. FOREIGN KEY (id) REFERENCES GRASS_MAP_base (id) ON DELETE CASCADE ON UPDATE CASCADE
  57. );
  58. CREATE INDEX GRASS_MAP_spatial_extent_index ON GRASS_MAP_spatial_extent (id);