d.to.rast.py 1.4 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-2015 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. #% keyword: display
  17. #% keyword: export
  18. #% keyword: raster
  19. #%end
  20. #%option G_OPT_R_OUTPUT
  21. #%end
  22. from grass.script import core as gcore
  23. # i18N
  24. import os
  25. import gettext
  26. gettext.install('grassmods', os.path.join(os.getenv("GISBASE"), 'locale'))
  27. def main():
  28. options, flags = gcore.parser()
  29. gisenv = gcore.gisenv()
  30. if 'MONITOR' in gisenv:
  31. cmd_file = gcore.parse_command('d.mon', flags='g')['cmd']
  32. d_cmd = 'd.to.rast'
  33. for param, val in options.items():
  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()