d.to.rast.py 1.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950
  1. #!/usr/bin/env python3
  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. def main():
  24. options, flags = gcore.parser()
  25. gisenv = gcore.gisenv()
  26. if "MONITOR" in gisenv:
  27. cmd_file = gcore.parse_command("d.mon", flags="g")["cmd"]
  28. d_cmd = "d.to.rast"
  29. for param, val in options.items():
  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(
  38. _("No graphics device selected. Use d.mon to select graphics device.")
  39. )
  40. if __name__ == "__main__":
  41. main()