[GRASS-SVN] r67880 - in grass/branches/releasebranch_7_0: lib/python/temporal temporal/t.list temporal/t.rast.list temporal/t.rast3d.list temporal/t.vect.list

svn_grass at osgeo.org svn_grass at osgeo.org
Thu Feb 18 03:19:25 PST 2016


Author: lucadelu
Date: 2016-02-18 03:19:25 -0800 (Thu, 18 Feb 2016)
New Revision: 67880

Modified:
   grass/branches/releasebranch_7_0/lib/python/temporal/list_stds.py
   grass/branches/releasebranch_7_0/temporal/t.list/t.list.py
   grass/branches/releasebranch_7_0/temporal/t.rast.list/t.rast.list.py
   grass/branches/releasebranch_7_0/temporal/t.rast3d.list/t.rast3d.list.py
   grass/branches/releasebranch_7_0/temporal/t.vect.list/t.vect.list.py
Log:
temporal: backported changes to support output parameter [#2319]

Modified: grass/branches/releasebranch_7_0/lib/python/temporal/list_stds.py
===================================================================
--- grass/branches/releasebranch_7_0/lib/python/temporal/list_stds.py	2016-02-18 11:14:10 UTC (rev 67879)
+++ grass/branches/releasebranch_7_0/lib/python/temporal/list_stds.py	2016-02-18 11:19:25 UTC (rev 67880)
@@ -10,9 +10,9 @@
     tgis.register_maps_in_space_time_dataset(type, name, maps)
 
 
-(C) 2012-2013 by the GRASS Development Team
+(C) 2012-2016 by the GRASS Development Team
 This program is free software under the GNU General Public
-License (>=v2). Read the file COPYING that comes with GRASS
+License (>=v2). Read the file COPYING that comes with GRASS GIS
 for details.
 
 :authors: Soeren Gebbert
@@ -51,7 +51,8 @@
             >>> tgis.init()
             >>> name = "list_stds_test"
             >>> sp = tgis.open_new_stds(name=name, type="strds",
-            ... temporaltype="absolute", title="title", descr="descr", semantic="mean", dbif=None, overwrite=True)
+            ... temporaltype="absolute", title="title", descr="descr",
+            ... semantic="mean", dbif=None, overwrite=True)
             >>> mapset = tgis.get_current_mapset()
             >>> stds_list = tgis.get_dataset_list("strds", "absolute", columns="name")
             >>> rows =  stds_list[mapset]
@@ -59,7 +60,8 @@
             ...     if row["name"] == name:
             ...         print True
             True
-            >>> stds_list = tgis.get_dataset_list("strds", "absolute", columns="name,mapset", where="mapset = '%s'"%(mapset))
+            >>> stds_list = tgis.get_dataset_list("strds", "absolute",
+            ... columns="name,mapset", where="mapset = '%s'"%(mapset))
             >>> rows =  stds_list[mapset]
             >>> for row in rows:
             ...     if row["name"] == name and row["mapset"] == mapset:
@@ -111,8 +113,9 @@
 
 
 def list_maps_of_stds(type, input, columns, order, where, separator,
-                      method, no_header=False, gran=None):
-    """ List the maps of a space time dataset using diffetent methods
+                      method, no_header=False, gran=None,
+                      outpath=None):
+    """ List the maps of a space time dataset using different methods
 
         :param type: The type of the maps raster, raster3d or vector
         :param input: Name of a space time raster dataset
@@ -131,14 +134,15 @@
                end time, relative length of intervals and the relative
                distance to the begin
             - "deltagaps" Same as "delta" with additional listing of gaps.
-              Gaps can be simply identified as the id is "None"
+               Gaps can be easily identified as the id is "None"
             - "gran" List map using the granularity of the space time dataset,
-              columns are identical to deltagaps
+               columns are identical to deltagaps
 
         :param no_header: Supress the printing of column names
         :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: The path to file where to save output
     """
 
     dbif, connected = init_dbif(None)
@@ -149,6 +153,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":
@@ -180,7 +187,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:
 
@@ -225,7 +235,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
@@ -244,7 +257,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
@@ -260,7 +276,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 = ""
@@ -271,8 +290,12 @@
                         else:
                             output += str(col)
                         count += 1
-
-                    print output
+                    if outpath:
+                        outfile.write('{st}\n'.format(st=output))
+                    else:
+                        print output
+    if outpath:
+        outfile.close()
     if connected:
         dbif.close()
 

Modified: grass/branches/releasebranch_7_0/temporal/t.list/t.list.py
===================================================================
--- grass/branches/releasebranch_7_0/temporal/t.list/t.list.py	2016-02-18 11:14:10 UTC (rev 67879)
+++ grass/branches/releasebranch_7_0/temporal/t.list/t.list.py	2016-02-18 11:19:25 UTC (rev 67880)
@@ -71,6 +71,10 @@
 #% guisection: Formatting
 #%end
 
+#%option G_OPT_F_OUTPUT
+#% required: no
+#%end
+
 #%flag
 #% key: c
 #% description: Print the column names as first row
@@ -93,6 +97,7 @@
     order = options["order"]
     where = options["where"]
     separator = gscript.separator(options["separator"])
+    outpath = options["output"]
     colhead = flags['c']
 
     # Make sure the temporal database exists
@@ -100,8 +105,8 @@
 
     sp = tgis.dataset_factory(type, None)
     first = True
-    
-    if  gscript.verbosity() > 0:
+
+    if  gscript.verbosity() > 0 and not outpath:
         sys.stderr.write("----------------------------------------------\n")
 
     for ttype in temporal_type.split(","):
@@ -116,13 +121,16 @@
         # alphabetic ordering
         mapsets = tgis.get_tgis_c_library_interface().available_mapsets()
 
+        if outpath:
+            outfile = open(outpath, 'w')
+
         # Print for each mapset separately
         for key in mapsets:
             if key in stds_list.keys():
                 rows = stds_list[key]
 
                 if rows:
-                    if  gscript.verbosity() > 0:
+                    if  gscript.verbosity() > 0 and not outpath:
                         if issubclass(sp.__class__,  tgis.AbstractMapDataset):
                             sys.stderr.write(_("Time stamped %s maps with %s available in mapset <%s>:\n")%\
                                                      (sp.get_type(),  time,  key))
@@ -140,9 +148,12 @@
                             else:
                                 output += str(key)
                             count += 1
-                        print output
+                        if outpath:
+                            outfile.write("{st}\n".format(st=output))
+                        else:
+                            print output
                         first = False
-            
+
                     for row in rows:
                         output = ""
                         count = 0
@@ -152,8 +163,12 @@
                             else:
                                 output += str(col)
                             count += 1
-            
-                        print output
+                        if outpath:
+                            outfile.write("{st}\n".format(st=output))
+                        else:
+                            print output
+    if outpath:
+        outfile.close()
 
 if __name__ == "__main__":
     options, flags = gscript.parser()

Modified: grass/branches/releasebranch_7_0/temporal/t.rast.list/t.rast.list.py
===================================================================
--- grass/branches/releasebranch_7_0/temporal/t.rast.list/t.rast.list.py	2016-02-18 11:14:10 UTC (rev 67879)
+++ grass/branches/releasebranch_7_0/temporal/t.rast.list/t.rast.list.py	2016-02-18 11:19:25 UTC (rev 67880)
@@ -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/branches/releasebranch_7_0/temporal/t.rast3d.list/t.rast3d.list.py
===================================================================
--- grass/branches/releasebranch_7_0/temporal/t.rast3d.list/t.rast3d.list.py	2016-02-18 11:14:10 UTC (rev 67879)
+++ grass/branches/releasebranch_7_0/temporal/t.rast3d.list/t.rast3d.list.py	2016-02-18 11:19:25 UTC (rev 67880)
@@ -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/branches/releasebranch_7_0/temporal/t.vect.list/t.vect.list.py
===================================================================
--- grass/branches/releasebranch_7_0/temporal/t.vect.list/t.vect.list.py	2016-02-18 11:14:10 UTC (rev 67879)
+++ grass/branches/releasebranch_7_0/temporal/t.vect.list/t.vect.list.py	2016-02-18 11:19:25 UTC (rev 67880)
@@ -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