r.out.xyz.py 1.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061
  1. #!/usr/bin/env python
  2. ############################################################################
  3. #
  4. # MODULE: r.out.xyz
  5. # AUTHOR: M. Hamish Bowman, Dept. Marine Science, Otago Univeristy,
  6. # New Zealand
  7. # Converted to Python by Glynn Clements
  8. # PURPOSE: Export a raster map as x,y,z values based on cell centers
  9. # This is a simple wrapper script for "r.stats -1ng"
  10. #
  11. # COPYRIGHT: (c) 2006 Hamish Bowman, and the GRASS Development Team
  12. # (c) 2008 Glynn Clements, and the GRASS Development Team
  13. # This program is free software under the GNU General Public
  14. # License (>=v2). Read the file COPYING that comes with GRASS
  15. # for details.
  16. #
  17. #############################################################################
  18. #%module
  19. #% description: Exports a raster map to a text file as x,y,z values based on cell centers.
  20. #% keyword: raster
  21. #% keyword: export
  22. #% keyword: ASCII
  23. #% keyword: conversion
  24. #%end
  25. #%option G_OPT_R_INPUTS
  26. #% multiple: yes
  27. #%end
  28. #%option G_OPT_F_OUTPUT
  29. #% description: Name for output file (if omitted or "-" output to stdout)
  30. #% required: no
  31. #%end
  32. #%option G_OPT_F_SEP
  33. #%end
  34. import sys
  35. from grass.script import core as grass
  36. from grass.exceptions import CalledModuleError
  37. def main():
  38. # if no output filename, output to stdout
  39. output = options['output']
  40. parameters = dict(flags="1gn",
  41. input=options['input'],
  42. separator=options['separator'])
  43. if output:
  44. parameters.update(output=output)
  45. ret = 0
  46. try:
  47. grass.run_command("r.stats", **parameters)
  48. except CalledModuleError:
  49. ret = 1
  50. sys.exit(ret)
  51. if __name__ == "__main__":
  52. options, flags = grass.parser()
  53. main()