Просмотр исходного кода

temporal: add output file support for modules listing temporal information

git-svn-id: https://svn.osgeo.org/grass/grass/trunk@67860 15284696-431f-4ddb-bdfa-cd5b030d7da7
Luca Delucchi 9 лет назад
Родитель
Сommit
aed6b57182

+ 26 - 7
lib/python/temporal/list_stds.py

@@ -114,7 +114,8 @@ def get_dataset_list(type, temporal_type, columns=None, where=None,
 
 
 def list_maps_of_stds(type, input, columns, order, where, separator,
-                      method, no_header=False, gran=None, dbif=None):
+                      method, no_header=False, gran=None, dbif=None,
+                      outpath=None):
     """ List the maps of a space time dataset using diffetent methods
 
         :param type: The type of the maps raster, raster3d or vector
@@ -143,6 +144,7 @@ def list_maps_of_stds(type, input, columns, order, where, separator,
         :param gran: The user defined granule to be used if method=gran is
                      set, in case gran=None the granule of the space time
                      dataset is used
+        :param outpath: Tha path to output file where save info
     """
 
     dbif, connected = init_dbif(dbif)
@@ -153,6 +155,9 @@ def list_maps_of_stds(type, input, columns, order, where, separator,
     if separator is None or separator == "":
         separator = "\t"
 
+    if outpath:
+        outfile = open(outpath, 'w')
+
     # This method expects a list of objects for gap detection
     if method == "delta" or method == "deltagaps" or method == "gran":
         if type == "stvds":
@@ -184,7 +189,10 @@ def list_maps_of_stds(type, input, columns, order, where, separator,
             string += "%s%s" % ("end_time", separator)
             string += "%s%s" % ("interval_length", separator)
             string += "%s" % ("distance_from_begin")
-            print string
+            if outpath:
+                outfile.write('{st}\n'.format(st=string))
+            else:
+                print string
 
         if maps and len(maps) > 0:
 
@@ -229,7 +237,10 @@ def list_maps_of_stds(type, input, columns, order, where, separator,
                 string += "%s%s" % (end, separator)
                 string += "%s%s" % (delta, separator)
                 string += "%s" % (delta_first)
-                print string
+                if outpath:
+                    outfile.write('{st}\n'.format(st=string))
+                else:
+                    print string
 
     else:
         # In comma separated mode only map ids are needed
@@ -248,7 +259,10 @@ def list_maps_of_stds(type, input, columns, order, where, separator,
                     else:
                         string += ",%s" % row["id"]
                     count += 1
-                print string
+                if outpath:
+                    outfile.write('{st}\n'.format(st=string))
+                else:
+                    print string
 
             elif method == "cols":
                 # Print the column names if requested
@@ -264,7 +278,10 @@ def list_maps_of_stds(type, input, columns, order, where, separator,
                         else:
                             output += str(key)
                         count += 1
-                    print output
+                    if outpath:
+                        outfile.write('{st}\n'.format(st=output))
+                    else:
+                        print output
 
                 for row in rows:
                     output = ""
@@ -275,8 +292,10 @@ def list_maps_of_stds(type, input, columns, order, where, separator,
                         else:
                             output += str(col)
                         count += 1
-
-                    print output
+                    if outpath:
+                        outfile.write('{st}\n'.format(st=output))
+                    else:
+                        print output
     if connected:
         dbif.close()
 

+ 7 - 2
temporal/t.rast.list/t.rast.list.py

@@ -75,6 +75,10 @@
 #% guisection: Formatting
 #%end
 
+#%option G_OPT_F_OUTPUT
+#% required: no
+#%end
+
 #%flag
 #% key: s
 #% description: Suppress printing of column names
@@ -98,12 +102,13 @@ def main():
     method = options["method"]
     granule = options["granule"]
     header = flags["s"]
+    output = options["output"]
 
     # Make sure the temporal database exists
     tgis.init()
 
-    tgis.list_maps_of_stds(
-        "strds", input, columns, order, where, separator, method, header, granule)
+    tgis.list_maps_of_stds("strds", input, columns, order, where, separator,
+                           method, header, granule, outpath=output)
 
 if __name__ == "__main__":
     options, flags = grass.parser()

+ 7 - 2
temporal/t.rast3d.list/t.rast3d.list.py

@@ -67,6 +67,10 @@
 #% guisection: Formatting
 #%end
 
+#%option G_OPT_F_OUTPUT
+#% required: no
+#%end
+
 #%flag
 #% key: s
 #% description: Suppress printing of column names
@@ -89,12 +93,13 @@ def main():
     separator = grass.separator(options["separator"])
     method = options["method"]
     header = flags["s"]
+    output = options["output"]
 
     # Make sure the temporal database exists
     tgis.init()
 
-    tgis.list_maps_of_stds(
-        "str3ds", input, columns, order, where, separator, method, header)
+    tgis.list_maps_of_stds("str3ds", input, columns, order, where, separator,
+                           method, header, outpath=output)
 
 if __name__ == "__main__":
     options, flags = grass.parser()

+ 7 - 2
temporal/t.vect.list/t.vect.list.py

@@ -67,6 +67,10 @@
 #% guisection: Formatting
 #%end
 
+#%option G_OPT_F_OUTPUT
+#% required: no
+#%end
+
 #%flag
 #% key: s
 #% description: Suppress printing of column names
@@ -89,12 +93,13 @@ def main():
     separator = grass.separator(options["separator"])
     method = options["method"]
     header = flags["s"]
+    output = options["output"]
 
     # Make sure the temporal database exists
     tgis.init()
 
-    tgis.list_maps_of_stds(
-        "stvds", input, columns, order, where, separator, method, header)
+    tgis.list_maps_of_stds("stvds", input, columns, order, where, separator,
+                           method, header, outpath=output)
 
 if __name__ == "__main__":
     options, flags = grass.parser()