|
@@ -81,15 +81,15 @@
|
|
|
|
|
|
import grass.script as grass
|
|
|
import grass.temporal as tgis
|
|
|
+import sys
|
|
|
|
|
|
############################################################################
|
|
|
|
|
|
-
|
|
|
def main():
|
|
|
|
|
|
# Get the options
|
|
|
type = options["type"]
|
|
|
- temporaltype = options["temporaltype"]
|
|
|
+ temporal_type = options["temporaltype"]
|
|
|
columns = options["columns"]
|
|
|
order = options["order"]
|
|
|
where = options["where"]
|
|
@@ -99,69 +99,59 @@ def main():
|
|
|
# Make sure the temporal database exists
|
|
|
tgis.init()
|
|
|
|
|
|
- id = None
|
|
|
- sp = tgis.dataset_factory(type, id)
|
|
|
-
|
|
|
- dbif = tgis.SQLDatabaseInterfaceConnection()
|
|
|
- dbif.connect()
|
|
|
-
|
|
|
+ sp = tgis.dataset_factory(type, None)
|
|
|
first = True
|
|
|
|
|
|
- for ttype in temporaltype.split(","):
|
|
|
-
|
|
|
- # Create the sql selection statement
|
|
|
- # Table name
|
|
|
+ sys.stderr.write("----------------------------------------------\n")
|
|
|
+
|
|
|
+ for ttype in temporal_type.split(","):
|
|
|
if ttype == "absolute":
|
|
|
- table = sp.get_type() + "_view_abs_time"
|
|
|
+ time = "absolute time"
|
|
|
else:
|
|
|
- table = sp.get_type() + "_view_rel_time"
|
|
|
-
|
|
|
- if columns.find("all") == -1:
|
|
|
- sql = "SELECT " + str(columns) + " FROM " + table
|
|
|
- else:
|
|
|
- sql = "SELECT * FROM " + table
|
|
|
-
|
|
|
- if where:
|
|
|
- sql += " WHERE " + where
|
|
|
-
|
|
|
- if order:
|
|
|
- sql += " ORDER BY " + order
|
|
|
-
|
|
|
- dbif.cursor.execute(sql)
|
|
|
- rows = dbif.cursor.fetchall()
|
|
|
-
|
|
|
- # Print the query result to stout
|
|
|
- if rows:
|
|
|
- if separator is None or separator == "":
|
|
|
- separator = "\t"
|
|
|
-
|
|
|
- # Print the column names if requested
|
|
|
- if colhead == True and first == True:
|
|
|
- output = ""
|
|
|
- count = 0
|
|
|
- for key in rows[0].keys():
|
|
|
- if count > 0:
|
|
|
- output += separator + str(key)
|
|
|
- else:
|
|
|
- output += str(key)
|
|
|
- count += 1
|
|
|
- print output
|
|
|
- first = False
|
|
|
-
|
|
|
- for row in rows:
|
|
|
- output = ""
|
|
|
- count = 0
|
|
|
- for col in row:
|
|
|
- if count > 0:
|
|
|
- output += separator + str(col)
|
|
|
- else:
|
|
|
- output += str(col)
|
|
|
- count += 1
|
|
|
-
|
|
|
- print output
|
|
|
+ time = "relative time"
|
|
|
|
|
|
- dbif.close()
|
|
|
+ stds_list = tgis.get_dataset_list(type, ttype, columns, where, order)
|
|
|
+
|
|
|
+ # Print for each mapset separately
|
|
|
+ for key in stds_list.keys():
|
|
|
+ rows = stds_list[key]
|
|
|
+
|
|
|
+ if rows:
|
|
|
+ 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))
|
|
|
+ else:
|
|
|
+ sys.stderr.write(_("Space time %s datasets with %s available in mapset <%s>:\n")%\
|
|
|
+ (sp.get_new_map_instance(None).get_type(), time, key))
|
|
|
+
|
|
|
+ if separator is None or separator == "":
|
|
|
+ separator = "\t"
|
|
|
+
|
|
|
+ # Print the column names if requested
|
|
|
+ if colhead == True and first == True:
|
|
|
+ output = ""
|
|
|
+ count = 0
|
|
|
+ for key in rows[0].keys():
|
|
|
+ if count > 0:
|
|
|
+ output += separator + str(key)
|
|
|
+ else:
|
|
|
+ output += str(key)
|
|
|
+ count += 1
|
|
|
+ print output
|
|
|
+ first = False
|
|
|
|
|
|
+ for row in rows:
|
|
|
+ output = ""
|
|
|
+ count = 0
|
|
|
+ for col in row:
|
|
|
+ if count > 0:
|
|
|
+ output += separator + str(col)
|
|
|
+ else:
|
|
|
+ output += str(col)
|
|
|
+ count += 1
|
|
|
+
|
|
|
+ print output
|
|
|
+
|
|
|
if __name__ == "__main__":
|
|
|
options, flags = grass.parser()
|
|
|
main()
|