r.out.xyz.py 1.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556
  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. #% keywords: raster
  21. #% keywords: export
  22. #% keywords: ASCII
  23. #% keywords: 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. def main():
  37. # if no output filename, output to stdout
  38. output = options['output']
  39. parameters = dict(flags="1gn",
  40. input=options['input'],
  41. separator=options['separator'])
  42. if output:
  43. parameters.update(output=output)
  44. ret = grass.run_command("r.stats", **parameters)
  45. sys.exit(ret)
  46. if __name__ == "__main__":
  47. options, flags = grass.parser()
  48. main()