Przeglądaj źródła

More temporal extent setting tests

git-svn-id: https://svn.osgeo.org/grass/grass/trunk@57457 15284696-431f-4ddb-bdfa-cd5b030d7da7
Soeren Gebbert 11 lat temu
rodzic
commit
2de50e87b9

+ 22 - 12
lib/python/temporal/abstract_map_dataset.py

@@ -507,10 +507,10 @@ class AbstractMapDataset(AbstractDataset):
 
 
         self.write_timestamp_to_grass()
         self.write_timestamp_to_grass()
 
 
-    def set_temporal_extent(self, temporal_extent):
+    def set_temporal_extent(self, extent):
         """!Convenient method to set the temporal extent from a temporal extent object
         """!Convenient method to set the temporal extent from a temporal extent object
 
 
-           @param temporal_extent The temporal axtent that should be set for this object
+           @param temporal_extent The temporal extent that should be set for this object
 
 
            @code
            @code
            >>> import datetime
            >>> import datetime
@@ -527,21 +527,31 @@ class AbstractMapDataset(AbstractDataset):
            >>> print map.get_temporal_extent_as_tuple()
            >>> print map.get_temporal_extent_as_tuple()
            (datetime.datetime(2000, 1, 1, 0, 0), datetime.datetime(2001, 1, 1, 0, 0))
            (datetime.datetime(2000, 1, 1, 0, 0), datetime.datetime(2001, 1, 1, 0, 0))
 
 
+           >>> map1 = tgis.VectorDataset("A@P")
+           >>> check = map1.set_absolute_time(datetime.datetime(2000,5,5), datetime.datetime(2005,6,6), None)
+           >>> print map1.get_temporal_extent_as_tuple()
+           (datetime.datetime(2000, 5, 5, 0, 0), datetime.datetime(2005, 6, 6, 0, 0))
+           >>> map2 = tgis.RasterDataset("B@P")
+           >>> check = map2.set_absolute_time(datetime.datetime(1990,1,1), datetime.datetime(1999,8,1), None)
+           >>> print map2.get_temporal_extent_as_tuple()
+           (datetime.datetime(1990, 1, 1, 0, 0), datetime.datetime(1999, 8, 1, 0, 0))
+           >>> map2.set_temporal_extent(map1.get_temporal_extent())
+           >>> print map2.get_temporal_extent_as_tuple()
+           (datetime.datetime(2000, 5, 5, 0, 0), datetime.datetime(2005, 6, 6, 0, 0))
+
            @endcode
            @endcode
         """
         """
-
-
-        if issubclass(type(temporal_extent), RelativeTemporalExtent):
-            start = temporal_extent.get_start_time()
-            end = temporal_extent.get_end_time()
-            unit = temporal_extent.get_unit()
+        if issubclass(type(extent), RelativeTemporalExtent):
+            start = extent.get_start_time()
+            end = extent.get_end_time()
+            unit = extent.get_unit()
 
 
             self.set_relative_time(start, end, unit)
             self.set_relative_time(start, end, unit)
 
 
-        elif issubclass(type(temporal_extent), AbsoluteTemporalExtent):
-            start = temporal_extent.get_start_time()
-            end = temporal_extent.get_end_time()
-            tz = temporal_extent.get_timezone()
+        elif issubclass(type(extent), AbsoluteTemporalExtent):
+            start = extent.get_start_time()
+            end = extent.get_end_time()
+            tz = extent.get_timezone()
 
 
             self.set_absolute_time(start, end, tz)
             self.set_absolute_time(start, end, tz)
 
 

+ 38 - 38
lib/python/temporal/core.py

@@ -20,7 +20,7 @@ Usage:
 >>> # Execute a SQL statement
 >>> # Execute a SQL statement
 >>> dbif.execute_transaction("SELECT datetime(0, 'unixepoch', 'localtime');")
 >>> dbif.execute_transaction("SELECT datetime(0, 'unixepoch', 'localtime');")
 >>> # Mogrify an SQL statement
 >>> # Mogrify an SQL statement
->>> dbif.mogrify_sql_statement(["SELECT name from raster_base where name = ?", 
+>>> dbif.mogrify_sql_statement(["SELECT name from raster_base where name = ?",
 ... ("precipitation",)])
 ... ("precipitation",)])
 "SELECT name from raster_base where name = 'precipitation'"
 "SELECT name from raster_base where name = 'precipitation'"
 >>> dbif.close()
 >>> dbif.close()
@@ -97,7 +97,7 @@ def get_temporal_dbmi_init_string():
 
 
 ###############################################################################
 ###############################################################################
 
 
-# This variable specifies if the ctypes interface to the grass 
+# This variable specifies if the ctypes interface to the grass
 # libraries should be used to read map specific data. If set to False
 # libraries should be used to read map specific data. If set to False
 # the grass scripting library will be used to get map informations.
 # the grass scripting library will be used to get map informations.
 # The advantage of the ctypes inteface is speed, the disadvantage is that
 # The advantage of the ctypes inteface is speed, the disadvantage is that
@@ -107,7 +107,7 @@ use_ctypes_map_access = True
 
 
 def set_use_ctypes_map_access(use_ctype = True):
 def set_use_ctypes_map_access(use_ctype = True):
     """!Define the map access method for the temporal GIS library
     """!Define the map access method for the temporal GIS library
-    
+
        Using ctypes to read map metadata is much faster
        Using ctypes to read map metadata is much faster
        then using the grass.script interface that calls grass modules.
        then using the grass.script interface that calls grass modules.
        The disadvantage is that GRASS C-library function will call
        The disadvantage is that GRASS C-library function will call
@@ -138,21 +138,21 @@ def get_sql_template_path():
 
 
 def init():
 def init():
     """!This function set the correct database backend from the environmental variables
     """!This function set the correct database backend from the environmental variables
-       and creates the grass location database structure for raster, 
-       vector and raster3d maps as well as for the space-time datasets strds, 
+       and creates the grass location database structure for raster,
+       vector and raster3d maps as well as for the space-time datasets strds,
        str3ds and stvds in case it not exists.
        str3ds and stvds in case it not exists.
 
 
-        ATTENTION: This functions must be called before any spatio-temporal processing 
+        ATTENTION: This functions must be called before any spatio-temporal processing
                    can be started
                    can be started
     """
     """
     # We need to set the correct database backend from the environment variables
     # We need to set the correct database backend from the environment variables
     global tgis_backed
     global tgis_backed
     global has_command_column
     global has_command_column
-    
+
 
 
     core.run_command("t.connect", flags="c")
     core.run_command("t.connect", flags="c")
     kv = core.parse_command("t.connect", flags="pg")
     kv = core.parse_command("t.connect", flags="pg")
-    
+
     if "driver" in kv:
     if "driver" in kv:
         if kv["driver"] == "sqlite":
         if kv["driver"] == "sqlite":
             tgis_backed = kv["driver"]
             tgis_backed = kv["driver"]
@@ -177,7 +177,7 @@ def init():
     else:
     else:
         # Set the default sqlite3 connection in case nothing was defined
         # Set the default sqlite3 connection in case nothing was defined
         core.run_command("t.connect", flags="d")
         core.run_command("t.connect", flags="d")
-            
+
     database = get_temporal_dbmi_init_string()
     database = get_temporal_dbmi_init_string()
 
 
     db_exists = False
     db_exists = False
@@ -191,11 +191,11 @@ def init():
             cursor = connection.cursor()
             cursor = connection.cursor()
             # Check for raster_base table
             # Check for raster_base table
             cursor.execute("SELECT name FROM sqlite_master WHERE type='table' AND name='raster_base';")
             cursor.execute("SELECT name FROM sqlite_master WHERE type='table' AND name='raster_base';")
-            
+
             name = cursor.fetchone()[0]
             name = cursor.fetchone()[0]
             if name == "raster_base":
             if name == "raster_base":
                 db_exists = True
                 db_exists = True
-                
+
                 # Try to add the command column to the space time dataset metadata tables
                 # Try to add the command column to the space time dataset metadata tables
                 try:
                 try:
                     cursor.execute('ALTER TABLE strds_metadata ADD COLUMN command VARCHAR;')
                     cursor.execute('ALTER TABLE strds_metadata ADD COLUMN command VARCHAR;')
@@ -209,10 +209,10 @@ def init():
                     cursor.execute('ALTER TABLE stvds_metadata ADD COLUMN command VARCHAR;')
                     cursor.execute('ALTER TABLE stvds_metadata ADD COLUMN command VARCHAR;')
                 except:
                 except:
                     pass
                     pass
-                
+
             connection.commit()
             connection.commit()
             cursor.close()
             cursor.close()
-            
+
     elif tgis_backed == "pg":
     elif tgis_backed == "pg":
         # Connect to database
         # Connect to database
         connection = dbmi.connect(database)
         connection = dbmi.connect(database)
@@ -221,7 +221,7 @@ def init():
         cursor.execute("SELECT EXISTS(SELECT * FROM information_schema.tables "
         cursor.execute("SELECT EXISTS(SELECT * FROM information_schema.tables "
                        "WHERE table_name=%s)", ('raster_base',))
                        "WHERE table_name=%s)", ('raster_base',))
         db_exists = cursor.fetchone()[0]
         db_exists = cursor.fetchone()[0]
-    
+
         if db_exists:
         if db_exists:
             # Try to add the command column to the space time dataset metadata tables
             # Try to add the command column to the space time dataset metadata tables
             try:
             try:
@@ -236,7 +236,7 @@ def init():
                 cursor.execute('ALTER TABLE stvds_metadata ADD COLUMN command VARCHAR;')
                 cursor.execute('ALTER TABLE stvds_metadata ADD COLUMN command VARCHAR;')
             except:
             except:
                 pass
                 pass
-        
+
         connection.commit()
         connection.commit()
         cursor.close()
         cursor.close()
 
 
@@ -289,12 +289,12 @@ def init():
 
 
 
 
     if tgis_backed == "sqlite":
     if tgis_backed == "sqlite":
-        
+
         # We need to create the sqlite3 database path if it does not exists
         # We need to create the sqlite3 database path if it does not exists
         tgis_dir = os.path.dirname(database)
         tgis_dir = os.path.dirname(database)
         if not os.path.exists(tgis_dir):
         if not os.path.exists(tgis_dir):
             os.makedirs(tgis_dir)
             os.makedirs(tgis_dir)
-            
+
         # Connect to database
         # Connect to database
         connection = dbmi.connect(database)
         connection = dbmi.connect(database)
         cursor = connection.cursor()
         cursor = connection.cursor()
@@ -370,12 +370,12 @@ class SQLDatabaseInterfaceConnection():
             self.dbmi = sqlite3
             self.dbmi = sqlite3
         else:
         else:
             self.dbmi = psycopg2
             self.dbmi = psycopg2
-            
+
     def rollback(self):
     def rollback(self):
         """
         """
-            Roll back the last transaction. This must be called 
+            Roll back the last transaction. This must be called
             in case a new query should be performed after a db error.
             in case a new query should be performed after a db error.
-            
+
             This is only relevant for postgresql database.
             This is only relevant for postgresql database.
         """
         """
         if self.dbmi.__name__ == "psycopg2":
         if self.dbmi.__name__ == "psycopg2":
@@ -390,7 +390,7 @@ class SQLDatabaseInterfaceConnection():
         init = get_temporal_dbmi_init_string()
         init = get_temporal_dbmi_init_string()
         #print "Connect to",  self.database
         #print "Connect to",  self.database
         if self.dbmi.__name__ == "sqlite3":
         if self.dbmi.__name__ == "sqlite3":
-            self.connection = self.dbmi.connect(init, 
+            self.connection = self.dbmi.connect(init,
                     detect_types = self.dbmi.PARSE_DECLTYPES | self.dbmi.PARSE_COLNAMES)
                     detect_types = self.dbmi.PARSE_DECLTYPES | self.dbmi.PARSE_COLNAMES)
             self.connection.row_factory = self.dbmi.Row
             self.connection.row_factory = self.dbmi.Row
             self.connection.isolation_level = None
             self.connection.isolation_level = None
@@ -413,27 +413,27 @@ class SQLDatabaseInterfaceConnection():
 
 
     def mogrify_sql_statement(self, content):
     def mogrify_sql_statement(self, content):
         """!Return the SQL statement and arguments as executable SQL string
         """!Return the SQL statement and arguments as executable SQL string
-        
-           @param content The content as tuple with two entries, the first 
+
+           @param content The content as tuple with two entries, the first
                            entry is the SQL statement with DBMI specific
                            entry is the SQL statement with DBMI specific
                            place holder (?), the second entry is the argument
                            place holder (?), the second entry is the argument
                            list that should substitue the place holder.
                            list that should substitue the place holder.
-            
+
            Usage:
            Usage:
-           
+
            @code
            @code
-           
+
            >>> init()
            >>> init()
            >>> dbif = SQLDatabaseInterfaceConnection()
            >>> dbif = SQLDatabaseInterfaceConnection()
            >>> dbif.mogrify_sql_statement(["SELECT ctime FROM raster_base WHERE id = ?",
            >>> dbif.mogrify_sql_statement(["SELECT ctime FROM raster_base WHERE id = ?",
            ... ["soil@PERMANENT",]])
            ... ["soil@PERMANENT",]])
            "SELECT ctime FROM raster_base WHERE id = 'soil@PERMANENT'"
            "SELECT ctime FROM raster_base WHERE id = 'soil@PERMANENT'"
-           
+
            @endcode
            @endcode
         """
         """
         sql = content[0]
         sql = content[0]
         args = content[1]
         args = content[1]
-        
+
         if self.dbmi.__name__ == "psycopg2":
         if self.dbmi.__name__ == "psycopg2":
             if len(args) == 0:
             if len(args) == 0:
                 return sql
                 return sql
@@ -471,7 +471,7 @@ class SQLDatabaseInterfaceConnection():
                         break
                         break
 
 
                     if args[count] is None:
                     if args[count] is None:
-                        statement = "%sNULL%s" % (statement[0:pos], 
+                        statement = "%sNULL%s" % (statement[0:pos],
                                                   statement[pos + 1:])
                                                   statement[pos + 1:])
                     elif isinstance(args[count], (int, long)):
                     elif isinstance(args[count], (int, long)):
                         statement = "%s%d%s" % (statement[0:pos], args[count],
                         statement = "%s%d%s" % (statement[0:pos], args[count],
@@ -480,10 +480,10 @@ class SQLDatabaseInterfaceConnection():
                         statement = "%s%f%s" % (statement[0:pos], args[count],
                         statement = "%s%f%s" % (statement[0:pos], args[count],
                                                 statement[pos + 1:])
                                                 statement[pos + 1:])
                     else:
                     else:
-                        # Default is a string, this works for datetime 
+                        # Default is a string, this works for datetime
                         # objects too
                         # objects too
-                        statement = "%s\'%s\'%s" % (statement[0:pos], 
-                                                    str(args[count]), 
+                        statement = "%s\'%s\'%s" % (statement[0:pos],
+                                                    str(args[count]),
                                                     statement[pos + 1:])
                                                     statement[pos + 1:])
                     count += 1
                     count += 1
 
 
@@ -506,7 +506,7 @@ class SQLDatabaseInterfaceConnection():
         sql_script += "BEGIN TRANSACTION;\n"
         sql_script += "BEGIN TRANSACTION;\n"
         sql_script += statement
         sql_script += statement
         sql_script += "END TRANSACTION;"
         sql_script += "END TRANSACTION;"
-        
+
         try:
         try:
             if self.dbmi.__name__ == "sqlite3":
             if self.dbmi.__name__ == "sqlite3":
                 self.cursor.executescript(statement)
                 self.cursor.executescript(statement)
@@ -526,21 +526,21 @@ class SQLDatabaseInterfaceConnection():
 ###############################################################################
 ###############################################################################
 
 
 def init_dbif(dbif):
 def init_dbif(dbif):
-    """!This method checks if the database interface connection exists, 
+    """!This method checks if the database interface connection exists,
         if not a new one will be created, connected and True will be returned
         if not a new one will be created, connected and True will be returned
 
 
         Usage code sample:
         Usage code sample:
         @code
         @code
-        
+
         dbif, connect = tgis.init_dbif(None)
         dbif, connect = tgis.init_dbif(None)
-        
+
         sql = dbif.mogrify_sql_statement(["SELECT * FROM raster_base WHERE ? = ?"],
         sql = dbif.mogrify_sql_statement(["SELECT * FROM raster_base WHERE ? = ?"],
                                                ["id", "soil@PERMANENT"])
                                                ["id", "soil@PERMANENT"])
         dbif.execute_transaction(sql)
         dbif.execute_transaction(sql)
-        
+
         if connect:
         if connect:
             dbif.close()
             dbif.close()
-        
+
         @endcode
         @endcode
     """
     """
     if dbif is None:
     if dbif is None: