p.vect.py 8.8 KB

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