v.centroids.py 1.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970
  1. #!/usr/bin/env python
  2. ############################################################################
  3. #
  4. # MODULE: v.centroids
  5. # AUTHOR: Hamish Bowman
  6. # PURPOSE: Add missing centroids (frontend to v.category opt=add)
  7. # COPYRIGHT: (c) 2006 Hamish Bowman, and the GRASS Development Team
  8. # This program is free software under the GNU General Public
  9. # License (>=v2). Read the file COPYING that comes with GRASS
  10. # for details.
  11. #
  12. #############################################################################
  13. #%Module
  14. #% description: Adds missing centroids to closed boundaries.
  15. #% keyword: vector
  16. #% keyword: centroid
  17. #% keyword: area
  18. #%End
  19. #%option G_OPT_V_INPUT
  20. #%end
  21. #%option G_OPT_V_OUTPUT
  22. #%end
  23. #%option
  24. #% key: option
  25. #% type: string
  26. #% description: Action to be taken
  27. #% options: add
  28. #% answer: add
  29. #% required: no
  30. #%end
  31. #%option G_OPT_V_FIELD
  32. #%end
  33. #%option G_OPT_V_CAT
  34. #% description: Category number starting value
  35. #% answer: 1
  36. #%end
  37. #%option
  38. #% key: step
  39. #% type: integer
  40. #% description: Category increment
  41. #% answer: 1
  42. #% required: no
  43. #%end
  44. import sys
  45. import os
  46. import re
  47. import grass.script as grass
  48. def main():
  49. if options['option'] == 'add':
  50. num_bound = grass.vector_info_topo(map = options['input'])['boundaries']
  51. if num_bound == 0:
  52. grass.fatal(_("Input vector map contains no boundaries."))
  53. grass.run_command("v.category", type = 'area', **options)
  54. sys.exit(0)
  55. if __name__ == "__main__":
  56. options, flags = grass.parser()
  57. main()