[GRASS-SVN] r48293 - in grass/trunk: lib/python lib/temporal temporal/tr.register temporal/tr.unregister

svn_grass at osgeo.org svn_grass at osgeo.org
Wed Sep 14 03:40:51 EDT 2011


Author: huhabla
Date: 2011-09-14 00:40:51 -0700 (Wed, 14 Sep 2011)
New Revision: 48293

Modified:
   grass/trunk/lib/python/tgis_abstract_datasets.py
   grass/trunk/lib/temporal/map_stds_register_table_template.sql
   grass/trunk/lib/temporal/raster_metadata_table.sql
   grass/trunk/lib/temporal/stvds_metadata_table.sql
   grass/trunk/lib/temporal/test.temporal.py
   grass/trunk/lib/temporal/vector_metadata_table.sql
   grass/trunk/temporal/tr.register/tr.register.py
   grass/trunk/temporal/tr.unregister/tr.unregister.py
Log:
Minor fixes in map registration logic.

Modified: grass/trunk/lib/python/tgis_abstract_datasets.py
===================================================================
--- grass/trunk/lib/python/tgis_abstract_datasets.py	2011-09-14 05:04:43 UTC (rev 48292)
+++ grass/trunk/lib/python/tgis_abstract_datasets.py	2011-09-14 07:40:51 UTC (rev 48293)
@@ -1,20 +1,14 @@
-"""!@package grass.script.tgis_map_datasets
+"""!@package grass.script.tgis_abstract_datasets
 
 @brief GRASS Python scripting module (temporal GIS functions)
 
-Temporal GIS related functions to be used in Python scripts.
+Temporal GIS related functions to be used in temporal GIS Python library package.
 
 Usage:
 
 @code
-from grass.script import tgis_map_datasets as grass
+from grass.script import tgis_abstract_datasets as grass
 
-raster_ds = grass.raster_database("soil")
-if raster_ds.is_in_db():
-    raster_ds.select()
-else:
-    raster_ds.load()
-
 ...
 @endcode
 

Modified: grass/trunk/lib/temporal/map_stds_register_table_template.sql
===================================================================
--- grass/trunk/lib/temporal/map_stds_register_table_template.sql	2011-09-14 05:04:43 UTC (rev 48292)
+++ grass/trunk/lib/temporal/map_stds_register_table_template.sql	2011-09-14 07:40:51 UTC (rev 48293)
@@ -3,14 +3,15 @@
 -- 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. TABLE_NAME is a placeholder for the dataset name.
+-- in a STDS. TABLE_NAME is a placeholder for the table name which must be unique.
+-- A uuid is used as unique identifier across mapsets.
 --
 -- Author: Soeren Gebbert soerengebbert <at> googlemail <dot> com
 --#############################################################################
 
 PRAGMA foreign_keys = ON;
 
--- TABLE_NAME is a placeholder for specific map name (SQL compliant): name_mapset
+-- TABLE_NAME is a placeholder for specific table name (SQL compliant)
 -- 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

Modified: grass/trunk/lib/temporal/raster_metadata_table.sql
===================================================================
--- grass/trunk/lib/temporal/raster_metadata_table.sql	2011-09-14 05:04:43 UTC (rev 48292)
+++ grass/trunk/lib/temporal/raster_metadata_table.sql	2011-09-14 07:40:51 UTC (rev 48293)
@@ -11,8 +11,8 @@
 -- The metadata table reflects most of the raster metadata available in grass
 
 CREATE TABLE  raster_metadata (
-  id VARCHAR NOT NULL,                  -- The id (PFK) is the unique identifier for all tables, it is based on name and mapset (name at mapset) and is used as primary foreign key
-  strds_register VARCHAR, -- The name of the table storing all space-time raster datasets in which this map is registered
+  id VARCHAR NOT NULL,               -- The id (PFK) is the unique identifier for all tables, it is based on name and mapset (name at mapset) and is used as primary foreign key
+  strds_register VARCHAR,            -- The name of the table storing all space-time raster datasets in which this map is registered
   datatype VARCHAR NOT NULL,
   cols INTEGER NOT NULL,
   rows INTEGER NOT NULL,

Modified: grass/trunk/lib/temporal/stvds_metadata_table.sql
===================================================================
--- grass/trunk/lib/temporal/stvds_metadata_table.sql	2011-09-14 05:04:43 UTC (rev 48292)
+++ grass/trunk/lib/temporal/stvds_metadata_table.sql	2011-09-14 07:40:51 UTC (rev 48293)
@@ -19,7 +19,7 @@
 -- Create the views to access all columns for absolute or relative time
 
 CREATE VIEW stvds_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,
@@ -33,7 +33,7 @@
 	    A1.id = A3.id AND A1.id = A4.id;
 
 CREATE VIEW stvds_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/test.temporal.py
===================================================================
--- grass/trunk/lib/temporal/test.temporal.py	2011-09-14 05:04:43 UTC (rev 48292)
+++ grass/trunk/lib/temporal/test.temporal.py	2011-09-14 07:40:51 UTC (rev 48293)
@@ -4,7 +4,7 @@
 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_abstract_datasets import *
 from grass.script.tgis_space_time_datasets import *
 import grass.script as grass
 ###############################################################################
@@ -716,10 +716,10 @@
         # We need to specify the name and the mapset as identifier
         r3ds = raster3d_dataset(ident)
 
-        # Load data from the raster map in the mapset
+        # Load data from the raster3d map in the mapset
         r3ds.load()
 
-        print "Is raster in db: ", r3ds.is_in_db()
+        print "Is raster3d in db: ", r3ds.is_in_db()
 
         if r3ds.is_in_db():      
             r3ds.select()
@@ -734,7 +734,7 @@
                                 end_time= datetime(year=2000, month=i + 1, day=1))
         # Insert the map data into the SQL database
         r3ds.insert()
-        # Register the map in the space time raster dataset
+        # Register the map in the space time raster3d dataset
         str3ds.register_map(r3ds)
         # Print self info
         #r3ds.print_self()

Modified: grass/trunk/lib/temporal/vector_metadata_table.sql
===================================================================
--- grass/trunk/lib/temporal/vector_metadata_table.sql	2011-09-14 05:04:43 UTC (rev 48292)
+++ grass/trunk/lib/temporal/vector_metadata_table.sql	2011-09-14 07:40:51 UTC (rev 48293)
@@ -10,7 +10,7 @@
 -- The metadata table 
 
 CREATE TABLE  vector_metadata (
-  id VARCHAR NOT NULL,                  -- The id (PFK) is the unique identifier for all tables, it is based on name and mapset (name at mapset) and is used as primary foreign key
+  id VARCHAR NOT NULL,    -- The id (PFK) is the unique identifier for all tables, it is based on name and mapset (name at mapset) and is used as primary foreign key
   stvds_register VARCHAR, -- The name of the table storing all space-time vector datasets in which this map is registered
   PRIMARY KEY (id),
   FOREIGN KEY (id) REFERENCES  vector_base (id) ON DELETE CASCADE

Modified: grass/trunk/temporal/tr.register/tr.register.py
===================================================================
--- grass/trunk/temporal/tr.register/tr.register.py	2011-09-14 05:04:43 UTC (rev 48292)
+++ grass/trunk/temporal/tr.register/tr.register.py	2011-09-14 07:40:51 UTC (rev 48293)
@@ -88,55 +88,63 @@
             inc_unit = increment.split(" ")[1]
         else:
             inc_value = float(increment)
-
+                    
     count = 0
     for mapname in maplist:
         mapid = mapname + "@" + mapset
         map = grass.raster_dataset(mapid)
-        map.load()
 
         # In case the map is already registered print a message and continue to the next map
-
         
         # Put the map into the database
         if map.is_in_db() == False:
+            map.load()
 
-            # Set the time interval
-            if start:
-                grass.info("Set time interval for map " + mapname)
-                if sp.is_time_absolute():
-                    
-                    if start.find(":") > 0:
-                        time_format = "%Y-%m-%d %H:%M:%S"
-                    else:
-                        time_format = "%Y-%m-%d"
+            # Put map with time interval in the database
+            map.insert()
+        else:
+            map.select()
+            
+        if map.get_temporal_type() != sp.get_temporal_type():
+            grass.fatal("Unable to register map. The map has a different temporal types.")
 
-                    start_time = datetime.datetime.fromtimestamp(time.mktime(time.strptime(start, time_format)))
-                    end_time = None
+        # Set the time interval
+        if start:
+            grass.info("Set/overwrite time interval for map " + mapname)
+            
+            if sp.is_time_absolute():
 
-                    if increment:
-                        if inc_unit.find("seconds") >= 0:
-                            tdelta = timedelta(seconds=inc_value)
-                        elif inc_unit.find("minutes") >= 0:
-                            tdelta = timedelta(minutes=inc_value)
-                        elif inc_unit.find("hours") >= 0:
-                            tdelta = timedelta(hours=inc_value)
-                        elif inc_unit.find("days") >= 0:
-                            tdelta = timedelta(days=inc_value)
-                        elif inc_unit.find("weeks") >= 0:
-                            tdelta = timedelta(weeks=inc_value)
-                        else:
-                            grass.fatal("Wrong increment format: " + increment)
+                if start.find(":") > 0:
+                    time_format = "%Y-%m-%d %H:%M:%S"
+                else:
+                    time_format = "%Y-%m-%d"
 
-                        start_time += count * tdelta
-                        end_time = start_time + tdelta
+                start_time = datetime.datetime.fromtimestamp(time.mktime(time.strptime(start, time_format)))
+                end_time = None
 
-                    map.set_absolute_time(start_time, end_time)
-                else:
-                    interval = float(start) + count * inc_value
-                    map.set_relative_time(interval)
-            # Put map with time interval in the database
-            map.insert()
+                if increment:
+                    if inc_unit.find("seconds") >= 0:
+                        tdelta = timedelta(seconds=inc_value)
+                    elif inc_unit.find("minutes") >= 0:
+                        tdelta = timedelta(minutes=inc_value)
+                    elif inc_unit.find("hours") >= 0:
+                        tdelta = timedelta(hours=inc_value)
+                    elif inc_unit.find("days") >= 0:
+                        tdelta = timedelta(days=inc_value)
+                    elif inc_unit.find("weeks") >= 0:
+                        tdelta = timedelta(weeks=inc_value)
+                    else:
+                        grass.fatal("Wrong increment format: " + increment)
+
+                    start_time += count * tdelta
+                    end_time = start_time + tdelta
+
+                map.set_absolute_time(start_time, end_time)
+                map.absolute_time.update()
+            else:
+                interval = float(start) + count * inc_value
+                map.set_relative_time(interval)
+                map.arelative_time.update()                            
             
         # Register map
         sp.register_map(map)

Modified: grass/trunk/temporal/tr.unregister/tr.unregister.py
===================================================================
--- grass/trunk/temporal/tr.unregister/tr.unregister.py	2011-09-14 05:04:43 UTC (rev 48292)
+++ grass/trunk/temporal/tr.unregister/tr.unregister.py	2011-09-14 07:40:51 UTC (rev 48293)
@@ -36,11 +36,6 @@
 #% multiple: yes
 #%end
 
-
-import sys
-import os
-import getpass
-import subprocess
 import grass.script as grass
 ############################################################################
 



More information about the grass-commit mailing list