GRASS Programmer's Manual
6.4.2(2012)
|
00001 #!/usr/bin/env python 00002 ############################################################################ 00003 # 00004 # MODULE: v.type_wrapper.py (v.type wrapper script) 00005 # 00006 # AUTHOR(S): Hamish Bowman (Otago University, New Zealand) 00007 # (original contributor, v.type.sh) 00008 # Pythonized by Martin Landa <landa.martin gmail.com> (2008/08) 00009 # 00010 # PURPOSE: Supply v.type options in a GUI compatible way 00011 # 00012 # COPYRIGHT: (C) 2007-2008 by Hamish Bowman, and the GRASS Development Team 00013 # 00014 # This program is free software under the GNU General Public 00015 # License (>=v2). Read the file COPYING that comes with GRASS 00016 # for details. 00017 # 00018 ############################################################################# 00019 00020 #%module 00021 #% description: Change the type of geometry elements. 00022 #% keywords: vector, geometry 00023 #%end 00024 00025 #%option 00026 #% key: input 00027 #% type: string 00028 #% required: yes 00029 #% multiple: no 00030 #% key_desc: name 00031 #% description: Name of input vector map 00032 #% gisprompt: old,vector,vector 00033 #%end 00034 00035 #%option 00036 #% key: output 00037 #% type: string 00038 #% required: yes 00039 #% multiple: no 00040 #% key_desc: name 00041 #% description: Name for output vector map 00042 #% gisprompt: new,vector,vector 00043 #%end 00044 00045 #%option 00046 #% key: type 00047 #% type: string 00048 #% required: no 00049 #% multiple: no 00050 #% 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 00051 #% description: Conversion 00052 #% answer: boundary to line 00053 #%end 00054 00055 import sys 00056 from grass.script import core as grass 00057 00058 def main(): 00059 if options['type'] == "point to centroid": 00060 type_cnv = "point,centroid" 00061 elif options['type'] == "point to kernel": 00062 type_cnv = "point,kernel" 00063 elif options['type'] == "centroid to point": 00064 type_cnv = "centroid,point" 00065 elif options['type'] == "centroid to kernel": 00066 type_cnv = "centroid,kernel" 00067 elif options['type'] == "kernel to point": 00068 type_cnv = "kernel,point" 00069 elif options['type'] == "kernel to centroid": 00070 type_cnv = "kernel,centroid" 00071 elif options['type'] == "line to boundary": 00072 type_cnv = "line,boundary" 00073 elif options['type'] == "line to face": 00074 type_cnv = "line,face" 00075 elif options['type'] == "boundary to line": 00076 type_cnv = "boundary,line" 00077 elif options['type'] == "boundary to face": 00078 type_cnv = "boundary,face" 00079 elif options['type'] == "face to line": 00080 type_cnv = "face,line" 00081 elif options['type'] == "face to boundary": 00082 type_cnv = "face,boundary" 00083 00084 options.pop('type') 00085 grass.exec_command("v.type", type = type_cnv, **options) 00086 00087 return 0 00088 00089 if __name__ == "__main__": 00090 options, flags = grass.parser() 00091 sys.exit(main())