v.build.all.py 1.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657
  1. #!/usr/bin/env python
  2. ############################################################################
  3. #
  4. # MODULE: v.build.all
  5. # AUTHOR(S): Glynn Clements, Radim Blazek
  6. # PURPOSE: Build all vectors in current mapset
  7. # COPYRIGHT: (C) 2004, 2008-2009 by the GRASS Development Team
  8. #
  9. # This program is free software under the GNU General Public
  10. # License (>=v2). Read the file COPYING that comes with GRASS
  11. # for details.
  12. #
  13. #############################################################################
  14. #%module
  15. #% description: Rebuilds topology on all vector maps in the current mapset.
  16. #% keyword: vector
  17. #% keyword: topology
  18. #%end
  19. import sys
  20. from grass.script import core as grass
  21. from grass.exceptions import CalledModuleError
  22. def main():
  23. env = grass.gisenv()
  24. mapset = env['MAPSET']
  25. ret = 0
  26. vectors = grass.list_grouped('vect')[mapset]
  27. num_vectors = len(vectors)
  28. if grass.verbosity() < 2:
  29. quiet = True
  30. else:
  31. quiet = False
  32. i = 1
  33. for vect in vectors:
  34. map = "%s@%s" % (vect, mapset)
  35. grass.message(_("%s\nBuilding topology for vector map <%s> (%d of %d)...\n%s") % \
  36. ('-' * 80, map, i, num_vectors, '-' * 80))
  37. grass.verbose(_("v.build map=%s") % map)
  38. try:
  39. grass.run_command("v.build", map=map, quiet=quiet)
  40. except CalledModuleError:
  41. grass.error(_("Building topology for vector map <%s> failed") % map)
  42. ret = 1
  43. i += 1
  44. return ret
  45. if __name__ == "__main__":
  46. options, flags = grass.parser()
  47. sys.exit(main())