vector_metadata_table.sql 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475
  1. --#############################################################################
  2. -- This SQL script generates the vector table to store
  3. -- metadata for SQL queries and temporal GIS support.
  4. --
  5. -- Author: Soeren Gebbert soerengebbert <at> googlemail <dot> com
  6. --#############################################################################
  7. --PRAGMA foreign_keys = ON;
  8. -- The metadata table
  9. CREATE TABLE vector_metadata (
  10. 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
  11. stvds_register VARCHAR, -- The name of the table storing all space-time vector datasets in which this map is registered
  12. is_3d BOOLEAN, -- This is 1 if the vector map is 3d and 0 otherwise
  13. points INTEGER, -- The number of points
  14. lines INTEGER, -- The number of lines
  15. boundaries INTEGER, -- The number of boundaries
  16. centroids INTEGER, -- The number of centroids
  17. faces INTEGER, -- The number of faces
  18. kernels INTEGER, -- The number of kernels
  19. primitives INTEGER, -- All primitives accumulated (points, lines,boundaries,centroids,faces,kernels)
  20. nodes INTEGER, -- Number of nodes (topological information)
  21. areas INTEGER, -- The number of areas (topological information)
  22. islands INTEGER, -- The number of islands (topological information)
  23. holes INTEGER, -- The number of holes (topological information)
  24. volumes INTEGER, -- The number of volumes (topological information)
  25. PRIMARY KEY (id),
  26. FOREIGN KEY (id) REFERENCES vector_base (id) ON DELETE CASCADE
  27. );
  28. -- Create the views to access all columns for the absolute and relative time
  29. CREATE VIEW vector_view_abs_time AS SELECT
  30. A1.id, A1.mapset,
  31. A1.name, A1.layer, A1.temporal_type,
  32. A1.creation_time,
  33. -- Uncommented due to performance issues
  34. -- A1.modification_time, A1.revision,
  35. A1.creator,
  36. A2.start_time, A2.end_time, A2.timezone,
  37. A3.north, A3.south, A3.east, A3.west, A3.proj,
  38. A4.stvds_register, A4.is_3d, A4.points, A4.lines,
  39. A4.boundaries, A4.centroids, A4.faces, A4.kernels,
  40. A4.primitives, A4.nodes, A4.areas, A4.islands,
  41. A4.holes, A4.volumes
  42. FROM vector_base A1, vector_absolute_time A2,
  43. vector_spatial_extent A3, vector_metadata A4
  44. WHERE A1.id = A2.id AND A1.id = A3.id AND A1.id = A4.id;
  45. CREATE VIEW vector_view_rel_time AS SELECT
  46. A1.id, A1.mapset,
  47. A1.name, A1.layer, A1.temporal_type,
  48. A1.creation_time,
  49. -- Uncommented due to performance issues
  50. -- A1.modification_time, A1.revision,
  51. A1.creator,
  52. A2.start_time, A2.end_time,
  53. A3.north, A3.south, A3.east, A3.west, A3.proj,
  54. A4.stvds_register, A4.is_3d, A4.points, A4.lines,
  55. A4.boundaries, A4.centroids, A4.faces, A4.kernels,
  56. A4.primitives, A4.nodes, A4.areas, A4.islands,
  57. A4.holes, A4.volumes
  58. FROM vector_base A1, vector_relative_time A2,
  59. vector_spatial_extent A3, vector_metadata A4
  60. WHERE A1.id = A2.id AND A1.id = A3.id AND A1.id = A4.id;
  61. -- Create a trigger to update the modification time and revision number in case the metadata or timestanps have been updated
  62. -- Uncommented due to performance issues
  63. --CREATE TRIGGER update_vector_metadata AFTER UPDATE ON vector_metadata
  64. -- BEGIN
  65. -- UPDATE vector_base SET modification_time = datetime("NOW") WHERE id = old.id;
  66. -- UPDATE vector_base SET revision = (revision + 1) WHERE id = old.id;
  67. -- END;