~ubuntu-branches/ubuntu/wily/grass/wily

« back to all changes in this revision

Viewing changes to raster/r.patch/main.c

Tags: 7.0.0~rc1+ds1-1~exp1
* New upstream release candidate.
* Repack upstream tarball, remove precompiled Python objects.
* Add upstream metadata.
* Update gbp.conf and Vcs-Git URL to use the experimental branch.
* Update watch file for GRASS 7.0.
* Drop build dependencies for Tcl/Tk, add build dependencies:
  python-numpy, libnetcdf-dev, netcdf-bin, libblas-dev, liblapack-dev
* Update Vcs-Browser URL to use cgit instead of gitweb.
* Update paths to use grass70.
* Add configure options: --with-netcdf, --with-blas, --with-lapack,
  remove --with-tcltk-includes.
* Update patches for GRASS 7.
* Update copyright file, changes:
  - Update copyright years
  - Group files by license
  - Remove unused license sections
* Add patches for various typos.
* Fix desktop file with patch instead of d/rules.
* Use minimal dh rules.
* Bump Standards-Version to 3.9.6, no changes.
* Use dpkg-maintscript-helper to replace directories with symlinks.
  (closes: #776349)
* Update my email to use @debian.org address.

Show diffs side-by-side

added added

removed removed

Lines of Context:
3
3
 *
4
4
 * MODULE:       r.patch
5
5
 * AUTHOR(S):    Michael Shapiro, CERL (original contributor)
6
 
 *               Hamish Bowman <hamish_nospam yahoo.com>, Markus Neteler <neteler itc.it>
 
6
 *               Hamish Bowman <hamish_b yahoo.com>, Markus Neteler <neteler itc.it>
7
7
 *               Glynn Clements <glynn gclements.plus.com>, Jachym Cepicky <jachym les-ejk.cz>,
8
8
 *               Jan-Oliver Wagner <jan intevation.de>
9
9
 * PURPOSE:      
17
17
#include <stdlib.h>
18
18
#include <unistd.h>
19
19
#include <grass/gis.h>
 
20
#include <grass/raster.h>
20
21
#include <grass/glocale.h>
21
22
#include "local_proto.h"
22
23
 
35
36
    int nfiles;
36
37
    char *rname;
37
38
    int i;
38
 
    int ok;
39
39
    int row, nrows, ncols;
40
 
    int ZEROFLAG;
 
40
    int use_zero;
41
41
    char *new_name;
42
42
    char **names;
43
43
    char **ptr;
 
44
    struct Cell_head window;
 
45
    struct Cell_head *cellhd;
44
46
 
45
47
    struct GModule *module;
46
 
    struct Flag *flag1;
47
48
    struct Flag *zeroflag;
48
49
    struct Option *opt1, *opt2;
49
50
 
50
51
    G_gisinit(argv[0]);
51
52
 
52
53
    module = G_define_module();
53
 
    module->keywords = _("raster");
 
54
    G_add_keyword(_("raster"));
 
55
    G_add_keyword(_("geometry"));
 
56
    G_add_keyword(_("mosaicking"));
54
57
    module->description =
55
58
        _("Creates a composite raster map layer by using "
56
59
          "known category values from one (or more) map layer(s) "
66
69
 
67
70
    /* Define the different flags */
68
71
 
69
 
    /* please, remove before GRASS 7 released */
70
 
    flag1 = G_define_flag();
71
 
    flag1->key = 'q';
72
 
    flag1->description = _("Quiet");
73
 
 
74
72
    zeroflag = G_define_flag();
75
73
    zeroflag->key = 'z';
76
74
    zeroflag->description =
77
75
        _("Use zero (0) for transparency instead of NULL");
78
76
 
79
 
    ZEROFLAG = 0;               /* default: use NULL for transparency */
80
 
 
81
77
    if (G_parser(argc, argv))
82
78
        exit(EXIT_FAILURE);
83
79
 
84
 
    /* please, remove before GRASS 7 released */
85
 
    if (flag1->answer) {
86
 
        putenv("GRASS_VERBOSE=0");
87
 
        G_warning(_("The '-q' flag is superseded and will be removed "
88
 
                    "in future. Please use '--quiet' instead."));
89
 
    }
90
 
 
91
 
 
92
 
    ZEROFLAG = (zeroflag->answer);
93
 
 
94
 
    ok = 1;
 
80
    use_zero = (zeroflag->answer);
 
81
 
95
82
    names = opt1->answers;
96
83
 
97
84
    out_type = CELL_TYPE;
103
90
 
104
91
    infd = G_malloc(nfiles * sizeof(int));
105
92
    statf = G_malloc(nfiles * sizeof(struct Cell_stats));
 
93
    cellhd = G_malloc(nfiles * sizeof(struct Cell_head));
106
94
 
107
95
    for (i = 0; i < nfiles; i++) {
108
96
        const char *name = names[i];
109
 
        const char *mapset = G_find_cell2(name, "");
110
97
        int fd;
111
98
 
112
 
        if (mapset == NULL) {
113
 
            G_warning(_("Raster map <%s> not found"), name);
114
 
            G_sleep(3);
115
 
            ok = 0;
116
 
        }
117
 
 
118
 
        if (!ok)
119
 
            continue;
120
 
 
121
 
        fd = G_open_cell_old(name, mapset);
122
 
        if (fd < 0) {
123
 
            ok = 0;
124
 
            continue;
125
 
        }
 
99
        fd = Rast_open_old(name, "");
126
100
 
127
101
        infd[i] = fd;
128
102
 
129
 
        map_type = G_get_raster_map_type(fd);
 
103
        map_type = Rast_get_map_type(fd);
130
104
        if (map_type == FCELL_TYPE && out_type == CELL_TYPE)
131
105
            out_type = FCELL_TYPE;
132
106
        else if (map_type == DCELL_TYPE)
133
107
            out_type = DCELL_TYPE;
134
108
 
135
 
        G_init_cell_stats(&statf[i]);
 
109
        Rast_init_cell_stats(&statf[i]);
 
110
 
 
111
        Rast_get_cellhd(name, "", &cellhd[i]);
136
112
    }
137
113
 
138
 
    if (!ok)
139
 
        G_fatal_error(_("One or more input raster maps not found"));
140
 
 
141
114
    rname = opt2->answer;
142
 
    outfd = G_open_raster_new(new_name = rname, out_type);
143
 
    if (outfd < 0)
144
 
        G_fatal_error(_("Unable to create raster map <%s>"), new_name);
145
 
 
146
 
    presult = G_allocate_raster_buf(out_type);
147
 
    patch = G_allocate_raster_buf(out_type);
148
 
 
149
 
    nrows = G_window_rows();
150
 
    ncols = G_window_cols();
 
115
    outfd = Rast_open_new(new_name = rname, out_type);
 
116
 
 
117
    presult = Rast_allocate_buf(out_type);
 
118
    patch = Rast_allocate_buf(out_type);
 
119
 
 
120
    Rast_get_window(&window);
 
121
    nrows = Rast_window_rows();
 
122
    ncols = Rast_window_cols();
151
123
 
152
124
    G_verbose_message(_("Percent complete..."));
153
125
    for (row = 0; row < nrows; row++) {
 
126
        double north_edge, south_edge;
 
127
 
154
128
        G_percent(row, nrows, 2);
155
 
        if (G_get_raster_row(infd[0], presult, row, out_type) < 0)
156
 
            G_fatal_error(_("Unable to read raster map <%s> row %d"),
157
 
                          names[0], row);
 
129
        Rast_get_row(infd[0], presult, row, out_type);
 
130
 
 
131
        north_edge = Rast_row_to_northing(row, &window);
 
132
        south_edge = north_edge - window.ns_res;
158
133
 
159
134
        if (out_type == CELL_TYPE)
160
 
            G_update_cell_stats((CELL *) presult, ncols, &statf[0]);
 
135
            Rast_update_cell_stats((CELL *) presult, ncols, &statf[0]);
161
136
        for (i = 1; i < nfiles; i++) {
162
 
            if (G_get_raster_row(infd[i], patch, row, out_type) < 0)
163
 
                G_fatal_error(_("Unable to read raster map <%s> row %d"),
164
 
                              names[i], row);
 
137
            /* check if raster i overlaps with the current row */
 
138
            if (south_edge >= cellhd[i].north ||
 
139
                north_edge <= cellhd[i].south ||
 
140
                window.west >= cellhd[i].east ||
 
141
                window.east <= cellhd[i].west)
 
142
                continue;
 
143
 
 
144
            Rast_get_row(infd[i], patch, row, out_type);
165
145
            if (!do_patch
166
 
                (presult, patch, &statf[i], ncols, out_type, ZEROFLAG))
 
146
                (presult, patch, &statf[i], ncols, out_type, use_zero))
167
147
                break;
168
148
        }
169
 
        G_put_raster_row(outfd, presult, out_type);
 
149
        Rast_put_row(outfd, presult, out_type);
170
150
    }
171
151
    G_percent(row, nrows, 2);
172
152
 
173
153
    G_free(patch);
174
154
    G_free(presult);
175
155
    for (i = 0; i < nfiles; i++)
176
 
        G_close_cell(infd[i]);
 
156
        Rast_close(infd[i]);
177
157
    /* 
178
158
     * build the new cats and colors. do this before closing the new
179
159
     * file, in case the new file is one of the patching files as well.
180
160
     */
181
 
    G_message(_("Creating support files for raster map <%s>"), new_name);
 
161
    G_verbose_message(_("Creating support files for raster map <%s>..."), new_name);
182
162
    support(names, statf, nfiles, &cats, &cats_ok, &colr, &colr_ok, out_type);
183
163
 
184
164
    /* now close (and create) the result */
185
 
    G_close_cell(outfd);
 
165
    Rast_close(outfd);
186
166
    if (cats_ok)
187
 
        G_write_cats(new_name, &cats);
 
167
        Rast_write_cats(new_name, &cats);
188
168
    if (colr_ok)
189
 
        G_write_colors(new_name, G_mapset(), &colr);
 
169
        Rast_write_colors(new_name, G_mapset(), &colr);
190
170
 
191
 
    G_short_history(new_name, "raster", &history);
192
 
    G_command_history(&history);
193
 
    G_write_history(new_name, &history);
 
171
    Rast_short_history(new_name, "raster", &history);
 
172
    Rast_command_history(&history);
 
173
    Rast_write_history(new_name, &history);
194
174
 
195
175
    exit(EXIT_SUCCESS);
196
176
}