d.to.rast.py 1.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253
  1. #!/usr/bin/env python
  2. ############################################################################
  3. #
  4. # MODULE: d.to.rast
  5. # AUTHOR(S): Anna Petrasova <kratochanna gmail.com>
  6. # PURPOSE: Script for exporting content of monitor to raster map
  7. # COPYRIGHT: (C) 2014 by the GRASS Development Team
  8. #
  9. # This program is free software under the GNU General
  10. # Public License (>=v2). Read the file COPYING that
  11. # comes with GRASS for details.
  12. #
  13. #############################################################################
  14. #%module
  15. #% description: Saves the contents of the active display monitor to a raster map.
  16. #% keywords: display
  17. #% keywords: export
  18. #% keywords: raster
  19. #%end
  20. #%option G_OPT_R_OUTPUT
  21. #%end
  22. from grass.script import core as gcore
  23. def main():
  24. env = gcore.gisenv()
  25. mon = env.get('MONITOR', None)
  26. if not mon:
  27. gcore.fatal(_("No graphics device selected. Use d.mon to select graphics device."))
  28. options, flags = gcore.parser()
  29. gisenv = gcore.gisenv()
  30. if 'MONITOR' in gisenv:
  31. cmd_file = gisenv['MONITOR_{monitor}_CMDFILE'.format(monitor=gisenv['MONITOR'].upper())]
  32. d_cmd = 'd.to.rast'
  33. for param, val in options.iteritems():
  34. if val:
  35. d_cmd += " {param}={val}".format(param=param, val=val)
  36. if gcore.overwrite():
  37. d_cmd += ' --overwrite'
  38. with open(cmd_file, "a") as file_:
  39. file_.write(d_cmd)
  40. else:
  41. gcore.fatal(_("No graphics device selected. Use d.mon to select graphics device."))
  42. if __name__ == "__main__":
  43. main()