d.to.rast.py 1.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748
  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. #% 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. def main():
  24. options, flags = gcore.parser()
  25. gisenv = gcore.gisenv()
  26. if 'MONITOR' in gisenv:
  27. cmd_file = gisenv['MONITOR_{monitor}_CMDFILE'.format(monitor=gisenv['MONITOR'].upper())]
  28. d_cmd = 'd.to.rast'
  29. for param, val in options.iteritems():
  30. if val:
  31. d_cmd += " {param}={val}".format(param=param, val=val)
  32. if gcore.overwrite():
  33. d_cmd += ' --overwrite'
  34. with open(cmd_file, "a") as file_:
  35. file_.write(d_cmd)
  36. else:
  37. gcore.fatal(_("No graphics device selected. Use d.mon to select graphics device."))
  38. if __name__ == "__main__":
  39. main()