浏览代码

temporal framework: Better error handling when enabling the temporal granularity algebra

git-svn-id: https://svn.osgeo.org/grass/grass/trunk@62704 15284696-431f-4ddb-bdfa-cd5b030d7da7
Soeren Gebbert 10 年之前
父节点
当前提交
3fef9610b9
共有 1 个文件被更改,包括 24 次插入12 次删除
  1. 24 12
      lib/python/temporal/temporal_algebra.py

+ 24 - 12
lib/python/temporal/temporal_algebra.py

@@ -694,7 +694,7 @@ class TemporalAlgebraParser(object):
              space time datasets in the expression to generate the map lists.
              space time datasets in the expression to generate the map lists.
              
              
              This function will analyze the expression to detect space time datasets
              This function will analyze the expression to detect space time datasets
-             and computes are common granularity  from all granularities.
+             and computes the common granularity  from all granularities.
           
           
              This granularity is then be used to generate the map lists. Hence, all
              This granularity is then be used to generate the map lists. Hence, all
              maps from all STDS will have equidistant temporal extents. The only meaningful
              maps from all STDS will have equidistant temporal extents. The only meaningful
@@ -706,15 +706,18 @@ class TemporalAlgebraParser(object):
                                     parse the expression, default is TemporalAlgebraLexer
                                     parse the expression, default is TemporalAlgebraLexer
              
              
              :return: True if successful, False otherwise
              :return: True if successful, False otherwise
-             
-             :TODO: Check for tmap and map functions in the expression to avoid
-                         problems with map names that are handled as STDS
+ 
         """
         """
         l = lexer
         l = lexer
         # Split the expression to ignore the left part
         # Split the expression to ignore the left part
         expressions = expression.split("=")[1:]
         expressions = expression.split("=")[1:]
         expression = " ".join(expressions)
         expression = " ".join(expressions)
-
+        
+        # Check if spatio-temporal operators are present in the expression
+        if "{" in expression or "}" in expression:
+            self.msgr.error(_("Spatio temporal operators are not supported in granularity algebra mode"))
+            return False
+            
         # detect all STDS
         # detect all STDS
         if l is None:
         if l is None:
             l = TemporalAlgebraLexer()
             l = TemporalAlgebraLexer()
@@ -748,6 +751,7 @@ class TemporalAlgebraParser(object):
             stds = open_old_stds(name,  stdstype,  dbif)
             stds = open_old_stds(name,  stdstype,  dbif)
             # We need valid temporal topology
             # We need valid temporal topology
             if stds.check_temporal_topology() is False:
             if stds.check_temporal_topology() is False:
+                self.msgr.error(_("All input space time datasets must have a valid temporal topology."))
                 return False
                 return False
 
 
             grans.append(stds.get_granularity())
             grans.append(stds.get_granularity())
@@ -755,6 +759,7 @@ class TemporalAlgebraParser(object):
         
         
         # Only one temporal type is allowed
         # Only one temporal type is allowed
         if len(ttypes) > 1:
         if len(ttypes) > 1:
+            self.msgr.error(_("All input space time datasets must have the same temporal type."))
             return False
             return False
             
             
         # Compute the common granularity
         # Compute the common granularity
@@ -767,7 +772,8 @@ class TemporalAlgebraParser(object):
         
         
         return True
         return True
 
 
-    def parse(self, expression, stdstype = 'strds', maptype = 'rast',  mapclass = RasterDataset, basename = None, overwrite=False):
+    def parse(self, expression, stdstype = 'strds', maptype = 'rast',  mapclass = RasterDataset, 
+                      basename = None, overwrite=False):
         self.lexer = TemporalAlgebraLexer()
         self.lexer = TemporalAlgebraLexer()
         self.lexer.build()
         self.lexer.build()
         self.parser = yacc.yacc(module=self, debug=self.debug)
         self.parser = yacc.yacc(module=self, debug=self.debug)
@@ -1264,7 +1270,8 @@ class TemporalAlgebraParser(object):
                     for boolean in relationmap.condition_value:
                     for boolean in relationmap.condition_value:
                         if isinstance(boolean, bool):
                         if isinstance(boolean, bool):
                             condition_value_list.append(boolean)
                             condition_value_list.append(boolean)
-                    print(str(relationmap.get_temporal_extent_as_tuple()) + str(boolean))
+                    if self.debug:
+                        print(str(relationmap.get_temporal_extent_as_tuple()) + str(boolean))
         if all(condition_value_list):
         if all(condition_value_list):
             resultbool = True
             resultbool = True
         else:
         else:
@@ -1306,9 +1313,11 @@ class TemporalAlgebraParser(object):
             condition_value_list.append(')')
             condition_value_list.append(')')
         # Convert conditional list to concatenated string and evaluate booleans.
         # Convert conditional list to concatenated string and evaluate booleans.
         condition_value_str = ''.join(map(str, condition_value_list))
         condition_value_str = ''.join(map(str, condition_value_list))
-        print(condition_value_str)
+        if self.debug:
+            print(condition_value_str)
         resultbool = eval(condition_value_str)
         resultbool = eval(condition_value_str)
-        print(resultbool)
+        if self.debug:
+            print(resultbool)
         # Add boolean value to result list.
         # Add boolean value to result list.
         map_i.condition_value = [resultbool]
         map_i.condition_value = [resultbool]
         
         
@@ -1524,10 +1533,12 @@ class TemporalAlgebraParser(object):
                                 map_i.set_relative_time(int(start), int(end), relunit)
                                 map_i.set_relative_time(int(start), int(end), relunit)
                             resultdict[map_i.get_id()] = map_i
                             resultdict[map_i.get_id()] = map_i
                 else:
                 else:
-                    print('Topologic relation: ' + topo.upper() + ' not found.')
+                    if self.debug:
+                        print('Topologic relation: ' + topo.upper() + ' not found.')
                     resultdict[map_i.get_id()] = map_i
                     resultdict[map_i.get_id()] = map_i
             if unchanged == True:
             if unchanged == True:
-                print('Leave temporal extend of result map: ' +  map_i.get_map_id() + ' unchanged.')
+                if self.debug:
+                    print('Leave temporal extend of result map: ' +  map_i.get_map_id() + ' unchanged.')
         
         
         resultlist = resultdict.values()
         resultlist = resultdict.values()
         # Sort list of maps chronological.
         # Sort list of maps chronological.
@@ -1861,7 +1872,8 @@ class TemporalAlgebraParser(object):
                 # Add all maps that fulfill the conditions to result list.
                 # Add all maps that fulfill the conditions to result list.
                 if resultbool[0]:
                 if resultbool[0]:
                     resultlist.append(map_i)
                     resultlist.append(map_i)
-                    print(map_i.get_map_id() + ' ' + str(map_i.condition_value))
+                    if self.debug:
+                        print(map_i.get_map_id() + ' ' + str(map_i.condition_value))
                 else:
                 else:
                     inverselist.append(map_i)
                     inverselist.append(map_i)
         if inverse:
         if inverse: