GRASS Programmer's Manual  6.4.2(2012)
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Pages
p.rast.py
Go to the documentation of this file.
1 #!/usr/bin/env python
2 ############################################################################
3 #
4 # MODULE: p.rast
5 # AUTHOR(S): Jachym Cepicky, Martin Landa, Hamish Bowman
6 # Converted to Python by Huidae Cho
7 # PURPOSE: Displays raster map layer in the active map display window.
8 # COPYRIGHT: (C) 2009 by The GRASS Development Team
9 #
10 # This program is free software; you can redistribute it and/or modify
11 # it under the terms of the GNU General Public License as published by
12 # the Free Software Foundation; either version 2 of the License, or
13 # (at your option) any later version.
14 #
15 # This program is distributed in the hope that it will be useful,
16 # but WITHOUT ANY WARRANTY; without even the implied warranty of
17 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 # GNU General Public License for more details.
19 #
20 ############################################################################
21 
22 #%module
23 #% description: Displays raster map layer in the active map display window.
24 #% keywords: display, raster
25 #%end
26 #%flag
27 #% key: n
28 #% description: Make null cells opaque
29 #%end
30 #%flag
31 #% key: i
32 #% description: Invert catlist
33 #% guisection: Selection
34 #%end
35 #%option
36 #% key: map
37 #% type: string
38 #% required: yes
39 #% multiple: no
40 #% key_desc: name
41 #% description: Raster map to be displayed
42 #% gisprompt: old,cell,raster
43 #%end
44 #%option
45 #% key: catlist
46 #% type: string
47 #% required: no
48 #% multiple: yes
49 #% key_desc: cat[-cat]
50 #% description: List of categories to be displayed (INT maps)
51 #% guisection: Selection
52 #%end
53 #%option
54 #% key: vallist
55 #% type: string
56 #% required: no
57 #% multiple: yes
58 #% key_desc: val[-val]
59 #% description: List of values to be displayed (FP maps)
60 #% guisection: Selection
61 #%end
62 #%option
63 #% key: bg
64 #% type: string
65 #% required: no
66 #% multiple: no
67 #% key_desc: color
68 #% description: Background color (for null)
69 #% gisprompt: old_color,color,color
70 #%end
71 #%option
72 #% key: opacity
73 #% type: string
74 #% required: no
75 #% multiple: no
76 #% key_desc: val
77 #% answer: 100
78 #% description: Set opacity between 0-100%
79 #%end
80 
81 import sys
82 import os
83 import grass.script as grass
84 
86  line = cmd
87  for key, val in options.iteritems():
88  if val != "":
89  line += " %s=%s" % (key, val)
90  for key, val in flags.iteritems():
91  if val == True:
92  line += " -%s" % key
93  return line
94 
95 def main():
96  cmd_file = grass.gisenv()["GRASS_PYCMDFILE"]
97 
98  if cmd_file == "" or os.path.exists(cmd_file) == False:
99  grass.message(_("GRASS_PYCMDFILE - File not found. Run p.mon."), "e")
100  return
101 
102  cmd = construct_command("d"+os.path.basename(sys.argv[0])[1:-3])
103 
104  fp = open(cmd_file, "a")
105  fp.write("%s\n" % cmd)
106  fp.close()
107 
108 if __name__ == "__main__":
109  options, flags = grass.parser()
110  main()