r.rgb.py 1.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162
  1. #!/usr/bin/env python
  2. ############################################################################
  3. #
  4. # MODULE: r.rgb
  5. # AUTHOR(S): Glynn Clements
  6. # PURPOSE: Split a raster map into red, green and blue maps
  7. # COPYRIGHT: (C) 2009 Glynn Clements and the GRASS Development Team
  8. #
  9. # This program is free software under the GNU General Public
  10. # License (>=v2). Read the file COPYING that comes with GRASS
  11. # for details.
  12. #
  13. #############################################################################
  14. #% Module
  15. #% description: Split a raster map into red, green and blue maps
  16. #% keywords: raster
  17. #% End
  18. #% option
  19. #% key: input
  20. #% type: string
  21. #% gisprompt: old,cell,raster
  22. #% description: Input map
  23. #% required : yes
  24. #% end
  25. #% option
  26. #% key: output
  27. #% type: string
  28. #% description: Base name for output maps
  29. #% required : no
  30. #% end
  31. import sys
  32. import os
  33. import string
  34. from grass.script import core, raster as grass
  35. def main():
  36. input = options['input']
  37. output = options['output']
  38. if not grass.find_file(input)['file']:
  39. grass.fatal("Map <%s> not found." % input)
  40. if not output:
  41. output = input
  42. expr = ';'.join(["${output}.r = r#${input}",
  43. "${output}.g = g#${input}",
  44. "${output}.b = b#${input}"])
  45. grass.mapcalc(expr, input = input, output = output)
  46. for ch in ['r', 'g', 'b']:
  47. name = "%s.%s" % (output, ch)
  48. grass.run_command('r.colors', map = name, color = 'grey255')
  49. grass.raster_history(name)
  50. if __name__ == "__main__":
  51. options, flags = grass.parser()
  52. main()