[GRASS-SVN] r67860 - in grass/trunk: lib/python/temporal temporal/t.rast.list temporal/t.rast3d.list temporal/t.vect.list

svn_grass at osgeo.org svn_grass at osgeo.org
Wed Feb 17 02:08:38 PST 2016


Author: lucadelu
Date: 2016-02-17 02:08:38 -0800 (Wed, 17 Feb 2016)
New Revision: 67860

Modified:
   grass/trunk/lib/python/temporal/list_stds.py
   grass/trunk/temporal/t.rast.list/t.rast.list.py
   grass/trunk/temporal/t.rast3d.list/t.rast3d.list.py
   grass/trunk/temporal/t.vect.list/t.vect.list.py
Log:
temporal: add output file support for modules listing temporal information

Modified: grass/trunk/lib/python/temporal/list_stds.py
===================================================================
--- grass/trunk/lib/python/temporal/list_stds.py	2016-02-17 10:02:02 UTC (rev 67859)
+++ grass/trunk/lib/python/temporal/list_stds.py	2016-02-17 10:08:38 UTC (rev 67860)
@@ -114,7 +114,8 @@
 
 
 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 @@
         :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 @@
     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 @@
             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 @@
                 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 @@
                     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 @@
                         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 @@
                         else:
                             output += str(col)
                         count += 1
-
-                    print output
+                    if outpath:
+                        outfile.write('{st}\n'.format(st=output))
+                    else:
+                        print output
     if connected:
         dbif.close()
 

Modified: grass/trunk/temporal/t.rast.list/t.rast.list.py
===================================================================
--- grass/trunk/temporal/t.rast.list/t.rast.list.py	2016-02-17 10:02:02 UTC (rev 67859)
+++ grass/trunk/temporal/t.rast.list/t.rast.list.py	2016-02-17 10:08:38 UTC (rev 67860)
@@ -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 @@
     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()

Modified: grass/trunk/temporal/t.rast3d.list/t.rast3d.list.py
===================================================================
--- grass/trunk/temporal/t.rast3d.list/t.rast3d.list.py	2016-02-17 10:02:02 UTC (rev 67859)
+++ grass/trunk/temporal/t.rast3d.list/t.rast3d.list.py	2016-02-17 10:08:38 UTC (rev 67860)
@@ -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 @@
     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()

Modified: grass/trunk/temporal/t.vect.list/t.vect.list.py
===================================================================
--- grass/trunk/temporal/t.vect.list/t.vect.list.py	2016-02-17 10:02:02 UTC (rev 67859)
+++ grass/trunk/temporal/t.vect.list/t.vect.list.py	2016-02-17 10:08:38 UTC (rev 67860)
@@ -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 @@
     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()



More information about the grass-commit mailing list