[GRASS-SVN] r53287 - grass/trunk/lib/python/temporal
svn_grass at osgeo.org
svn_grass at osgeo.org
Fri Sep 28 17:31:28 PDT 2012
Author: huhabla
Date: 2012-09-28 17:31:27 -0700 (Fri, 28 Sep 2012)
New Revision: 53287
Modified:
grass/trunk/lib/python/temporal/space_time_datasets_tools.py
Log:
Added space time dataset listing functionality implemented by Anna Kratochv?\195?\173lov?\195?\161.
Modified: grass/trunk/lib/python/temporal/space_time_datasets_tools.py
===================================================================
--- grass/trunk/lib/python/temporal/space_time_datasets_tools.py 2012-09-28 23:11:38 UTC (rev 53286)
+++ grass/trunk/lib/python/temporal/space_time_datasets_tools.py 2012-09-29 00:31:27 UTC (rev 53287)
@@ -723,3 +723,89 @@
print string
dbif.close()
+
+###############################################################################
+
+def tlist_grouped(type):
+ """!List of temporal elements grouped by mapsets.
+
+ Returns a dictionary where the keys are mapset
+ names and the values are lists of space time datasets in that
+ mapset. Example:
+
+ @code
+ >>> tgis.tlist_grouped('strds')['PERMANENT']
+ ['precipitation', 'temperature']
+ @endcode
+
+ @param type element type (strds, str3ds, stvds)
+
+ @return directory of mapsets/elements
+ """
+ result = {}
+
+ mapset = None
+ if type == 'stds':
+ types = ['strds', 'str3ds', 'stvds']
+ else:
+ types = [type]
+ for type in types:
+ try:
+ tlist_result = tlist(type)
+ except core.ScriptError, e:
+ warning(e)
+ continue
+
+ for line in tlist_result:
+ try:
+ name, mapset = line.split('@')
+ except ValueError:
+ warning(_("Invalid element '%s'") % line)
+ continue
+
+ if mapset in result:
+ result[mapset].append(name)
+ else:
+ result[mapset] = [name, ]
+
+ return result
+
+###############################################################################
+
+def tlist(type):
+ """!Return a list of space time datasets of absolute and relative time
+
+ @param type element type (strds, str3ds, stvds)
+
+ @return a list of space time dataset ids
+ """
+ id = None
+ sp = dataset_factory(type, id)
+
+ dbif = SQLDatabaseInterfaceConnection()
+ dbif.connect()
+
+ output = []
+ temporal_type = ["absolute", 'relative']
+ for type in temporal_type:
+ # Table name
+ if type == "absolute":
+ table = sp.get_type() + "_view_abs_time"
+ else:
+ table = sp.get_type() + "_view_rel_time"
+
+ # Create the sql selection statement
+ sql = "SELECT id FROM " + table
+ sql += " ORDER BY id"
+
+ dbif.cursor.execute(sql)
+ rows = dbif.cursor.fetchall()
+
+ # Append the ids of the space time datasets
+ for row in rows:
+ for col in row:
+ output.append(str(col))
+ dbif.close()
+
+ return output
+
More information about the grass-commit
mailing list