|
@@ -10,9 +10,9 @@ Usage:
|
|
|
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 @@ def get_dataset_list(type, temporal_type, columns=None, where=None,
|
|
|
>>> 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 @@ def get_dataset_list(type, temporal_type, columns=None, where=None,
|
|
|
... 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 get_dataset_list(type, temporal_type, columns=None, where=None,
|
|
|
|
|
|
|
|
|
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 @@ def list_maps_of_stds(type, input, columns, order, where, separator,
|
|
|
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 @@ def list_maps_of_stds(type, input, columns, order, where, separator,
|
|
|
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 @@ def list_maps_of_stds(type, input, columns, order, where, separator,
|
|
|
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 @@ def list_maps_of_stds(type, input, columns, order, where, separator,
|
|
|
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 @@ def list_maps_of_stds(type, input, columns, order, where, separator,
|
|
|
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 @@ def list_maps_of_stds(type, input, columns, order, where, separator,
|
|
|
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 @@ def list_maps_of_stds(type, input, columns, order, where, separator,
|
|
|
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()
|
|
|
|