浏览代码

Minor fixes in map registration logic.

git-svn-id: https://svn.osgeo.org/grass/grass/trunk@48293 15284696-431f-4ddb-bdfa-cd5b030d7da7
Soeren Gebbert 13 年之前
父节点
当前提交
ae4c16b58c

+ 3 - 9
lib/python/tgis_abstract_datasets.py

@@ -1,19 +1,13 @@
-"""!@package grass.script.tgis_map_datasets
+"""!@package grass.script.tgis_abstract_datasets
 
 
 @brief GRASS Python scripting module (temporal GIS functions)
 @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:
 Usage:
 
 
 @code
 @code
-from grass.script import tgis_map_datasets as grass
-
-raster_ds = grass.raster_database("soil")
-if raster_ds.is_in_db():
-    raster_ds.select()
-else:
-    raster_ds.load()
+from grass.script import tgis_abstract_datasets as grass
 
 
 ...
 ...
 @endcode
 @endcode

+ 3 - 0
lib/temporal/map_stds_register_table_template.sql

@@ -3,14 +3,15 @@
 -- which the GRASS_MAP map is registered
 -- which the GRASS_MAP map is registered
 --
 --
 -- This table is map specific and created for each GRASS_MAP map which 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 table name which must be unique.
+-- A uuid is used as unique identifier across mapsets.
 --
 --
 -- Author: Soeren Gebbert soerengebbert <at> googlemail <dot> com
 -- Author: Soeren Gebbert soerengebbert <at> googlemail <dot> com
 --#############################################################################
 --#############################################################################
 
 
 PRAGMA foreign_keys = ON;
 PRAGMA foreign_keys = ON;
 
 
+-- TABLE_NAME is a placeholder for specific table name (SQL compliant)
 -- MAP_ID is a placeholder for specific map id: name@mapset
 -- MAP_ID is a placeholder for specific map id: name@mapset
 -- GRASS_MAP is a placeholder for specific map type: raster, raster3d or vector
 -- 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
 -- STDS is a placeholder for specific space-time dataset type: strds, str3ds, stvds

+ 2 - 2
lib/temporal/raster_metadata_table.sql

@@ -11,8 +11,8 @@ PRAGMA foreign_keys = ON;
 -- The metadata table reflects most of the raster metadata available in grass
 -- The metadata table reflects most of the raster metadata available in grass
 
 
 CREATE TABLE  raster_metadata (
 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@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@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,
   datatype VARCHAR NOT NULL,
   cols INTEGER NOT NULL,
   cols INTEGER NOT NULL,
   rows INTEGER NOT NULL,
   rows INTEGER NOT NULL,

+ 2 - 2
lib/temporal/stvds_metadata_table.sql

@@ -19,7 +19,7 @@ CREATE TABLE  stvds_metadata (
 -- Create the views to access all columns for absolute or relative time
 -- Create the views to access all columns for absolute or relative time
 
 
 CREATE VIEW stvds_view_abs_time AS SELECT 
 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.creator, A1.semantic_type,  
             A1.creation_time, A1.modification_time,
             A1.creation_time, A1.modification_time,
             A1.revision, A2.start_time,
             A1.revision, A2.start_time,
@@ -33,7 +33,7 @@ CREATE VIEW stvds_view_abs_time AS SELECT
 	    A1.id = A3.id AND A1.id = A4.id;
 	    A1.id = A3.id AND A1.id = A4.id;
 
 
 CREATE VIEW stvds_view_rel_time AS SELECT 
 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.creator, A1.semantic_type,  
             A1.creation_time, A1.modification_time,
             A1.creation_time, A1.modification_time,
             A1.revision, 
             A1.revision, 

+ 4 - 4
lib/temporal/test.temporal.py

@@ -4,7 +4,7 @@ from grass.script.tgis_base import *
 from grass.script.tgis_temporal_extent import *
 from grass.script.tgis_temporal_extent import *
 from grass.script.tgis_spatial_extent import *
 from grass.script.tgis_spatial_extent import *
 from grass.script.tgis_metadata 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 *
 from grass.script.tgis_space_time_datasets import *
 import grass.script as grass
 import grass.script as grass
 ###############################################################################
 ###############################################################################
@@ -716,10 +716,10 @@ def test_str3ds_dataset():
         # We need to specify the name and the mapset as identifier
         # We need to specify the name and the mapset as identifier
         r3ds = raster3d_dataset(ident)
         r3ds = raster3d_dataset(ident)
 
 
-        # Load data from the raster map in the mapset
+        # Load data from the raster3d map in the mapset
         r3ds.load()
         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():      
         if r3ds.is_in_db():      
             r3ds.select()
             r3ds.select()
@@ -734,7 +734,7 @@ def test_str3ds_dataset():
                                 end_time= datetime(year=2000, month=i + 1, day=1))
                                 end_time= datetime(year=2000, month=i + 1, day=1))
         # Insert the map data into the SQL database
         # Insert the map data into the SQL database
         r3ds.insert()
         r3ds.insert()
-        # Register the map in the space time raster dataset
+        # Register the map in the space time raster3d dataset
         str3ds.register_map(r3ds)
         str3ds.register_map(r3ds)
         # Print self info
         # Print self info
         #r3ds.print_self()
         #r3ds.print_self()

+ 1 - 1
lib/temporal/vector_metadata_table.sql

@@ -10,7 +10,7 @@ PRAGMA foreign_keys = ON;
 -- The metadata table 
 -- The metadata table 
 
 
 CREATE TABLE  vector_metadata (
 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@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@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
   stvds_register VARCHAR, -- The name of the table storing all space-time vector datasets in which this map is registered
   PRIMARY KEY (id),
   PRIMARY KEY (id),
   FOREIGN KEY (id) REFERENCES  vector_base (id) ON DELETE CASCADE
   FOREIGN KEY (id) REFERENCES  vector_base (id) ON DELETE CASCADE

+ 45 - 37
temporal/tr.register/tr.register.py

@@ -88,55 +88,63 @@ def main():
             inc_unit = increment.split(" ")[1]
             inc_unit = increment.split(" ")[1]
         else:
         else:
             inc_value = float(increment)
             inc_value = float(increment)
-
+                    
     count = 0
     count = 0
     for mapname in maplist:
     for mapname in maplist:
         mapid = mapname + "@" + mapset
         mapid = mapname + "@" + mapset
         map = grass.raster_dataset(mapid)
         map = grass.raster_dataset(mapid)
-        map.load()
 
 
         # In case the map is already registered print a message and continue to the next map
         # In case the map is already registered print a message and continue to the next map
-
         
         
         # Put the map into the database
         # Put the map into the database
         if map.is_in_db() == False:
         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"
-
-                    start_time = datetime.datetime.fromtimestamp(time.mktime(time.strptime(start, time_format)))
-                    end_time = None
-
-                    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)
-                else:
-                    interval = float(start) + count * inc_value
-                    map.set_relative_time(interval)
             # Put map with time interval in the database
             # Put map with time interval in the database
             map.insert()
             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.")
+
+        # Set the time interval
+        if start:
+            grass.info("Set/overwrite 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"
+
+                start_time = datetime.datetime.fromtimestamp(time.mktime(time.strptime(start, time_format)))
+                end_time = None
+
+                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
         # Register map
         sp.register_map(map)
         sp.register_map(map)

+ 0 - 5
temporal/tr.unregister/tr.unregister.py

@@ -36,11 +36,6 @@
 #% multiple: yes
 #% multiple: yes
 #%end
 #%end
 
 
-
-import sys
-import os
-import getpass
-import subprocess
 import grass.script as grass
 import grass.script as grass
 ############################################################################
 ############################################################################