GRASS Programmer's Manual
6.4.2(2012)
|
00001 #!/usr/bin/env python 00002 ############################################################################ 00003 # 00004 # MODULE: p.rast 00005 # AUTHOR(S): Jachym Cepicky, Martin Landa, Hamish Bowman 00006 # Converted to Python by Huidae Cho 00007 # PURPOSE: Displays raster map layer in the active map display window. 00008 # COPYRIGHT: (C) 2009 by The GRASS Development Team 00009 # 00010 # This program is free software; you can redistribute it and/or modify 00011 # it under the terms of the GNU General Public License as published by 00012 # the Free Software Foundation; either version 2 of the License, or 00013 # (at your option) any later version. 00014 # 00015 # This program is distributed in the hope that it will be useful, 00016 # but WITHOUT ANY WARRANTY; without even the implied warranty of 00017 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 00018 # GNU General Public License for more details. 00019 # 00020 ############################################################################ 00021 00022 #%module 00023 #% description: Displays raster map layer in the active map display window. 00024 #% keywords: display, raster 00025 #%end 00026 #%flag 00027 #% key: n 00028 #% description: Make null cells opaque 00029 #%end 00030 #%flag 00031 #% key: i 00032 #% description: Invert catlist 00033 #% guisection: Selection 00034 #%end 00035 #%option 00036 #% key: map 00037 #% type: string 00038 #% required: yes 00039 #% multiple: no 00040 #% key_desc: name 00041 #% description: Raster map to be displayed 00042 #% gisprompt: old,cell,raster 00043 #%end 00044 #%option 00045 #% key: catlist 00046 #% type: string 00047 #% required: no 00048 #% multiple: yes 00049 #% key_desc: cat[-cat] 00050 #% description: List of categories to be displayed (INT maps) 00051 #% guisection: Selection 00052 #%end 00053 #%option 00054 #% key: vallist 00055 #% type: string 00056 #% required: no 00057 #% multiple: yes 00058 #% key_desc: val[-val] 00059 #% description: List of values to be displayed (FP maps) 00060 #% guisection: Selection 00061 #%end 00062 #%option 00063 #% key: bg 00064 #% type: string 00065 #% required: no 00066 #% multiple: no 00067 #% key_desc: color 00068 #% description: Background color (for null) 00069 #% gisprompt: old_color,color,color 00070 #%end 00071 #%option 00072 #% key: opacity 00073 #% type: string 00074 #% required: no 00075 #% multiple: no 00076 #% key_desc: val 00077 #% answer: 100 00078 #% description: Set opacity between 0-100% 00079 #%end 00080 00081 import sys 00082 import os 00083 import grass.script as grass 00084 00085 def construct_command(cmd): 00086 line = cmd 00087 for key, val in options.iteritems(): 00088 if val != "": 00089 line += " %s=%s" % (key, val) 00090 for key, val in flags.iteritems(): 00091 if val == True: 00092 line += " -%s" % key 00093 return line 00094 00095 def main(): 00096 cmd_file = grass.gisenv()["GRASS_PYCMDFILE"] 00097 00098 if cmd_file == "" or os.path.exists(cmd_file) == False: 00099 grass.message(_("GRASS_PYCMDFILE - File not found. Run p.mon."), "e") 00100 return 00101 00102 cmd = construct_command("d"+os.path.basename(sys.argv[0])[1:-3]) 00103 00104 fp = open(cmd_file, "a") 00105 fp.write("%s\n" % cmd) 00106 fp.close() 00107 00108 if __name__ == "__main__": 00109 options, flags = grass.parser() 00110 main()