GRASS Programmer's Manual  6.4.2(2012)
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Pages
p.vect.py
Go to the documentation of this file.
1 #!/usr/bin/env python
2 ############################################################################
3 #
4 # MODULE: p.vect
5 # AUTHOR(S): Jachym Cepicky, Hamish Bowman
6 # Converted to Python by Huidae Cho
7 # PURPOSE: Displays vector 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 vector map layer in the active map display window.
24 #% keywords: display, vector
25 #%end
26 #%flag
27 #% key: a
28 #% description: Get colors from map table column (of form RRR:GGG:BBB)
29 #% guisection: Colors
30 #%end
31 #%flag
32 #% key: c
33 #% description: Random colors according to category number (or layer number if 'layer=-1' is given)
34 #% guisection: Colors
35 #%end
36 #%flag
37 #% key: i
38 #% description: Use values from 'cats' option as feature id
39 #% guisection: Selection
40 #%end
41 #%flag
42 #% key: z
43 #% description: Colorize polygons according to z height
44 #%end
45 #%option
46 #% key: map
47 #% type: string
48 #% required: yes
49 #% multiple: no
50 #% key_desc: name
51 #% description: Name of input vector map
52 #% gisprompt: old,vector,vector
53 #%end
54 #%option
55 #% key: display
56 #% type: string
57 #% required: no
58 #% multiple: yes
59 #% options: shape,cat,topo,dir,attr,zcoor
60 #% description: Display
61 #% answer: shape
62 #%end
63 #%option
64 #% key: type
65 #% type: string
66 #% required: no
67 #% multiple: yes
68 #% options: point,line,boundary,centroid,area,face
69 #% description: Feature type
70 #% answer: point,line,boundary,centroid,area,face
71 #% guisection: Selection
72 #%end
73 #%option
74 #% key: layer
75 #% type: string
76 #% required: no
77 #% multiple: no
78 #% label: Layer number (if -1, all layers are displayed)
79 #% description: A single vector map can be connected to multiple database tables. This number determines which table to use.
80 #% answer: 1
81 #% gisprompt: old_layer,layer,layer_all
82 #% guisection: Selection
83 #%end
84 #%option
85 #% key: cats
86 #% type: string
87 #% required: no
88 #% multiple: no
89 #% key_desc: range
90 #% label: Category values
91 #% description: Example: 1,3,7-9,13
92 #% guisection: Selection
93 #%end
94 #%option
95 #% key: where
96 #% type: string
97 #% required: no
98 #% multiple: no
99 #% key_desc: sql_query
100 #% label: WHERE conditions of SQL statement without 'where' keyword
101 #% description: Example: income < 1000 and inhab >= 10000
102 #% guisection: Selection
103 #%end
104 #%option
105 #% key: color
106 #% type: string
107 #% required: no
108 #% multiple: no
109 #% label: Line color
110 #% description: Either a standard GRASS color, R:G:B triplet, or "none"
111 #% answer: black
112 #% gisprompt: old_color,color,color_none
113 #% guisection: Colors
114 #%end
115 #%option
116 #% key: fcolor
117 #% type: string
118 #% required: no
119 #% multiple: no
120 #% label: Area fill color
121 #% description: Either a standard GRASS color, R:G:B triplet, or "none"
122 #% answer: 200:200:200
123 #% gisprompt: old_color,color,color_none
124 #% guisection: Colors
125 #%end
126 #%option
127 #% key: rgb_column
128 #% type: string
129 #% required: no
130 #% multiple: no
131 #% key_desc: name
132 #% description: Name of color definition column (for use with -a flag)
133 #% answer: GRASSRGB
134 #% gisprompt: old_dbcolumn,dbcolumn,dbcolumn
135 #% guisection: Colors
136 #%end
137 #%option
138 #% key: zcolor
139 #% type: string
140 #% required: no
141 #% multiple: no
142 #% key_desc: style
143 #% description: Type of color table (for use with -z flag)
144 #% answer: terrain
145 #% guisection: Colors
146 #%end
147 #%option
148 #% key: width
149 #% type: integer
150 #% required: no
151 #% multiple: no
152 #% description: Line width
153 #% answer: 0
154 #% guisection: Lines
155 #%end
156 #%option
157 #% key: wcolumn
158 #% type: string
159 #% required: no
160 #% multiple: no
161 #% key_desc: name
162 #% description: Name of column for line widths (these values will be scaled by wscale)
163 #% gisprompt: old_dbcolumn,dbcolumn,dbcolumn
164 #% guisection: Lines
165 #%end
166 #%option
167 #% key: wscale
168 #% type: double
169 #% required: no
170 #% multiple: no
171 #% description: Scale factor for wcolumn
172 #% answer: 1
173 #% guisection: Lines
174 #%end
175 #%option
176 #% key: icon
177 #% type: string
178 #% required: no
179 #% multiple: no
180 #% 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
181 #% description: Point and centroid symbol
182 #% answer: basic/x
183 #% guisection: Symbols
184 #%end
185 #%option
186 #% key: size
187 #% type: integer
188 #% required: no
189 #% multiple: no
190 #% description: Symbol size
191 #% answer: 5
192 #% guisection: Symbols
193 #%end
194 #%option
195 #% key: size_column
196 #% type: string
197 #% required: no
198 #% multiple: no
199 #% key_desc: name
200 #% description: Name of numeric column containing symbol size
201 #% gisprompt: old_dbcolumn,dbcolumn,dbcolumn
202 #% guisection: Symbols
203 #%end
204 #%option
205 #% key: rot_column
206 #% type: string
207 #% required: no
208 #% multiple: no
209 #% key_desc: name
210 #% label: Name of numeric column containing symbol rotation angle
211 #% description: Measured in degrees CCW from east
212 #% gisprompt: old_dbcolumn,dbcolumn,dbcolumn
213 #% guisection: Symbols
214 #%end
215 #%option
216 #% key: llayer
217 #% type: string
218 #% required: no
219 #% multiple: no
220 #% label: Layer number or name
221 #% description: Layer number for labels (default: the given layer number)
222 #% answer: 1
223 #% gisprompt: old_layer,layer,layer
224 #% guisection: Labels
225 #%end
226 #%option
227 #% key: attrcol
228 #% type: string
229 #% required: no
230 #% multiple: no
231 #% key_desc: name
232 #% description: Name of column to be displayed
233 #% gisprompt: old_dbcolumn,dbcolumn,dbcolumn
234 #% guisection: Labels
235 #%end
236 #%option
237 #% key: lcolor
238 #% type: string
239 #% required: no
240 #% multiple: no
241 #% label: Label color
242 #% description: Either a standard color name or R:G:B triplet
243 #% answer: red
244 #% gisprompt: old_color,color,color
245 #% guisection: Labels
246 #%end
247 #%option
248 #% key: bgcolor
249 #% type: string
250 #% required: no
251 #% multiple: no
252 #% label: Label background color
253 #% description: Either a standard GRASS color, R:G:B triplet, or "none"
254 #% answer: none
255 #% gisprompt: old_color,color,color_none
256 #% guisection: Labels
257 #%end
258 #%option
259 #% key: bcolor
260 #% type: string
261 #% required: no
262 #% multiple: no
263 #% label: Label border color
264 #% description: Either a standard GRASS color, R:G:B triplet, or "none"
265 #% answer: none
266 #% gisprompt: old_color,color,color_none
267 #% guisection: Labels
268 #%end
269 #%option
270 #% key: lsize
271 #% type: integer
272 #% required: no
273 #% multiple: no
274 #% description: Label size (pixels)
275 #% answer: 8
276 #% guisection: Labels
277 #%end
278 #%option
279 #% key: font
280 #% type: string
281 #% required: no
282 #% multiple: no
283 #% description: Font name
284 #% guisection: Labels
285 #%end
286 #%option
287 #% key: encoding
288 #% type: string
289 #% required: no
290 #% multiple: no
291 #% description: Text encoding
292 #% guisection: Labels
293 #%end
294 #%option
295 #% key: xref
296 #% type: string
297 #% required: no
298 #% multiple: no
299 #% options: left,center,right
300 #% description: Label horizontal justification
301 #% answer: left
302 #% guisection: Labels
303 #%end
304 #%option
305 #% key: yref
306 #% type: string
307 #% required: no
308 #% multiple: no
309 #% options: top,center,bottom
310 #% description: Label vertical justification
311 #% answer: center
312 #% guisection: Labels
313 #%end
314 #%option
315 #% key: minreg
316 #% type: double
317 #% required: no
318 #% multiple: no
319 #% description: Minimum region size (average from height and width) when map is displayed
320 #%end
321 #%option
322 #% key: maxreg
323 #% type: double
324 #% required: no
325 #% multiple: no
326 #% description: Maximum region size (average from height and width) when map is displayed
327 #%end
328 #%option
329 #% key: opacity
330 #% type: string
331 #% required: no
332 #% multiple: no
333 #% key_desc: val
334 #% answer: 100
335 #% description: Set opacity between 0-100%
336 #%end
337 
338 import sys
339 import os
340 import grass.script as grass
341 
342 def construct_command(cmd):
343  line = cmd
344  for key, val in options.iteritems():
345  if val != "":
346  line += " %s=%s" % (key, val)
347  for key, val in flags.iteritems():
348  if val == True:
349  line += " -%s" % key
350  return line
351 
352 def main():
353  cmd_file = grass.gisenv()["GRASS_PYCMDFILE"]
354 
355  if cmd_file == "" or os.path.exists(cmd_file) == False:
356  grass.message(_("GRASS_PYCMDFILE - File not found. Run p.mon."), "e")
357  return
358 
359  cmd = construct_command("d"+os.path.basename(sys.argv[0])[1:-3])
360 
361  fp = open(cmd_file, "a")
362  fp.write("%s\n" % cmd)
363  fp.close()
364 
365 if __name__ == "__main__":
366  options, flags = grass.parser()
367  main()