stvds_metadata_table.sql 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081
  1. --#############################################################################
  2. -- This SQL script generates the space time vector dataset metadata table,
  3. -- view and trigger
  4. --
  5. -- Author: Soeren Gebbert soerengebbert <at> googlemail <dot> com
  6. --#############################################################################
  7. --PRAGMA foreign_keys = ON;
  8. CREATE TABLE stvds_metadata (
  9. id VARCHAR NOT NULL, -- Name of the space-time vector dataset, this is the primary foreign key
  10. vector_register VARCHAR,-- The id of the table in which the vector maps are registered for this dataset
  11. number_of_maps INTEGER, -- The number of registered vector maps
  12. title VARCHAR, -- Title of the space-time vector dataset
  13. description VARCHAR, -- Detailed description of the space-time vector dataset
  14. command VARCHAR, -- The command that was used to create the space time vector dataset
  15. points INTEGER, -- The number of points accumulated from all registered maps
  16. lines INTEGER, -- The number of lines accumulated from all registered maps
  17. boundaries INTEGER, -- The number of boundaries accumulated from all registered maps
  18. centroids INTEGER, -- The number of centroids accumulated from all registered maps
  19. faces INTEGER, -- The number of faces accumulated from all registered maps
  20. kernels INTEGER, -- The number of kernels accumulated from all registered maps
  21. primitives INTEGER, -- All primitives accumulated (points, lines,boundaries,centroids,faces,kernels)
  22. nodes INTEGER, -- Number of nodes accumulated from all registered maps (topological information)
  23. areas INTEGER, -- The number of areas accumulated from all registered maps (topological information)
  24. islands INTEGER, -- The number of islands accumulated from all registered maps (topological information)
  25. holes INTEGER, -- The number of holes accumulated from all registered maps (topological information)
  26. volumes INTEGER, -- The number of volumes accumulated from all registered maps (topological information)
  27. PRIMARY KEY (id),
  28. FOREIGN KEY (id) REFERENCES stvds_base (id) ON DELETE CASCADE
  29. );
  30. -- Create the views to access all columns for absolute or relative time
  31. CREATE VIEW stvds_view_abs_time AS SELECT
  32. A1.id, A1.name, A1.mapset, A1.temporal_type,
  33. A1.semantic_type,
  34. A1.creation_time,
  35. -- Uncommented due to performance issues
  36. -- A1.modification_time, A1.revision,
  37. A1.creator,
  38. A2.start_time, A2.end_time, A2.timezone,
  39. A2.granularity,
  40. A3.north, A3.south, A3.east, A3.west, A3.proj,
  41. A4.vector_register,
  42. A4.number_of_maps,
  43. A4.title, A4.description, A4.command, A4.points, A4.lines,
  44. A4.boundaries, A4.centroids, A4.faces, A4.kernels,
  45. A4.primitives, A4.nodes, A4.areas, A4.islands,
  46. A4.holes, A4.volumes
  47. FROM stvds_base A1, stvds_absolute_time A2,
  48. stvds_spatial_extent A3, stvds_metadata A4 WHERE A1.id = A2.id AND
  49. A1.id = A3.id AND A1.id = A4.id;
  50. CREATE VIEW stvds_view_rel_time AS SELECT
  51. A1.id, A1.name, A1.mapset, A1.temporal_type,
  52. A1.semantic_type,
  53. A1.creation_time,
  54. -- Uncommented due to performance issues
  55. -- A1.modification_time, A1.revision,
  56. A1.creator,
  57. A2.start_time, A2.end_time, A2.granularity,
  58. A3.north, A3.south, A3.east, A3.west, A3.proj,
  59. A4.vector_register,
  60. A4.number_of_maps,
  61. A4.title, A4.description, A4.command, A4.points, A4.lines,
  62. A4.boundaries, A4.centroids, A4.faces, A4.kernels,
  63. A4.primitives, A4.nodes, A4.areas, A4.islands,
  64. A4.holes, A4.volumes
  65. FROM stvds_base A1, stvds_relative_time A2,
  66. stvds_spatial_extent A3, stvds_metadata A4 WHERE A1.id = A2.id AND
  67. A1.id = A3.id AND A1.id = A4.id;
  68. -- Create a trigger to update the modification time and revision number in case the metadata or timestanps have been updated
  69. -- Uncommented due to performance issues
  70. --CREATE TRIGGER update_stvds_metadata AFTER UPDATE ON stvds_metadata
  71. -- BEGIN
  72. -- UPDATE stvds_base SET modification_time = datetime("NOW") WHERE id = old.id;
  73. -- UPDATE stvds_base SET revision = (revision + 1) WHERE id = old.id;
  74. -- END;