v.type.py 2.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192
  1. #!/usr/bin/env python
  2. ############################################################################
  3. #
  4. # MODULE: v.type.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. #%module
  20. #% description: Change the type of geometry elements.
  21. #% keywords: vector, geometry
  22. #%end
  23. #%option
  24. #% key: input
  25. #% type: string
  26. #% required: yes
  27. #% multiple: no
  28. #% key_desc: name
  29. #% description: Name of input vector map
  30. #% gisprompt: old,vector,vector
  31. #%end
  32. #%option
  33. #% key: output
  34. #% type: string
  35. #% required: yes
  36. #% multiple: no
  37. #% key_desc: name
  38. #% description: Name for output vector map
  39. #% gisprompt: new,vector,vector
  40. #%end
  41. #%option
  42. #% key: type
  43. #% type: string
  44. #% required: no
  45. #% multiple: no
  46. #% 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
  47. #% description: Conversion
  48. #% answer: boundary to line
  49. #%end
  50. import grass
  51. import sys
  52. def main():
  53. if options['type'] == "point to centroid":
  54. type_cnv = "point,centroid"
  55. elif options['type'] == "point to kernel":
  56. type_cnv = "point,kernel"
  57. elif options['type'] == "centroid to point":
  58. type_cnv = "centroid,point"
  59. elif options['type'] == "centroid to kernel":
  60. type_cnv = "centroid,kernel"
  61. elif options['type'] == "kernel to point":
  62. type_cnv = "kernel,point"
  63. elif options['type'] == "kernel to centroid":
  64. type_cnv = "kernel,centroid"
  65. elif options['type'] == "line to boundary":
  66. type_cnv = "line,boundary"
  67. elif options['type'] == "line to face":
  68. type_cnv = "line,face"
  69. elif options['type'] == "boundary to line":
  70. type_cnv = "boundary,line"
  71. elif options['type'] == "boundary to face":
  72. type_cnv = "boundary,face"
  73. elif options['type'] == "face to line":
  74. type_cnv = "face,line"
  75. elif options['type'] == "face to boundary":
  76. type_cnv = "face,boundary"
  77. options.pop('type')
  78. grass.exec_command("v.type", type = type_cnv, **options)
  79. return 0
  80. if __name__ == "__main__":
  81. options, flags = grass.parser()
  82. sys.exit(main())