r.out.xyz.py 1.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364
  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: Export a raster map to a text file as x,y,z values based on cell centers.
  20. #% keywords: raster, export
  21. #%End
  22. #%option
  23. #% key: input
  24. #% type: string
  25. #% gisprompt: old,cell,raster
  26. #% key_desc: name
  27. #% description: Name of input raster map
  28. #% required: yes
  29. #%end
  30. #%option
  31. #% key: output
  32. #% type: string
  33. #% gisprompt: new_file,file,output
  34. #% key_desc: name
  35. #% description: Name for output file (if omitted or "-" output to stdout)
  36. #% required: no
  37. #%end
  38. #%option
  39. #% key: fs
  40. #% type: string
  41. #% key_desc: character
  42. #% description: Field separator
  43. #% answer: |
  44. #% required: no
  45. #%end
  46. import sys
  47. from grass.script import core as grass
  48. def main():
  49. # if no output filename, output to stdout
  50. output = options['output']
  51. if output == "" or output == "-":
  52. outf = sys.stdout
  53. else:
  54. outf = file(output)
  55. ret = grass.run_command("r.stats", flags = "1gn", input = options['input'], fs = options['fs'], stdout = outf)
  56. sys.exit(ret)
  57. if __name__ == "__main__":
  58. options, flags = grass.parser()
  59. main()