GRASS Programmer's Manual
6.4.2(2012)
|
00001 #!/usr/bin/env python 00002 ############################################################################ 00003 # 00004 # MODULE: p.vect 00005 # AUTHOR(S): Jachym Cepicky, Hamish Bowman 00006 # Converted to Python by Huidae Cho 00007 # PURPOSE: Displays vector 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 vector map layer in the active map display window. 00024 #% keywords: display, vector 00025 #%end 00026 #%flag 00027 #% key: a 00028 #% description: Get colors from map table column (of form RRR:GGG:BBB) 00029 #% guisection: Colors 00030 #%end 00031 #%flag 00032 #% key: c 00033 #% description: Random colors according to category number (or layer number if 'layer=-1' is given) 00034 #% guisection: Colors 00035 #%end 00036 #%flag 00037 #% key: i 00038 #% description: Use values from 'cats' option as feature id 00039 #% guisection: Selection 00040 #%end 00041 #%flag 00042 #% key: z 00043 #% description: Colorize polygons according to z height 00044 #%end 00045 #%option 00046 #% key: map 00047 #% type: string 00048 #% required: yes 00049 #% multiple: no 00050 #% key_desc: name 00051 #% description: Name of input vector map 00052 #% gisprompt: old,vector,vector 00053 #%end 00054 #%option 00055 #% key: display 00056 #% type: string 00057 #% required: no 00058 #% multiple: yes 00059 #% options: shape,cat,topo,dir,attr,zcoor 00060 #% description: Display 00061 #% answer: shape 00062 #%end 00063 #%option 00064 #% key: type 00065 #% type: string 00066 #% required: no 00067 #% multiple: yes 00068 #% options: point,line,boundary,centroid,area,face 00069 #% description: Feature type 00070 #% answer: point,line,boundary,centroid,area,face 00071 #% guisection: Selection 00072 #%end 00073 #%option 00074 #% key: layer 00075 #% type: string 00076 #% required: no 00077 #% multiple: no 00078 #% label: Layer number (if -1, all layers are displayed) 00079 #% description: A single vector map can be connected to multiple database tables. This number determines which table to use. 00080 #% answer: 1 00081 #% gisprompt: old_layer,layer,layer_all 00082 #% guisection: Selection 00083 #%end 00084 #%option 00085 #% key: cats 00086 #% type: string 00087 #% required: no 00088 #% multiple: no 00089 #% key_desc: range 00090 #% label: Category values 00091 #% description: Example: 1,3,7-9,13 00092 #% guisection: Selection 00093 #%end 00094 #%option 00095 #% key: where 00096 #% type: string 00097 #% required: no 00098 #% multiple: no 00099 #% key_desc: sql_query 00100 #% label: WHERE conditions of SQL statement without 'where' keyword 00101 #% description: Example: income < 1000 and inhab >= 10000 00102 #% guisection: Selection 00103 #%end 00104 #%option 00105 #% key: color 00106 #% type: string 00107 #% required: no 00108 #% multiple: no 00109 #% label: Line color 00110 #% description: Either a standard GRASS color, R:G:B triplet, or "none" 00111 #% answer: black 00112 #% gisprompt: old_color,color,color_none 00113 #% guisection: Colors 00114 #%end 00115 #%option 00116 #% key: fcolor 00117 #% type: string 00118 #% required: no 00119 #% multiple: no 00120 #% label: Area fill color 00121 #% description: Either a standard GRASS color, R:G:B triplet, or "none" 00122 #% answer: 200:200:200 00123 #% gisprompt: old_color,color,color_none 00124 #% guisection: Colors 00125 #%end 00126 #%option 00127 #% key: rgb_column 00128 #% type: string 00129 #% required: no 00130 #% multiple: no 00131 #% key_desc: name 00132 #% description: Name of color definition column (for use with -a flag) 00133 #% answer: GRASSRGB 00134 #% gisprompt: old_dbcolumn,dbcolumn,dbcolumn 00135 #% guisection: Colors 00136 #%end 00137 #%option 00138 #% key: zcolor 00139 #% type: string 00140 #% required: no 00141 #% multiple: no 00142 #% key_desc: style 00143 #% description: Type of color table (for use with -z flag) 00144 #% answer: terrain 00145 #% guisection: Colors 00146 #%end 00147 #%option 00148 #% key: width 00149 #% type: integer 00150 #% required: no 00151 #% multiple: no 00152 #% description: Line width 00153 #% answer: 0 00154 #% guisection: Lines 00155 #%end 00156 #%option 00157 #% key: wcolumn 00158 #% type: string 00159 #% required: no 00160 #% multiple: no 00161 #% key_desc: name 00162 #% description: Name of column for line widths (these values will be scaled by wscale) 00163 #% gisprompt: old_dbcolumn,dbcolumn,dbcolumn 00164 #% guisection: Lines 00165 #%end 00166 #%option 00167 #% key: wscale 00168 #% type: double 00169 #% required: no 00170 #% multiple: no 00171 #% description: Scale factor for wcolumn 00172 #% answer: 1 00173 #% guisection: Lines 00174 #%end 00175 #%option 00176 #% key: icon 00177 #% type: string 00178 #% required: no 00179 #% multiple: no 00180 #% options: basic/marker,basic/circle,basic/arrow1,basic/star,basic/point,basic/triangle,basic/box,basic/arrow2,basic/octagon,basic/cross2,basic/pushpin,basic/diamond,basic/cross1,basic/x,demo/smrk,demo/muchomurka,extra/dive_flag,extra/half-box,extra/bridge,extra/fiducial,extra/ping,extra/offbox_ne,extra/adcp,extra/alpha_flag,extra/4pt_star,extra/half-circle,extra/offbox_nw,extra/fancy_compass,extra/airport,extra/compass,extra/offbox_se,extra/fish,extra/target,extra/offbox_sw,extra/n_arrow1,extra/pentagon,extra/n_arrow2,geology/strike_circle,geology/strike_box,geology/strike_line,geology/strike_triangle 00181 #% description: Point and centroid symbol 00182 #% answer: basic/x 00183 #% guisection: Symbols 00184 #%end 00185 #%option 00186 #% key: size 00187 #% type: integer 00188 #% required: no 00189 #% multiple: no 00190 #% description: Symbol size 00191 #% answer: 5 00192 #% guisection: Symbols 00193 #%end 00194 #%option 00195 #% key: size_column 00196 #% type: string 00197 #% required: no 00198 #% multiple: no 00199 #% key_desc: name 00200 #% description: Name of numeric column containing symbol size 00201 #% gisprompt: old_dbcolumn,dbcolumn,dbcolumn 00202 #% guisection: Symbols 00203 #%end 00204 #%option 00205 #% key: rot_column 00206 #% type: string 00207 #% required: no 00208 #% multiple: no 00209 #% key_desc: name 00210 #% label: Name of numeric column containing symbol rotation angle 00211 #% description: Measured in degrees CCW from east 00212 #% gisprompt: old_dbcolumn,dbcolumn,dbcolumn 00213 #% guisection: Symbols 00214 #%end 00215 #%option 00216 #% key: llayer 00217 #% type: string 00218 #% required: no 00219 #% multiple: no 00220 #% label: Layer number or name 00221 #% description: Layer number for labels (default: the given layer number) 00222 #% answer: 1 00223 #% gisprompt: old_layer,layer,layer 00224 #% guisection: Labels 00225 #%end 00226 #%option 00227 #% key: attrcol 00228 #% type: string 00229 #% required: no 00230 #% multiple: no 00231 #% key_desc: name 00232 #% description: Name of column to be displayed 00233 #% gisprompt: old_dbcolumn,dbcolumn,dbcolumn 00234 #% guisection: Labels 00235 #%end 00236 #%option 00237 #% key: lcolor 00238 #% type: string 00239 #% required: no 00240 #% multiple: no 00241 #% label: Label color 00242 #% description: Either a standard color name or R:G:B triplet 00243 #% answer: red 00244 #% gisprompt: old_color,color,color 00245 #% guisection: Labels 00246 #%end 00247 #%option 00248 #% key: bgcolor 00249 #% type: string 00250 #% required: no 00251 #% multiple: no 00252 #% label: Label background color 00253 #% description: Either a standard GRASS color, R:G:B triplet, or "none" 00254 #% answer: none 00255 #% gisprompt: old_color,color,color_none 00256 #% guisection: Labels 00257 #%end 00258 #%option 00259 #% key: bcolor 00260 #% type: string 00261 #% required: no 00262 #% multiple: no 00263 #% label: Label border color 00264 #% description: Either a standard GRASS color, R:G:B triplet, or "none" 00265 #% answer: none 00266 #% gisprompt: old_color,color,color_none 00267 #% guisection: Labels 00268 #%end 00269 #%option 00270 #% key: lsize 00271 #% type: integer 00272 #% required: no 00273 #% multiple: no 00274 #% description: Label size (pixels) 00275 #% answer: 8 00276 #% guisection: Labels 00277 #%end 00278 #%option 00279 #% key: font 00280 #% type: string 00281 #% required: no 00282 #% multiple: no 00283 #% description: Font name 00284 #% guisection: Labels 00285 #%end 00286 #%option 00287 #% key: encoding 00288 #% type: string 00289 #% required: no 00290 #% multiple: no 00291 #% description: Text encoding 00292 #% guisection: Labels 00293 #%end 00294 #%option 00295 #% key: xref 00296 #% type: string 00297 #% required: no 00298 #% multiple: no 00299 #% options: left,center,right 00300 #% description: Label horizontal justification 00301 #% answer: left 00302 #% guisection: Labels 00303 #%end 00304 #%option 00305 #% key: yref 00306 #% type: string 00307 #% required: no 00308 #% multiple: no 00309 #% options: top,center,bottom 00310 #% description: Label vertical justification 00311 #% answer: center 00312 #% guisection: Labels 00313 #%end 00314 #%option 00315 #% key: minreg 00316 #% type: double 00317 #% required: no 00318 #% multiple: no 00319 #% description: Minimum region size (average from height and width) when map is displayed 00320 #%end 00321 #%option 00322 #% key: maxreg 00323 #% type: double 00324 #% required: no 00325 #% multiple: no 00326 #% description: Maximum region size (average from height and width) when map is displayed 00327 #%end 00328 #%option 00329 #% key: opacity 00330 #% type: string 00331 #% required: no 00332 #% multiple: no 00333 #% key_desc: val 00334 #% answer: 100 00335 #% description: Set opacity between 0-100% 00336 #%end 00337 00338 import sys 00339 import os 00340 import grass.script as grass 00341 00342 def construct_command(cmd): 00343 line = cmd 00344 for key, val in options.iteritems(): 00345 if val != "": 00346 line += " %s=%s" % (key, val) 00347 for key, val in flags.iteritems(): 00348 if val == True: 00349 line += " -%s" % key 00350 return line 00351 00352 def main(): 00353 cmd_file = grass.gisenv()["GRASS_PYCMDFILE"] 00354 00355 if cmd_file == "" or os.path.exists(cmd_file) == False: 00356 grass.message(_("GRASS_PYCMDFILE - File not found. Run p.mon."), "e") 00357 return 00358 00359 cmd = construct_command("d"+os.path.basename(sys.argv[0])[1:-3]) 00360 00361 fp = open(cmd_file, "a") 00362 fp.write("%s\n" % cmd) 00363 fp.close() 00364 00365 if __name__ == "__main__": 00366 options, flags = grass.parser() 00367 main()