r.out.xyz.py 1.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849
  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. #%end
  23. #%option G_OPT_R_INPUT
  24. #%end
  25. #%option G_OPT_F_OUTPUT
  26. #% description: Name for output file (if omitted or "-" output to stdout)
  27. #% required: no
  28. #%end
  29. #%option G_OPT_F_SEP
  30. #%end
  31. import sys
  32. from grass.script import core as grass
  33. def main():
  34. # if no output filename, output to stdout
  35. output = options['output']
  36. if output == "" or output == "-":
  37. outf = sys.stdout
  38. else:
  39. outf = file(output)
  40. ret = grass.run_command("r.stats", flags = "1gn", input = options['input'], fs = options['fs'], stdout = outf)
  41. sys.exit(ret)
  42. if __name__ == "__main__":
  43. options, flags = grass.parser()
  44. main()