[GRASS-SVN] r71101 - grass/branches/releasebranch_7_2/scripts/v.what.strds

svn_grass at osgeo.org svn_grass at osgeo.org
Fri May 19 06:43:36 PDT 2017


Author: lucadelu
Date: 2017-05-19 06:43:36 -0700 (Fri, 19 May 2017)
New Revision: 71101

Modified:
   grass/branches/releasebranch_7_2/scripts/v.what.strds/v.what.strds.py
Log:
v.what.strds: backports of r69331

Modified: grass/branches/releasebranch_7_2/scripts/v.what.strds/v.what.strds.py
===================================================================
--- grass/branches/releasebranch_7_2/scripts/v.what.strds/v.what.strds.py	2017-05-18 11:34:10 UTC (rev 71100)
+++ grass/branches/releasebranch_7_2/scripts/v.what.strds/v.what.strds.py	2017-05-19 13:43:36 UTC (rev 71101)
@@ -58,7 +58,7 @@
 class Sample(object):
 
     def __init__(self, start=None, end=None, raster_names=None,
-                 strds_name=None):
+                 strds_name=None, granularity=None):
         self.start = start
         self.end = end
         if raster_names is not None:
@@ -66,6 +66,7 @@
         else:
             self.raster_names = []
         self.strds_name = strds_name
+        self.granu = granularity
 
     def __str__(self):
         return "Start: %s\nEnd: %s\nNames: %s\n" % (str(self.start),
@@ -73,13 +74,18 @@
                                                     str(self.raster_names))
 
     def printDay(self, date='start'):
+        output = ''
         if date == 'start':
-            return str(self.start).split(' ')[0].replace('-', '_')
+            output = str(self.start).split(' ')[0].replace('-', '_')
         elif date == 'end':
-            return str(self.end).split(' ')[0].replace('-', '_')
+            output = str(self.end).split(' ')[0].replace('-', '_')
         else:
             grass.fatal("The values accepted by printDay in Sample are:"
                         " 'start', 'end'")
+        if self.granu:
+            if self.granu.find('minute') != -1 or self.granu.find('second') != -1:
+                output += '_' + str(self.start).split(' ')[1].replace(':', '_')
+        return output
 
 ############################################################################
 
@@ -129,6 +135,7 @@
     first_strds = tgis.open_old_stds(strds_names[0], "strds", dbif)
     # Single space time raster dataset
     if len(strds_names) == 1:
+        granu = first_strds.get_granularity()
         rows = first_strds.get_registered_maps("name,mapset,start_time,end_time",
                                                tempwhere, "start_time",
                                                dbif)
@@ -137,13 +144,12 @@
             dbif.close()
             grass.fatal(_("Space time raster dataset <%s> is empty") %
                         first_strds.get_id())
-
         for row in rows:
             start = row["start_time"]
             end = row["end_time"]
             raster_maps = [row["name"] + "@" + row["mapset"], ]
 
-            s = Sample(start, end, raster_maps, first_strds.get_name())
+            s = Sample(start, end, raster_maps, first_strds.get_name(), granu)
             samples.append(s)
     else:
         # Multiple space time raster datasets
@@ -164,7 +170,7 @@
                                                         False, None,
                                                         "equal", False,
                                                         False)
-
+        #TODO check granularity for multiple STRDS
         for i in range(len(mapmatrizes[0])):
             isvalid = True
             mapname_list = []
@@ -207,11 +213,14 @@
 
     if len(pymap.dblinks) == 0:
         try:
+            pymap.close()
             grass.run_command("v.db.addtable", map=output)
         except CalledModuleError:
             dbif.close()
             grass.fatal(_("Unable to add table <%s> to vector map <%s>" % output))
-    pymap.close()
+    if pymap.is_open():
+        pymap.close()
+
     for sample in samples:
         raster_names = sample.raster_names
         # Call v.what.rast for each raster map



More information about the grass-commit mailing list