~ubuntu-branches/ubuntu/vivid/grass/vivid-proposed

« back to all changes in this revision

Viewing changes to display/d.what.rast/main.c

  • Committer: Package Import Robot
  • Author(s): Bas Couwenberg
  • Date: 2015-02-20 23:12:08 UTC
  • mfrom: (8.2.6 experimental)
  • Revision ID: package-import@ubuntu.com-20150220231208-1u6qvqm84v430b10
Tags: 7.0.0-1~exp1
* New upstream release.
* Update python-ctypes-ternary.patch to use if/else instead of and/or.
* Drop check4dev patch, rely on upstream check.
* Add build dependency on libpq-dev to grass-dev for libpq-fe.h.
* Drop patches applied upstream, refresh remaining patches.
* Update symlinks for images switched from jpg to png.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
 
2
 
/****************************************************************************
3
 
 *
4
 
 * MODULE:       d.what.rast
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
15
 
 *
16
 
 *               This program is free software under the GNU General Public
17
 
 *               License (>=v2). Read the file COPYING that comes with GRASS
18
 
 *               for details.
19
 
 *
20
 
 *****************************************************************************/
21
 
 
22
 
#include <stdlib.h>
23
 
#include <string.h>
24
 
#include "what.h"
25
 
#include <grass/display.h>
26
 
#include <grass/raster.h>
27
 
#include <grass/glocale.h>
28
 
#include "local_proto.h"
29
 
 
30
 
struct Categories *cats;
31
 
int *fd;
32
 
char **rast;
33
 
int nrasts;
34
 
char **name;
35
 
char **mapset;
36
 
 
37
 
int main(int argc, char **argv)
38
 
{
39
 
    struct Cell_head window;
40
 
    char temp[128];
41
 
    int t, b, l, r;
42
 
    int i, j;
43
 
    int width, mwidth;
44
 
    struct Flag *once, *terse, *colrow;
45
 
    struct Option *opt1, *fs;
46
 
    struct GModule *module;
47
 
 
48
 
    /* Initialize the GIS calls */
49
 
    G_gisinit(argv[0]);
50
 
 
51
 
    module = G_define_module();
52
 
    module->keywords = _("display, raster");
53
 
    module->description =
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.");
57
 
 
58
 
 
59
 
    /* Don't fail initially if driver open fails, and don't let call kill
60
 
     * us -- set quiet mode
61
 
     */
62
 
    R__open_quiet();
63
 
    if (R_open_driver() == 0) {
64
 
        if (D_get_cell_list(&rast, &nrasts) < 0)
65
 
            rast = NULL;
66
 
        else {
67
 
            rast = (char **)G_realloc(rast, (nrasts + 1) * sizeof(char *));
68
 
            rast[nrasts] = NULL;
69
 
        }
70
 
        R_close_driver();
71
 
    }
72
 
 
73
 
    opt1 = G_define_option();
74
 
    opt1->key = "map";
75
 
    opt1->type = TYPE_STRING;
76
 
    opt1->required = NO;
77
 
    opt1->multiple = YES;
78
 
    if (rast)
79
 
        opt1->answers = rast;
80
 
    opt1->gisprompt = "old,cell,raster";
81
 
    opt1->description = _("Name of existing raster map(s)");
82
 
    opt1->key_desc = "name";
83
 
 
84
 
    fs = G_define_option();
85
 
    fs->key = "fs";
86
 
    fs->type = TYPE_STRING;
87
 
    fs->required = NO;
88
 
    fs->answer = ":";
89
 
    fs->description = _("Field separator (terse mode only)");
90
 
    fs->key_desc = "character";
91
 
 
92
 
    once = G_define_flag();
93
 
    once->key = '1';
94
 
    once->description = _("Identify just one location");
95
 
 
96
 
    terse = G_define_flag();
97
 
    terse->key = 't';
98
 
    terse->description = _("Terse output. For parsing by programs");
99
 
 
100
 
    colrow = G_define_flag();
101
 
    colrow->key = 'c';
102
 
    colrow->description =
103
 
        _("Print out col/row for the entire map in grid resolution of the region");
104
 
 
105
 
    if (!rast)
106
 
        opt1->required = YES;
107
 
 
108
 
    if ((argc > 1 || !rast) && G_parser(argc, argv))
109
 
        exit(EXIT_FAILURE);
110
 
 
111
 
 
112
 
    if (opt1->answers && opt1->answers[0])
113
 
        rast = opt1->answers;
114
 
 
115
 
    if (R_open_driver() != 0)
116
 
        G_fatal_error(_("No graphics device selected"));
117
 
 
118
 
    if (D_get_cur_wind(temp))
119
 
        G_fatal_error(_("No current graphics window"));
120
 
 
121
 
    if (D_set_cur_wind(temp))
122
 
        G_fatal_error(_("Current graphics window not available"));
123
 
 
124
 
    /* Read in the map window associated with window */
125
 
    G_get_window(&window);
126
 
 
127
 
    if (D_check_map_window(&window))
128
 
        G_fatal_error(_("Setting graphics window"));
129
 
 
130
 
    if (G_set_window(&window) == -1)
131
 
        G_fatal_error(_("Can't set current graphics window"));
132
 
 
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"));
138
 
 
139
 
    width = mwidth = 0;
140
 
    if (rast) {
141
 
        for (i = 0; rast[i]; i++) ;
142
 
        nrasts = i;
143
 
 
144
 
        fd = (int *)G_malloc(nrasts * sizeof(int));
145
 
        name = (char **)G_malloc(nrasts * sizeof(char *));
146
 
        mapset = (char **)G_malloc(nrasts * sizeof(char *));
147
 
        cats =
148
 
            (struct Categories *)G_malloc(nrasts * sizeof(struct Categories));
149
 
 
150
 
        for (i = 0; i < nrasts; i++) {
151
 
            name[i] = (char *)G_malloc(GNAME_MAX);
152
 
            mapset[i] = (char *)G_malloc(GMAPSET_MAX);
153
 
 
154
 
            if ((fd[i] = opencell(rast[i], name[i], mapset[i])) < 0)
155
 
                G_fatal_error(_("Raster map <%s> not found"), rast[i]);
156
 
 
157
 
            j = strlen(name[i]);
158
 
            if (j > width)
159
 
                width = j;
160
 
 
161
 
            j = strlen(mapset[i]);
162
 
            if (j > mwidth)
163
 
                mwidth = j;
164
 
 
165
 
            if (G_read_cats(name[i], mapset[i], &cats[i]) < 0)
166
 
                cats[i].ncats = -1;
167
 
        }
168
 
    }
169
 
 
170
 
    what(once->answer, terse->answer, colrow->answer, fs->answer, width,
171
 
         mwidth);
172
 
 
173
 
    R_close_driver();
174
 
    exit(EXIT_SUCCESS);
175
 
}