2
/****************************************************************************
5
* AUTHOR(S): Michael Shapiro (CERL) (original contributor)
6
* Markus Neteler <neteler itc.it>,
7
* Andreas Lange <andreas.lange rhein-main.de>,
8
* Bernhard Reiter <bernhard intevation.de>,
9
* Huidae Cho <grass4u gmail.com>,
10
* Eric G. Miller <egm2 jps.net>,
11
* Glynn Clements <glynn gclements.plus.com>,
12
* Hamish Bowman <hamish_b yahoo.com>
13
* PURPOSE: interactive query of cat/label of raster map in display
14
* COPYRIGHT: (C) 1999-2006 by the GRASS Development Team
16
* This program is free software under the GNU General Public
17
* License (>=v2). Read the file COPYING that comes with GRASS
20
*****************************************************************************/
25
#include <grass/display.h>
26
#include <grass/raster.h>
27
#include <grass/glocale.h>
28
#include "local_proto.h"
30
struct Categories *cats;
37
int main(int argc, char **argv)
39
struct Cell_head window;
44
struct Flag *once, *terse, *colrow;
45
struct Option *opt1, *fs;
46
struct GModule *module;
48
/* Initialize the GIS calls */
51
module = G_define_module();
52
module->keywords = _("display, raster");
54
_("Allows the user to interactively query the category contents "
55
"of multiple raster map layers at user specified locations "
56
"within the current geographic region.");
59
/* Don't fail initially if driver open fails, and don't let call kill
60
* us -- set quiet mode
63
if (R_open_driver() == 0) {
64
if (D_get_cell_list(&rast, &nrasts) < 0)
67
rast = (char **)G_realloc(rast, (nrasts + 1) * sizeof(char *));
73
opt1 = G_define_option();
75
opt1->type = TYPE_STRING;
80
opt1->gisprompt = "old,cell,raster";
81
opt1->description = _("Name of existing raster map(s)");
82
opt1->key_desc = "name";
84
fs = G_define_option();
86
fs->type = TYPE_STRING;
89
fs->description = _("Field separator (terse mode only)");
90
fs->key_desc = "character";
92
once = G_define_flag();
94
once->description = _("Identify just one location");
96
terse = G_define_flag();
98
terse->description = _("Terse output. For parsing by programs");
100
colrow = G_define_flag();
102
colrow->description =
103
_("Print out col/row for the entire map in grid resolution of the region");
106
opt1->required = YES;
108
if ((argc > 1 || !rast) && G_parser(argc, argv))
112
if (opt1->answers && opt1->answers[0])
113
rast = opt1->answers;
115
if (R_open_driver() != 0)
116
G_fatal_error(_("No graphics device selected"));
118
if (D_get_cur_wind(temp))
119
G_fatal_error(_("No current graphics window"));
121
if (D_set_cur_wind(temp))
122
G_fatal_error(_("Current graphics window not available"));
124
/* Read in the map window associated with window */
125
G_get_window(&window);
127
if (D_check_map_window(&window))
128
G_fatal_error(_("Setting graphics window"));
130
if (G_set_window(&window) == -1)
131
G_fatal_error(_("Can't set current graphics window"));
133
/* Determine conversion factors */
134
if (D_get_screen_window(&t, &b, &l, &r))
135
G_fatal_error(_("Getting graphics window coordinates"));
136
if (D_do_conversions(&window, t, b, l, r))
137
G_fatal_error(_("Error in calculating conversions"));
141
for (i = 0; rast[i]; i++) ;
144
fd = (int *)G_malloc(nrasts * sizeof(int));
145
name = (char **)G_malloc(nrasts * sizeof(char *));
146
mapset = (char **)G_malloc(nrasts * sizeof(char *));
148
(struct Categories *)G_malloc(nrasts * sizeof(struct Categories));
150
for (i = 0; i < nrasts; i++) {
151
name[i] = (char *)G_malloc(GNAME_MAX);
152
mapset[i] = (char *)G_malloc(GMAPSET_MAX);
154
if ((fd[i] = opencell(rast[i], name[i], mapset[i])) < 0)
155
G_fatal_error(_("Raster map <%s> not found"), rast[i]);
161
j = strlen(mapset[i]);
165
if (G_read_cats(name[i], mapset[i], &cats[i]) < 0)
170
what(once->answer, terse->answer, colrow->answer, fs->answer, width,