v.in.sites.all.py 1.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950
  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, vector, import
  18. #%End
  19. import sys
  20. import grass
  21. def main():
  22. env = grass.gisenv()
  23. mapset = env['MAPSET']
  24. converted = 0
  25. ret = 0
  26. for site in grass.list_grouped('sites')[mapset]:
  27. inmap = "%s@%s" % (site, mapset)
  28. outmap = site.replace(".", "_") + "_points"
  29. grass.message("Processing %s -> %s" % (inmap, outmap))
  30. if grass.run_command("v.in.sites", input = inmap, output = outmap) == 0:
  31. converted += 1
  32. else:
  33. grass.warning("Error converting map %s to %s" % (inmap, outmap))
  34. ret = 1
  35. if converted < 1:
  36. grass.warning("No sites maps converted as no old sites maps present in current mapset.")
  37. else:
  38. grass.message("Total %u sites maps in current mapset converted to vector maps (original names extended by '_points')" % converted)
  39. grass.message("Please verify new vector map(s) before deleting old sites map(s).")
  40. sys.exit(ret)
  41. if __name__ == "__main__":
  42. options, flags = grass.parser()
  43. main()