1#!/usr/local/bin/python3.8
2
3############################################################################
4#
5# MODULE:    d.what.rast
6# AUTHOR(S): Anna Petrasova <kratochanna gmail.com>
7# PURPOSE:   Script for querying raster maps in d.mon
8# COPYRIGHT: (C) 2014-2015 by the GRASS Development Team
9#
10#		This program is free software under the GNU General
11#		Public License (>=v2). Read the file COPYING that
12#		comes with GRASS for details.
13#
14#############################################################################
15
16#%module
17#% description: Allows the user to interactively query raster map layers at user-selected locations.
18#% keyword: display
19#% keyword: vector
20#%end
21#%option G_OPT_R_INPUTS
22#% key: map
23#%end
24
25
26from grass.script import core as gcore
27
28
29def main():
30    options, flags = gcore.parser()
31    gisenv = gcore.gisenv()
32    if 'MONITOR' in gisenv:
33        cmd_file = gcore.parse_command('d.mon', flags='g').get('cmd', None)
34        if not cmd_file:
35            gcore.fatal(_("Unable to open file '%s'") % cmd_file)
36        dout_cmd = 'd.what.rast'
37        for param, val in options.items():
38            if val:
39                dout_cmd += " {param}={val}".format(param=param, val=val)
40        with open(cmd_file, "a") as file_:
41            file_.write(dout_cmd)
42    else:
43        gcore.fatal(_("No graphics device selected. Use d.mon to select graphics device."))
44
45
46if __name__ == "__main__":
47    main()
48