r.out.xyz.py 1.8 KB

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