d.what.vect.py 1.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748
  1. #!/usr/bin/env python
  2. ############################################################################
  3. #
  4. # MODULE: d.what.vect
  5. # AUTHOR(S): Anna Petrasova <kratochanna gmail.com>
  6. # PURPOSE: Script for querying vector maps in d.mon
  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: Allows the user to interactively query vector map layers at user-selected locations.
  16. #% keyword: display
  17. #% keyword: vector
  18. #%end
  19. #%option G_OPT_V_INPUTS
  20. #% key: map
  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').get('cmd', None)
  28. if not cmd_file:
  29. gcore.fatal(_("Unable to open file '%s'") % cmd_file)
  30. dout_cmd = 'd.what.vect'
  31. for param, val in options.items():
  32. if val:
  33. dout_cmd += " {param}={val}".format(param=param, val=val)
  34. with open(cmd_file, "a") as file_:
  35. file_.write(dout_cmd)
  36. else:
  37. gcore.fatal(_("No graphics device selected. Use d.mon to select graphics device."))
  38. if __name__ == "__main__":
  39. main()