v.convert.all.py 1.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152
  1. #!/usr/bin/env python
  2. #
  3. ############################################################################
  4. #
  5. # MODULE: v.convert.all
  6. # AUTHOR(S): Markus Neteler, converted to Python by Glynn Clements
  7. # PURPOSE: converts all old GRASS < V5.7 vector maps to current format
  8. # in current mapset
  9. # COPYRIGHT: (C) 2004, 2008 by the GRASS Development Team
  10. #
  11. # This program is free software under the GNU General Public
  12. # License (>=v2). Read the file COPYING that comes with GRASS
  13. # for details.
  14. #
  15. #############################################################################
  16. #%module
  17. #% description: Converts all older versions of GRASS vector maps in current mapset to current format.
  18. #% keywords: vector
  19. #% keywords: import
  20. #% keywords: conversion
  21. #%end
  22. import sys
  23. from grass.script import core as grass
  24. def main():
  25. env = grass.gisenv()
  26. mapset = env['MAPSET']
  27. converted = 0
  28. ret = 0
  29. for vect in grass.list_grouped('oldvect')[mapset]:
  30. inmap = "%s@%s" % (vect, mapset)
  31. outmap = vect.replace(".", "_")
  32. if grass.run_command("v.convert", input = inmap, output = outmap) == 0:
  33. converted += 1
  34. else:
  35. grass.warning(_("Error converting map <%s> to <%s>") % (inmap, outmap))
  36. ret = 1
  37. if converted < 1:
  38. grass.warning(_("No vector maps converted as no old vector maps present in current mapset."))
  39. else:
  40. grass.message(_("Total %u vector maps in current mapset converted.") % converted)
  41. grass.message(_("Please verify new vector map(s) before deleting old vector map(s)."))
  42. sys.exit(ret)
  43. if __name__ == "__main__":
  44. options, flags = grass.parser()
  45. main()