v.in.sites.all.py 1.7 KB

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