فهرست منبع

Added listing of stds register.

git-svn-id: https://svn.osgeo.org/grass/grass/trunk@49866 15284696-431f-4ddb-bdfa-cd5b030d7da7
Soeren Gebbert 13 سال پیش
والد
کامیت
c97aeba1a2

+ 18 - 63
lib/python/temporal/abstract_dataset.py

@@ -47,6 +47,24 @@ class abstract_dataset(object):
         """
         """
         raise IOError("This method must be implemented in the subclasses")
         raise IOError("This method must be implemented in the subclasses")
 
 
+    def print_info(self):
+        """Print information about this class in human readable style"""
+	raise IOError("This method must be implemented in the subclasses")
+        
+    def print_shell_info(self):
+        """Print information about this class in shell style"""
+	raise IOError("This method must be implemented in the subclasses")
+ 
+    def print_self(self):
+	"""Print the content of the internal structure to stdout"""
+	self.base.print_self()
+	if self.is_time_absolute():
+	    self.absolute_time.print_self()
+        if self.is_time_relative():
+	    self.relative_time.print_self()
+	self.spatial_extent.print_self()
+	self.metadata.print_self()
+
     def get_id(self):
     def get_id(self):
         return self.base.get_id()
         return self.base.get_id()
 
 
@@ -223,69 +241,6 @@ class abstract_dataset(object):
 
 
         if connect:
         if connect:
             dbif.close()
             dbif.close()
- 
-    def print_self(self):
-	"""Print the content of the internal structure to stdout"""
-	self.base.print_self()
-	if self.is_time_absolute():
-	    self.absolute_time.print_self()
-        if self.is_time_relative():
-	    self.relative_time.print_self()
-	self.spatial_extent.print_self()
-	self.metadata.print_self()
-
-    def print_info(self):
-        """Print information about this class in human readable style"""
-        
-        if self.get_type() == "raster":
-            #                1         2         3         4         5         6         7
-            #      0123456789012345678901234567890123456789012345678901234567890123456789012345678
-            print ""
-            print " +-------------------- Raster Dataset ----------------------------------------+"
-        if self.get_type() == "raster3d":
-            #                1         2         3         4         5         6         7
-            #      0123456789012345678901234567890123456789012345678901234567890123456789012345678
-            print ""
-            print " +-------------------- Raster3d Dataset --------------------------------------+"
-        if self.get_type() == "vector":
-            #                1         2         3         4         5         6         7
-            #      0123456789012345678901234567890123456789012345678901234567890123456789012345678
-            print ""
-            print " +-------------------- Vector Dataset ----------------------------------------+"
-        if self.get_type() == "strds":
-            #                1         2         3         4         5         6         7
-            #      0123456789012345678901234567890123456789012345678901234567890123456789012345678
-            print ""
-            print " +-------------------- Space Time Raster Dataset -----------------------------+"
-        if self.get_type() == "str3ds":
-            #                1         2         3         4         5         6         7
-            #      0123456789012345678901234567890123456789012345678901234567890123456789012345678
-            print ""
-            print " +-------------------- Space Time Raster3d Dataset ---------------------------+"
-        if self.get_type() == "stvds":
-            #                1         2         3         4         5         6         7
-            #      0123456789012345678901234567890123456789012345678901234567890123456789012345678
-            print ""
-            print " +-------------------- Space Time Vector Dataset -----------------------------+"
-        print " |                                                                            |"
-	self.base.print_info()
-	if self.is_time_absolute():
-	    self.absolute_time.print_info()
-        if self.is_time_relative():
-	    self.relative_time.print_info()
-	self.spatial_extent.print_info()
-	self.metadata.print_info()
-        print " +----------------------------------------------------------------------------+"
-
-    def print_shell_info(self):
-        """Print information about this class in shell style"""
-	self.base.print_shell_info()
-	if self.is_time_absolute():
-	    self.absolute_time.print_shell_info()
-        if self.is_time_relative():
-	    self.relative_time.print_shell_info()
-	self.spatial_extent.print_shell_info()
-	self.metadata.print_shell_info()
 
 
     def set_time_to_absolute(self):
     def set_time_to_absolute(self):
 	self.base.set_ttype("absolute")
 	self.base.set_ttype("absolute")

+ 60 - 0
lib/python/temporal/abstract_map_dataset.py

@@ -52,6 +52,66 @@ class abstract_map_dataset(abstract_dataset):
     def load(self):
     def load(self):
         """Load the content of this object from map files"""
         """Load the content of this object from map files"""
         raise IOError("This method must be implemented in the subclasses")
         raise IOError("This method must be implemented in the subclasses")
+ 
+    def print_info(self):
+        """Print information about this class in human readable style"""
+        
+        if self.get_type() == "raster":
+            #                1         2         3         4         5         6         7
+            #      0123456789012345678901234567890123456789012345678901234567890123456789012345678
+            print ""
+            print " +-------------------- Raster Dataset ----------------------------------------+"
+        if self.get_type() == "raster3d":
+            #                1         2         3         4         5         6         7
+            #      0123456789012345678901234567890123456789012345678901234567890123456789012345678
+            print ""
+            print " +-------------------- Raster3d Dataset --------------------------------------+"
+        if self.get_type() == "vector":
+            #                1         2         3         4         5         6         7
+            #      0123456789012345678901234567890123456789012345678901234567890123456789012345678
+            print ""
+            print " +-------------------- Vector Dataset ----------------------------------------+"
+        print " |                                                                            |"
+	self.base.print_info()
+	if self.is_time_absolute():
+	    self.absolute_time.print_info()
+        if self.is_time_relative():
+	    self.relative_time.print_info()
+	self.spatial_extent.print_info()
+	self.metadata.print_info()
+        datasets = self.get_registered_datasets()
+        count = 0
+        string = ""
+        for ds in datasets:
+            if count == 0:
+                string += ds["id"]
+            else:
+                string += ",%s" % ds["id"]
+            count += 1
+            if count > 2:
+                string += " | ............................ "
+        print " | Registered datasets ........ " + string
+        print " +----------------------------------------------------------------------------+"
+
+    def print_shell_info(self):
+        """Print information about this class in shell style"""
+	self.base.print_shell_info()
+	if self.is_time_absolute():
+	    self.absolute_time.print_shell_info()
+        if self.is_time_relative():
+	    self.relative_time.print_shell_info()
+	self.spatial_extent.print_shell_info()
+	self.metadata.print_shell_info()
+        datasets = self.get_registered_datasets()
+        count = 0
+        string = ""
+        for ds in datasets:
+            if count == 0:
+                string += ds["id"]
+            else:
+                string += ",%s" % ds["id"]
+            count += 1
+        print "registered_datasets=" + string
 
 
     def set_absolute_time(self, start_time, end_time=None, timezone=None):
     def set_absolute_time(self, start_time, end_time=None, timezone=None):
         """Set the absolute time interval with start time and end time
         """Set the absolute time interval with start time and end time

+ 130 - 36
lib/python/temporal/abstract_space_time_dataset.py

@@ -59,6 +59,54 @@ class abstract_space_time_dataset(abstract_dataset):
            @param name: The name of the register table
            @param name: The name of the register table
         """
         """
         raise IOError("This method must be implemented in the subclasses")
         raise IOError("This method must be implemented in the subclasses")
+ 
+    def print_self(self):
+	"""Print the content of the internal structure to stdout"""
+	self.base.print_self()
+	if self.is_time_absolute():
+	    self.absolute_time.print_self()
+        if self.is_time_relative():
+	    self.relative_time.print_self()
+	self.spatial_extent.print_self()
+	self.metadata.print_self()
+
+    def print_info(self):
+        """Print information about this class in human readable style"""
+        
+        if self.get_type() == "strds":
+            #                1         2         3         4         5         6         7
+            #      0123456789012345678901234567890123456789012345678901234567890123456789012345678
+            print ""
+            print " +-------------------- Space Time Raster Dataset -----------------------------+"
+        if self.get_type() == "str3ds":
+            #                1         2         3         4         5         6         7
+            #      0123456789012345678901234567890123456789012345678901234567890123456789012345678
+            print ""
+            print " +-------------------- Space Time Raster3d Dataset ---------------------------+"
+        if self.get_type() == "stvds":
+            #                1         2         3         4         5         6         7
+            #      0123456789012345678901234567890123456789012345678901234567890123456789012345678
+            print ""
+            print " +-------------------- Space Time Vector Dataset -----------------------------+"
+        print " |                                                                            |"
+	self.base.print_info()
+	if self.is_time_absolute():
+	    self.absolute_time.print_info()
+        if self.is_time_relative():
+	    self.relative_time.print_info()
+	self.spatial_extent.print_info()
+	self.metadata.print_info()
+        print " +----------------------------------------------------------------------------+"
+
+    def print_shell_info(self):
+        """Print information about this class in shell style"""
+	self.base.print_shell_info()
+	if self.is_time_absolute():
+	    self.absolute_time.print_shell_info()
+        if self.is_time_relative():
+	    self.relative_time.print_shell_info()
+	self.spatial_extent.print_shell_info()
+	self.metadata.print_shell_info()
 
 
     def set_initial_values(self, temporal_type, semantic_type, \
     def set_initial_values(self, temporal_type, semantic_type, \
                            title=None, description=None):
                            title=None, description=None):
@@ -348,7 +396,7 @@ class abstract_space_time_dataset(abstract_dataset):
            "gap" map objects (id==None). Each list entry is a list of map objects
            "gap" map objects (id==None). Each list entry is a list of map objects
            which are potentially located in temporal relation to the actual granule of the second space time dataset.
            which are potentially located in temporal relation to the actual granule of the second space time dataset.
 
 
-           Each entry in the object list is a dict. The actual sampler map and its temporal enxtent (the actual granule) and
+           Each entry in the object list is a dict. The actual sampler map and its temporal extent (the actual granule) and
            the list of samples are stored:
            the list of samples are stored:
 
 
            list = self.sample_by_dataset_topology(stds=sampler, method=["during","overlap","contain","equal"])    
            list = self.sample_by_dataset_topology(stds=sampler, method=["during","overlap","contain","equal"])    
@@ -359,7 +407,8 @@ class abstract_space_time_dataset(abstract_dataset):
                    map.select()
                    map.select()
                    map.print_info()
                    map.print_info()
 
 
-           A valid temporal topology (no overlapping or inclusion allowed) is needed to get correct results. 
+           A valid temporal topology (no overlapping or inclusion allowed) is needed to get correct results in case of gaps
+           in the sample dataset. 
     
     
            Gaps between maps are identified as unregistered maps with id==None.
            Gaps between maps are identified as unregistered maps with id==None.
 
 
@@ -458,40 +507,8 @@ class abstract_space_time_dataset(abstract_dataset):
         for granule in sample_maps:
         for granule in sample_maps:
             start, end = granule.get_valid_time()
             start, end = granule.get_valid_time()
 
 
-            where = "("
-
-            if use_start:
-                where += "(start_time >= '%s' and start_time < '%s') " % (start, end)
-
-            if use_during:
-                if use_start:
-                    where += " OR "
-                where += "((start_time > '%s' and end_time < '%s') OR " % (start, end)
-                where += "(start_time >= '%s' and end_time < '%s') OR " % (start, end)
-                where += "(start_time > '%s' and end_time <= '%s'))" % (start, end)
-
-            if use_overlap:
-                if use_start or use_during:
-                    where += " OR "
-
-                where += "((start_time < '%s' and end_time > '%s' and end_time < '%s') OR " % (start, start, end)
-                where += "(start_time < '%s' and start_time > '%s' and end_time > '%s'))" % (end, start, end)
-
-            if use_contain:
-                if use_start or use_during or use_overlap:
-                    where += " OR "
-
-                where += "((start_time < '%s' and end_time > '%s') OR " % (start, end)
-                where += "(start_time <= '%s' and end_time > '%s') OR " % (start, end)
-                where += "(start_time < '%s' and end_time >= '%s'))" % (start, end)
-
-            if use_equal:
-                if use_start or use_during or use_overlap or use_contain:
-                    where += " OR "
-
-                where += "(start_time = '%s' and end_time = '%s')" % (start, end)
-
-            where += ")"
+            where = create_temporal_relation_sql_where_statement(start, end, use_start, \
+                    use_during, use_overlap, use_contain, use_equal)  
 
 
             rows = self.get_registered_maps("id", where, "start_time", dbif)
             rows = self.get_registered_maps("id", where, "start_time", dbif)
 
 
@@ -1225,3 +1242,80 @@ class abstract_space_time_dataset(abstract_dataset):
 
 
         if connect == True:
         if connect == True:
             dbif.close()
             dbif.close()
+
+###############################################################################
+
+def create_temporal_relation_sql_where_statement(start, end, use_start=True, use_during=False, 
+                                        use_overlap=False, use_contain=False, use_equal=False):
+    """ Create a SQL WHERE statement for temporal relation selection of maps in space time datastes
+
+        @param start: The start time
+        @param end: The end time
+        @param use_start: Select maps of which the start time is located in the selection granule
+                         map    :        s
+                         granule:  s-----------------e
+
+                         map    :        s--------------------e
+                         granule:  s-----------------e
+
+                         map    :        s--------e
+                         granule:  s-----------------e
+
+        @param use_during: during: Select maps which are temporal during the selection granule
+                         map    :     s-----------e
+                         granule:  s-----------------e
+
+        @param use_overlap: Select maps which temporal overlap the selection granule
+                         map    :     s-----------e
+                         granule:        s-----------------e
+
+                         map    :     s-----------e
+                         granule:  s----------e
+
+        @param use_contain: Select maps which temporally contain the selection granule
+                         map    :  s-----------------e
+                         granule:     s-----------e
+
+        @param use_equal: Select maps which temporally equal to the selection granule
+                         map    :  s-----------e
+                         granule:  s-----------e
+    """
+
+    where = "("
+
+    if use_start:
+        where += "(start_time >= '%s' and start_time < '%s') " % (start, end)
+
+    if use_during:
+        if use_start:
+            where += " OR "
+        where += "((start_time > '%s' and end_time < '%s') OR " % (start, end)
+        where += "(start_time >= '%s' and end_time < '%s') OR " % (start, end)
+        where += "(start_time > '%s' and end_time <= '%s'))" % (start, end)
+
+    if use_overlap:
+        if use_start or use_during:
+            where += " OR "
+
+        where += "((start_time < '%s' and end_time > '%s' and end_time < '%s') OR " % (start, start, end)
+        where += "(start_time < '%s' and start_time > '%s' and end_time > '%s'))" % (end, start, end)
+
+    if use_contain:
+        if use_start or use_during or use_overlap:
+            where += " OR "
+
+        where += "((start_time < '%s' and end_time > '%s') OR " % (start, end)
+        where += "(start_time <= '%s' and end_time > '%s') OR " % (start, end)
+        where += "(start_time < '%s' and end_time >= '%s'))" % (start, end)
+
+    if use_equal:
+        if use_start or use_during or use_overlap or use_contain:
+            where += " OR "
+
+        where += "(start_time = '%s' and end_time = '%s')" % (start, end)
+
+    where += ")"
+
+    return where
+
+

+ 31 - 5
lib/python/temporal/aggregation.py

@@ -24,12 +24,39 @@ for details.
 
 
 from space_time_datasets import *
 from space_time_datasets import *
 
 
-def collect_map_names(sp, dbif, start, end):
+def collect_map_names(sp, dbif, start, end, sampling):
     
     
-    where = " start_time >= \'%s\' and start_time < \'%s\'" % (start, end)
+    use_start = False
+    use_during = False
+    use_overlap = False
+    use_contain = False
+    use_equal = False
+
+    # Inititalize the methods
+    if sampling:
+        for name in sampling.split(","):
+            if name == "start":
+                use_start = True
+            if name == "during":
+                use_during = True
+            if name == "overlap":
+                use_overlap = True
+            if name == "contain":
+                use_contain = True
+            if name == "equal":
+                use_equal = True
+    else:
+        use_start = True
 
 
-    print where
-    
+    if sp.get_map_time() != "interval":
+        use_start = True
+        use_during = False
+        use_overlap = False
+        use_contain = False
+        use_equal = False
+
+    where = create_temporal_relation_sql_where_statement(start, end, use_start, use_during, use_overlap, use_contain, use_equal)
+   
     rows = sp.get_registered_maps("id", where, "start_time", dbif)
     rows = sp.get_registered_maps("id", where, "start_time", dbif)
 
 
     if not rows:
     if not rows:
@@ -41,7 +68,6 @@ def collect_map_names(sp, dbif, start, end):
 
 
     return names    
     return names    
 
 
-
 def aggregate_raster_maps(dataset, mapset, inputs, base, start, end, count, method, register_null, dbif):
 def aggregate_raster_maps(dataset, mapset, inputs, base, start, end, count, method, register_null, dbif):
 
 
     core.verbose(_("Aggregate %s raster maps") %(len(inputs)))
     core.verbose(_("Aggregate %s raster maps") %(len(inputs)))

+ 13 - 6
lib/python/temporal/metadata.py

@@ -199,12 +199,13 @@ class raster_metadata(raster_metadata_base):
         """Print information about this class in human readable style"""
         """Print information about this class in human readable style"""
         print " +-------------------- Metadata information ----------------------------------+"
         print " +-------------------- Metadata information ----------------------------------+"
         #      0123456789012345678901234567890
         #      0123456789012345678901234567890
-        print " | STRDS register table ....... " + str(self.get_strds_register())
         raster_metadata_base.print_info(self)
         raster_metadata_base.print_info(self)
+        print " | STRDS register table ....... " + str(self.get_strds_register())
 
 
     def print_shell_info(self):
     def print_shell_info(self):
         """Print information about this class in shell style"""
         """Print information about this class in shell style"""
         raster_metadata_base.print_shell_info(self)
         raster_metadata_base.print_shell_info(self)
+        print "strds_register=" + str(self.get_strds_register())
 
 
 ###############################################################################
 ###############################################################################
 
 
@@ -258,17 +259,18 @@ class raster3d_metadata(raster_metadata_base):
         """Print information about this class in human readable style"""
         """Print information about this class in human readable style"""
         print " +-------------------- Metadata information ----------------------------------+"
         print " +-------------------- Metadata information ----------------------------------+"
         #      0123456789012345678901234567890
         #      0123456789012345678901234567890
-        print " | STR3DS register table ...... " + str(self.get_str3ds_register())
         raster_metadata_base.print_info(self)
         raster_metadata_base.print_info(self)
         #      0123456789012345678901234567890
         #      0123456789012345678901234567890
         print " | Number of depths:........... " + str(self.get_depths())
         print " | Number of depths:........... " + str(self.get_depths())
         print " | Top-Bottom resolution:...... " + str(self.get_tbres())
         print " | Top-Bottom resolution:...... " + str(self.get_tbres())
+        print " | STR3DS register table ...... " + str(self.get_str3ds_register())
 
 
     def print_shell_info(self):
     def print_shell_info(self):
         """Print information about this class in shell style"""
         """Print information about this class in shell style"""
-        raster_metadata_base.print_shell_info(self)
+        print "str3ds_register=" + str(self.get_str3ds_register())
         print "depths=" + str(self.get_depths())
         print "depths=" + str(self.get_depths())
         print "tbres=" + str(self.get_tbres())
         print "tbres=" + str(self.get_tbres())
+        raster_metadata_base.print_shell_info(self)
         
         
 ###############################################################################
 ###############################################################################
 
 
@@ -541,12 +543,13 @@ class strds_metadata(stds_raster_metadata_base):
         """Print information about this class in human readable style"""
         """Print information about this class in human readable style"""
         print " +-------------------- Metadata information ----------------------------------+"
         print " +-------------------- Metadata information ----------------------------------+"
         #      0123456789012345678901234567890
         #      0123456789012345678901234567890
-        print " | Raster register table:...... " + str(self.get_raster_register())
         stds_raster_metadata_base.print_info(self)
         stds_raster_metadata_base.print_info(self)
+        print " | Raster register table:...... " + str(self.get_raster_register())
 
 
     def print_shell_info(self):
     def print_shell_info(self):
         """Print information about this class in shell style"""
         """Print information about this class in shell style"""
         stds_raster_metadata_base.print_shell_info(self)
         stds_raster_metadata_base.print_shell_info(self)
+        print "raster_register=" + str(self.get_raster_register())
 
 
 ###############################################################################
 ###############################################################################
 
 
@@ -594,17 +597,18 @@ class str3ds_metadata(stds_raster_metadata_base):
         """Print information about this class in human readable style"""
         """Print information about this class in human readable style"""
         print " +-------------------- Metadata information ----------------------------------+"
         print " +-------------------- Metadata information ----------------------------------+"
         #      0123456789012345678901234567890
         #      0123456789012345678901234567890
-        print " | Raster3d register table:.... " + str(self.get_raster3d_register())
         stds_raster_metadata_base.print_info(self)
         stds_raster_metadata_base.print_info(self)
         #      0123456789012345678901234567890
         #      0123456789012345678901234567890
         print " | Top-bottom resolution min:.. " + str(self.get_ewres_min())
         print " | Top-bottom resolution min:.. " + str(self.get_ewres_min())
         print " | Top-bottom resolution max:.. " + str(self.get_ewres_max())
         print " | Top-bottom resolution max:.. " + str(self.get_ewres_max())
+        print " | Raster3d register table:.... " + str(self.get_raster3d_register())
 
 
     def print_shell_info(self):
     def print_shell_info(self):
         """Print information about this class in shell style"""
         """Print information about this class in shell style"""
         stds_raster_metadata_base.print_shell_info(self)
         stds_raster_metadata_base.print_shell_info(self)
         print "tbres_min=" + str(self.get_tbres_min())
         print "tbres_min=" + str(self.get_tbres_min())
         print "tbres_max=" + str(self.get_tbres_max())
         print "tbres_max=" + str(self.get_tbres_max())
+        print "raster3d_register=" + str(self.get_raster3d_register())
 
 
 ###############################################################################
 ###############################################################################
 
 
@@ -632,9 +636,12 @@ class stvds_metadata(stds_metadata_base):
         """Print information about this class in human readable style"""
         """Print information about this class in human readable style"""
         print " +-------------------- Metadata information ----------------------------------+"
         print " +-------------------- Metadata information ----------------------------------+"
         #      0123456789012345678901234567890
         #      0123456789012345678901234567890
-        print " | Vector register table:...... " + str(self.get_vector_register())
         stds_metadata_base.print_info(self)
         stds_metadata_base.print_info(self)
+        print " | Vector register table:...... " + str(self.get_vector_register())
 
 
     def print_shell_info(self):
     def print_shell_info(self):
         """Print information about this class in shell style"""
         """Print information about this class in shell style"""
         stds_metadata_base.print_shell_info(self)
         stds_metadata_base.print_shell_info(self)
+        print "vector_register=" + str(self.get_vector_register())
+
+

+ 2 - 0
lib/python/temporal/space_time_datasets_tools.py

@@ -676,6 +676,7 @@ def list_maps_of_stds(type, input, columns, order, where, separator, method, hea
                         
                         
                     print output
                     print output
 
 
+###############################################################################
 
 
 def sample_stds_by_stds_topology(intype, sampletype, input, sampler, header, separator, method):
 def sample_stds_by_stds_topology(intype, sampletype, input, sampler, header, separator, method):
     """ Sample the input space time dataset with a sample space time dataset and print the result to stdout
     """ Sample the input space time dataset with a sample space time dataset and print the result to stdout
@@ -773,3 +774,4 @@ def sample_stds_by_stds_topology(intype, sampletype, input, sampler, header, sep
             print string
             print string
 
 
     dbif.close()
     dbif.close()
+