v.centroids.py 1.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970
  1. #!/usr/bin/env python3
  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 grass.script as gscript
  46. def main():
  47. if options["option"] == "add":
  48. num_bound = gscript.vector_info_topo(map=options["input"])["boundaries"]
  49. if num_bound == 0:
  50. gscript.fatal(_("Input vector map contains no boundaries."))
  51. gscript.run_command("v.category", type="area", **options)
  52. sys.exit(0)
  53. if __name__ == "__main__":
  54. options, flags = gscript.parser()
  55. main()