GRASS Programmer's Manual  6.4.2(2012)
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Pages
v.type_wrapper.py
Go to the documentation of this file.
1 #!/usr/bin/env python
2 ############################################################################
3 #
4 # MODULE: v.type_wrapper.py (v.type wrapper script)
5 #
6 # AUTHOR(S): Hamish Bowman (Otago University, New Zealand)
7 # (original contributor, v.type.sh)
8 # Pythonized by Martin Landa <landa.martin gmail.com> (2008/08)
9 #
10 # PURPOSE: Supply v.type options in a GUI compatible way
11 #
12 # COPYRIGHT: (C) 2007-2008 by Hamish Bowman, and the GRASS Development Team
13 #
14 # This program is free software under the GNU General Public
15 # License (>=v2). Read the file COPYING that comes with GRASS
16 # for details.
17 #
18 #############################################################################
19 
20 #%module
21 #% description: Change the type of geometry elements.
22 #% keywords: vector, geometry
23 #%end
24 
25 #%option
26 #% key: input
27 #% type: string
28 #% required: yes
29 #% multiple: no
30 #% key_desc: name
31 #% description: Name of input vector map
32 #% gisprompt: old,vector,vector
33 #%end
34 
35 #%option
36 #% key: output
37 #% type: string
38 #% required: yes
39 #% multiple: no
40 #% key_desc: name
41 #% description: Name for output vector map
42 #% gisprompt: new,vector,vector
43 #%end
44 
45 #%option
46 #% key: type
47 #% type: string
48 #% required: no
49 #% multiple: no
50 #% options: point to centroid,point to kernel,centroid to point,centroid to kernel,kernel to point,kernel to centroid,line to boundary,line to face,boundary to line,boundary to face,face to line,face to boundary
51 #% description: Conversion
52 #% answer: boundary to line
53 #%end
54 
55 import sys
56 from grass.script import core as grass
57 
58 def main():
59  if options['type'] == "point to centroid":
60  type_cnv = "point,centroid"
61  elif options['type'] == "point to kernel":
62  type_cnv = "point,kernel"
63  elif options['type'] == "centroid to point":
64  type_cnv = "centroid,point"
65  elif options['type'] == "centroid to kernel":
66  type_cnv = "centroid,kernel"
67  elif options['type'] == "kernel to point":
68  type_cnv = "kernel,point"
69  elif options['type'] == "kernel to centroid":
70  type_cnv = "kernel,centroid"
71  elif options['type'] == "line to boundary":
72  type_cnv = "line,boundary"
73  elif options['type'] == "line to face":
74  type_cnv = "line,face"
75  elif options['type'] == "boundary to line":
76  type_cnv = "boundary,line"
77  elif options['type'] == "boundary to face":
78  type_cnv = "boundary,face"
79  elif options['type'] == "face to line":
80  type_cnv = "face,line"
81  elif options['type'] == "face to boundary":
82  type_cnv = "face,boundary"
83 
84  options.pop('type')
85  grass.exec_command("v.type", type = type_cnv, **options)
86 
87  return 0
88 
89 if __name__ == "__main__":
90  options, flags = grass.parser()
91  sys.exit(main())