~ubuntu-branches/ubuntu/vivid/grass/vivid-proposed

« back to all changes in this revision

Viewing changes to temporal/t.list/t.list.py

  • Committer: Package Import Robot
  • Author(s): Bas Couwenberg
  • Date: 2015-02-20 23:12:08 UTC
  • mfrom: (8.2.6 experimental)
  • Revision ID: package-import@ubuntu.com-20150220231208-1u6qvqm84v430b10
Tags: 7.0.0-1~exp1
* New upstream release.
* Update python-ctypes-ternary.patch to use if/else instead of and/or.
* Drop check4dev patch, rely on upstream check.
* Add build dependency on libpq-dev to grass-dev for libpq-fe.h.
* Drop patches applied upstream, refresh remaining patches.
* Update symlinks for images switched from jpg to png.

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
#!/usr/bin/env python
 
2
# -*- coding: utf-8 -*-
 
3
############################################################################
 
4
#
 
5
# MODULE:       t.list
 
6
# AUTHOR(S):    Soeren Gebbert
 
7
#
 
8
# PURPOSE:      List space time datasets and maps registered in the temporal database
 
9
# COPYRIGHT:    (C) 2011-2014, Soeren Gebbert and the GRASS Development Team
 
10
#
 
11
#               This program is free software under the GNU General Public
 
12
#               License (version 2). Read the file COPYING that comes with GRASS
 
13
#               for details.
 
14
#
 
15
#############################################################################
 
16
 
 
17
#%module
 
18
#% description: Lists space time datasets and maps registered in the temporal database.
 
19
#% keyword: temporal
 
20
#% keyword: map management
 
21
#% keyword: list
 
22
#%end
 
23
 
 
24
#%option
 
25
#% key: type
 
26
#% type: string
 
27
#% description: Type of the space time dataset or map, default is strds
 
28
#% guisection: Selection
 
29
#% required: no
 
30
#% options: strds, str3ds, stvds, raster, raster_3d, vector
 
31
#% answer: strds
 
32
#%end
 
33
 
 
34
#%option G_OPT_T_TYPE
 
35
#% multiple: yes
 
36
#% answer: absolute,relative
 
37
#% guisection: Selection
 
38
#%end
 
39
 
 
40
#%option
 
41
#% key: order
 
42
#% type: string
 
43
#% description: Columns number_of_maps and granularity only available for space time datasets
 
44
#% label: Sort the space time dataset by category
 
45
#% guisection: Formatting
 
46
#% required: no
 
47
#% multiple: yes
 
48
#% options: id,name,creator,mapset,number_of_maps,creation_time,start_time,end_time,interval,north,south,west,east,granularity
 
49
#% answer: id
 
50
#%end
 
51
 
 
52
#%option
 
53
#% key: columns
 
54
#% type: string
 
55
#% description: Columns number_of_maps and granularity only available for space time datasets
 
56
#% label: Columns to be printed to stdout
 
57
#% guisection: Selection
 
58
#% required: no
 
59
#% multiple: yes
 
60
#% options: id,name,creator,mapset,number_of_maps,creation_time,start_time,end_time,north,south,west,east,granularity,all
 
61
#% answer: id
 
62
#%end
 
63
 
 
64
#%option G_OPT_T_WHERE
 
65
#% guisection: Selection
 
66
#%end
 
67
 
 
68
#%option G_OPT_F_SEP
 
69
#% description: Field separator character between the output columns
 
70
#% guisection: Formatting
 
71
#%end
 
72
 
 
73
#%flag
 
74
#% key: c
 
75
#% description: Print the column names as first row
 
76
#% guisection: Formatting
 
77
#%end
 
78
 
 
79
import grass.script as gscript
 
80
import grass.temporal as tgis
 
81
import sys
 
82
 
 
83
############################################################################
 
84
 
 
85
 
 
86
def main():
 
87
 
 
88
    # Get the options
 
89
    type = options["type"]
 
90
    temporal_type = options["temporaltype"]
 
91
    columns = options["columns"]
 
92
    order = options["order"]
 
93
    where = options["where"]
 
94
    separator = gscript.separator(options["separator"])
 
95
    colhead = flags['c']
 
96
 
 
97
    # Make sure the temporal database exists
 
98
    tgis.init()
 
99
 
 
100
    sp = tgis.dataset_factory(type, None)
 
101
    first = True
 
102
    
 
103
    if  gscript.verbosity() > 0:
 
104
        sys.stderr.write("----------------------------------------------\n")
 
105
 
 
106
    for ttype in temporal_type.split(","):
 
107
        if ttype == "absolute":
 
108
            time = "absolute time"
 
109
        else:
 
110
            time = "relative time"
 
111
 
 
112
        stds_list = tgis.get_dataset_list(type,  ttype,  columns,  where,  order)
 
113
 
 
114
        # Use the correct order of the mapsets, hence first the current mapset, then
 
115
        # alphabetic ordering
 
116
        mapsets = tgis.get_tgis_c_library_interface().available_mapsets()
 
117
 
 
118
        # Print for each mapset separately
 
119
        for key in mapsets:
 
120
            if key in stds_list.keys():
 
121
                rows = stds_list[key]
 
122
 
 
123
                if rows:
 
124
                    if  gscript.verbosity() > 0:
 
125
                        if issubclass(sp.__class__,  tgis.AbstractMapDataset):
 
126
                            sys.stderr.write(_("Time stamped %s maps with %s available in mapset <%s>:\n")%\
 
127
                                                     (sp.get_type(),  time,  key))
 
128
                        else:
 
129
                            sys.stderr.write(_("Space time %s datasets with %s available in mapset <%s>:\n")%\
 
130
                                                     (sp.get_new_map_instance(None).get_type(),  time,  key))
 
131
 
 
132
                    # Print the column names if requested
 
133
                    if colhead == True and first == True:
 
134
                        output = ""
 
135
                        count = 0
 
136
                        for key in rows[0].keys():
 
137
                            if count > 0:
 
138
                                output += separator + str(key)
 
139
                            else:
 
140
                                output += str(key)
 
141
                            count += 1
 
142
                        print output
 
143
                        first = False
 
144
            
 
145
                    for row in rows:
 
146
                        output = ""
 
147
                        count = 0
 
148
                        for col in row:
 
149
                            if count > 0:
 
150
                                output += separator + str(col)
 
151
                            else:
 
152
                                output += str(col)
 
153
                            count += 1
 
154
            
 
155
                        print output
 
156
 
 
157
if __name__ == "__main__":
 
158
    options, flags = gscript.parser()
 
159
    main()