[GRASS-SVN] r48287 - grass/trunk/lib/temporal

svn_grass at osgeo.org svn_grass at osgeo.org
Tue Sep 13 20:58:07 EDT 2011


Author: huhabla
Date: 2011-09-13 17:58:07 -0700 (Tue, 13 Sep 2011)
New Revision: 48287

Added:
   grass/trunk/lib/temporal/stds_vector_register_trigger_template.sql
Modified:
   grass/trunk/lib/temporal/map_stds_register_table_template.sql
   grass/trunk/lib/temporal/str3ds_metadata_table.sql
   grass/trunk/lib/temporal/strds_metadata_table.sql
   grass/trunk/lib/temporal/stvds_metadata_table.sql
   grass/trunk/lib/temporal/test.temporal.py
Log:
Minor SQL fixes and improved table name handling.


Modified: grass/trunk/lib/temporal/map_stds_register_table_template.sql
===================================================================
--- grass/trunk/lib/temporal/map_stds_register_table_template.sql	2011-09-13 22:22:28 UTC (rev 48286)
+++ grass/trunk/lib/temporal/map_stds_register_table_template.sql	2011-09-14 00:58:07 UTC (rev 48287)
@@ -3,32 +3,32 @@
 -- which the GRASS_MAP map is registered
 --
 -- This table is map specific and created for each GRASS_MAP map which is registered 
--- in a STDS. MAP_NAME is a placeholder for the dataset name.
+-- in a STDS. TABLE_NAME is a placeholder for the dataset name.
 --
 -- Author: Soeren Gebbert soerengebbert <at> googlemail <dot> com
 --#############################################################################
 
 PRAGMA foreign_keys = ON;
 
--- MAP_NAME is a placeholder for specific map name (SQL compliant): name_mapset
+-- TABLE_NAME is a placeholder for specific map name (SQL compliant): name_mapset
 -- MAP_ID is a placeholder for specific map id: name at mapset
 -- GRASS_MAP is a placeholder for specific map type: raster, raster3d or vector
 -- STDS is a placeholder for specific space-time dataset type: strds, str3ds, stvds
 
 -- This table stores the names of the space-time datasets in which this map is registered 
-CREATE TABLE  MAP_NAME_STDS_register (
+CREATE TABLE  TABLE_NAME_STDS_register (
   id VARCHAR NOT NULL, -- This column is a primary foreign key storing the STDS names
   PRIMARY KEY (id),
   FOREIGN KEY (id) REFERENCES  STDS_base (id) ON DELETE CASCADE
 );
 
-CREATE TRIGGER MAP_NAME_STDS_register_insert AFTER INSERT ON MAP_NAME_STDS_register 
+CREATE TRIGGER TABLE_NAME_STDS_register_insert AFTER INSERT ON TABLE_NAME_STDS_register
   BEGIN
     UPDATE GRASS_MAP_base SET modification_time = datetime("NOW") WHERE GRASS_MAP_base.id = "MAP_ID";
     UPDATE GRASS_MAP_base SET revision = (revision + 1) WHERE GRASS_MAP_base.id = "MAP_ID";
   END;
 
-CREATE TRIGGER MAP_NAME_STDS_register_delete AFTER DELETE ON MAP_NAME_STDS_register 
+CREATE TRIGGER TABLE_NAME_STDS_register_delete AFTER DELETE ON TABLE_NAME_STDS_register
   BEGIN
     UPDATE GRASS_MAP_base SET modification_time = datetime("NOW") WHERE GRASS_MAP_base.id = "MAP_ID";
     UPDATE GRASS_MAP_base SET revision = (revision + 1) WHERE GRASS_MAP_base.id = "MAP_ID";

Added: grass/trunk/lib/temporal/stds_vector_register_trigger_template.sql
===================================================================
--- grass/trunk/lib/temporal/stds_vector_register_trigger_template.sql	                        (rev 0)
+++ grass/trunk/lib/temporal/stds_vector_register_trigger_template.sql	2011-09-14 00:58:07 UTC (rev 48287)
@@ -0,0 +1,6 @@
+--#############################################################################
+-- This SQL script is for now a placeholder, till the vector metadata
+-- concept is clear
+--
+-- Author: Soeren Gebbert soerengebbert <at> googlemail <dot> com
+--#############################################################################
\ No newline at end of file

Modified: grass/trunk/lib/temporal/str3ds_metadata_table.sql
===================================================================
--- grass/trunk/lib/temporal/str3ds_metadata_table.sql	2011-09-13 22:22:28 UTC (rev 48286)
+++ grass/trunk/lib/temporal/str3ds_metadata_table.sql	2011-09-14 00:58:07 UTC (rev 48287)
@@ -29,7 +29,7 @@
 -- Create the views to access all cols for absolute or relative time
 
 CREATE VIEW str3ds_view_abs_time AS SELECT 
-            A1.id, A1.temporal_type,
+            A1.id, A1.name, A1.mapset, A1.temporal_type,
             A1.creator, A1.semantic_type,  
             A1.creation_time, A1.modification_time,
             A1.revision, A2.start_time,
@@ -48,7 +48,7 @@
 	    A1.id = A3.id AND A1.id = A4.id;
 
 CREATE VIEW str3ds_view_rel_time AS SELECT 
-            A1.id, A1.temporal_type,
+            A1.id, A1.name, A1.mapset, A1.temporal_type,
             A1.creator, A1.semantic_type,  
             A1.creation_time, A1.modification_time,
             A1.revision, 

Modified: grass/trunk/lib/temporal/strds_metadata_table.sql
===================================================================
--- grass/trunk/lib/temporal/strds_metadata_table.sql	2011-09-13 22:22:28 UTC (rev 48286)
+++ grass/trunk/lib/temporal/strds_metadata_table.sql	2011-09-14 00:58:07 UTC (rev 48287)
@@ -27,7 +27,7 @@
 -- Create the views to access all cols for absolute or relative time
 
 CREATE VIEW strds_view_abs_time AS SELECT 
-            A1.id, A1.temporal_type,
+            A1.id, A1.name, A1.mapset, A1.temporal_type,
             A1.creator, A1.semantic_type,  
             A1.creation_time, A1.modification_time,
             A1.revision, A2.start_time,
@@ -45,7 +45,7 @@
 	    A1.id = A3.id AND A1.id = A4.id;
 
 CREATE VIEW strds_view_rel_time AS SELECT 
-            A1.id, A1.temporal_type,
+            A1.id, A1.name, A1.mapset, A1.temporal_type,
             A1.creator, A1.semantic_type,  
             A1.creation_time, A1.modification_time,
             A1.revision, 

Modified: grass/trunk/lib/temporal/stvds_metadata_table.sql
===================================================================
--- grass/trunk/lib/temporal/stvds_metadata_table.sql	2011-09-13 22:22:28 UTC (rev 48286)
+++ grass/trunk/lib/temporal/stvds_metadata_table.sql	2011-09-14 00:58:07 UTC (rev 48287)
@@ -61,7 +61,7 @@
   BEGIN
     DELETE FROM stvds_absolute_time WHERE id = old.id;
     DELETE FROM stvds_relative_time WHERE id = old.id;
-    DELETE FROM stvds_spatial_exntent WHERE id = old.id;
+    DELETE FROM stvds_spatial_extent WHERE id = old.id;
     DELETE FROM stvds_metadata WHERE id = old.id;
   END;
 

Modified: grass/trunk/lib/temporal/test.temporal.py
===================================================================
--- grass/trunk/lib/temporal/test.temporal.py	2011-09-13 22:22:28 UTC (rev 48286)
+++ grass/trunk/lib/temporal/test.temporal.py	2011-09-14 00:58:07 UTC (rev 48287)
@@ -1,7 +1,12 @@
 import os
-from grass.script.temporal import *
+from grass.script.tgis_core import *
+from grass.script.tgis_base import *
+from grass.script.tgis_temporal_extent import *
+from grass.script.tgis_spatial_extent import *
+from grass.script.tgis_metadata import *
+from grass.script.tgis_map_datasets import *
+from grass.script.tgis_space_time_datasets import *
 import grass.script as grass
-
 ###############################################################################
 
 def test_dict_sql_serializer():
@@ -629,7 +634,7 @@
     # Reread the data from the db
     strds.select()
     # Print self info
-    strds.print_self()
+    #strds.print_self()
 
     # Create a test maps
     for i in range(11):
@@ -666,11 +671,13 @@
         # Register the map in the space time raster dataset
         strds.register_map(rds)
         # Print self info
-        rds.print_self()
+        #rds.print_self()
     
     strds.select()
     # Print self info
     strds.print_self()
+    # Delete the dataset
+    strds.delete()
 
 
 def test_str3ds_dataset():
@@ -693,7 +700,7 @@
     # Reread the data from the db
     str3ds.select()
     # Print self info
-    str3ds.print_self()
+    #str3ds.print_self()
 
     # Create a test maps
     for i in range(11):
@@ -730,25 +737,96 @@
         # Register the map in the space time raster dataset
         str3ds.register_map(r3ds)
         # Print self info
-        r3ds.print_self()
+        #r3ds.print_self()
     
     str3ds.select()
     # Print self info
     str3ds.print_self()
+    # Delete the dataset
+    str3ds.delete()
 
 
-#test_dict_sql_serializer()
+def test_stvds_dataset():
+
+    name = "stvds_test_1"
+    mapset =  grass.gisenv()["MAPSET"]
+
+    print "Create a stvds object"
+
+    # We need to specify the name and the mapset as identifier
+    stvds = space_time_vector_dataset(ident = name + "@" + mapset)
+    # Check if in db
+    print "Is stvds in db: ", stvds.is_in_db()
+    # Create a new entry if not in db
+    if stvds.is_in_db() == False:
+        stvds.set_initial_values(temporal_type = "absolute", granularity="1 day",\
+        semantic_type="event", title="This is a test space time vector dataset", description="A space time vector dataset for testing")
+        stvds.insert()
+
+    # Reread the data from the db
+    stvds.select()
+    # Print self info
+    #stvds.print_self()
+
+    # Create a test maps
+    for i in range(11):
+        name = "test" + str(i)
+        mapset =  grass.gisenv()["MAPSET"]
+        ident = name + "@" + mapset
+
+        i = i + 1
+        grass.run_command("v.random", output=name, n=100, zmin=0, zmax=100, column="height" ,flags="z" , overwrite = True)
+
+
+        print "Create a vector object"
+
+        # We need to specify the name and the mapset as identifier
+        vds = vector_dataset(ident)
+
+        # Load data from the raster map in the mapset
+        vds.load()
+
+        print "Is vector in db: ", vds.is_in_db()
+
+        if vds.is_in_db():
+            vds.select()
+            vds.print_self()
+            # Remove the entry if it is in the db
+            vds.delete()
+            vds.reset(ident)
+            vds.load()
+
+        # Set the absolute valid time
+        vds.set_absolute_time(start_time= datetime(year=2000, month=i, day=1), \
+                                end_time= datetime(year=2000, month=i + 1, day=1))
+        # Insert the map data into the SQL database
+        vds.insert()
+        # Register the map in the space time raster dataset
+        stvds.register_map(vds)
+        # Print self info
+        #vds.print_self()
+
+    stvds.select()
+    # Print self info
+    stvds.print_self()
+    # Delete the dataset
+    stvds.delete()
+
+
+test_dict_sql_serializer()
 create_temporal_database()
-#test_dataset_identifer()
-#test_absolute_timestamp()
-#test_relative_timestamp()
-#test_spatial_extent()
-#test_map_metadata()
-#test_base_absolute_time_extent_metadata()
-#test_absolut_time_temporal_relations()
-#test_raster_dataset()
-#test_raster3d_dataset()
-#test_vector_dataset()
+test_dataset_identifer()
+test_absolute_timestamp()
+test_relative_timestamp()
+test_spatial_extent()
+test_map_metadata()
+test_base_absolute_time_extent_metadata()
+test_absolut_time_temporal_relations()
 
-#test_strds_dataset()
-test_str3ds_dataset()
\ No newline at end of file
+test_raster_dataset()
+test_raster3d_dataset()
+test_vector_dataset()
+
+test_strds_dataset()
+test_str3ds_dataset()
+test_stvds_dataset()
\ No newline at end of file



More information about the grass-commit mailing list