GRASS 8 Programmer's Manual 8.6.0dev(2026)-1d1e47ad9d
Loading...
Searching...
No Matches
raster/set_window.c
Go to the documentation of this file.
1/*!
2 * \file lib/raster/set_window.c
3 *
4 * \brief Raster Library - Set window (map region)
5 *
6 * (C) 2001-2009 by the GRASS Development Team
7 *
8 * This program is free software under the GNU General Public License
9 * (>=v2). Read the file COPYING that comes with GRASS for details.
10 *
11 * \author Original author CERL
12 */
13
14#include <grass/gis.h>
15#include <grass/raster.h>
16#include <grass/glocale.h>
17
18#include "../gis/G.h"
19#include "R.h"
20
21static void update_window_mappings(void);
22static void check_write_window(void);
23
37
38/*!
39 * \brief Establishes 'window' as the current working window.
40 *
41 * \param window window to become operative window
42 */
43void Rast_set_window(struct Cell_head *window)
44{
45 Rast__init();
46
47 if (R__.split_window)
48 G_warning(_("Rast_set_window() called while window split"));
49
50 check_write_window();
51
52 G_adjust_Cell_head(window, 0, 0);
53
54 R__.wr_window = *window;
55 R__.rd_window = *window;
56 R__.split_window = 0;
57
58 update_window_mappings();
59}
60
61/*!
62 \brief Unset current window
63 */
65{
66 G_debug(4, "Rast_unset_window()");
67
68 R__.window_set = 0;
69}
70
71/*!
72 * \brief Establishes 'window' as the current working window for output.
73 *
74 * \param window window to become operative window
75 */
77{
78 Rast__init();
79
80 check_write_window();
81
82 G_adjust_Cell_head(window, 0, 0);
83
84 R__.wr_window = *window;
85 R__.split_window = 1;
86
87 G_set_window(window);
88}
89
90/*!
91 * \brief Establishes 'window' as the current working window for input.
92 *
93 * Any opened cell files has its file-to-window mapping reworked.
94 *
95 * \param window window to become operative window
96 */
97void Rast_set_input_window(struct Cell_head *window)
98{
99 Rast__init();
100
101 G_adjust_Cell_head(window, 0, 0);
102
103 R__.rd_window = *window;
104 R__.split_window = 1;
105
106 update_window_mappings();
107}
108
109static void update_window_mappings(void)
110{
111 int i;
112 int maskfd;
113
114 /* adjust window, check for valid window */
115 /* adjust the real one, not a copy
116 G_copy (&twindow, window, sizeof(struct Cell_head));
117 window = &twindow;
118 */
119
120 /* except for mask raster, cell files open for read must have same
121 * projection and zone as new window
122 */
123 maskfd = R__.auto_mask > 0 ? R__.mask_fd : -1;
124 for (i = 0; i < R__.fileinfo_count; i++) {
125 struct fileinfo *fcb = &R__.fileinfo[i];
126
127 if (fcb->open_mode == OPEN_OLD) {
128 if (fcb->cellhd.zone == R__.rd_window.zone &&
129 fcb->cellhd.proj == R__.rd_window.proj)
130 continue;
131 if (i != maskfd)
132 G_fatal_error(_("Rast_set_read_window(): projection/zone "
133 "differs from that of "
134 "currently open raster maps"));
135 }
136 }
137
138 /* close the mask */
139 if (R__.auto_mask > 0) {
141 /* G_free (R__.mask_buf); */
142 R__.mask_fd = -1;
143 R__.auto_mask = -1; /* turn off masking */
144 }
145
146 /* now for each possible open cell file, recreate the window mapping */
147 /*
148 * also the memory for reading and writing must be reallocated for all
149 * opened cell files
150 */
151 for (i = 0; i < R__.fileinfo_count; i++) {
152 struct fileinfo *fcb = &R__.fileinfo[i];
153
154 if (fcb->open_mode != OPEN_OLD &&
155 fcb->open_mode != OPEN_NEW_UNCOMPRESSED &&
156 fcb->open_mode != OPEN_NEW_COMPRESSED)
157 continue;
158
159 if (fcb->open_mode == OPEN_OLD)
160 G_fatal_error(_("Input window changed while maps are open for "
161 "read. Map name <%s>"),
162 fcb->name);
163 }
164
165 /* turn masking (back) on if necessary */
167}
168
169static void check_write_window(void)
170{
171 int i;
172
173 for (i = 0; i < R__.fileinfo_count; i++) {
174 struct fileinfo *fcb = &R__.fileinfo[i];
175
176 if (fcb->open_mode == OPEN_NEW_UNCOMPRESSED ||
177 fcb->open_mode == OPEN_NEW_COMPRESSED)
178 G_fatal_error(_("Output window changed while maps are open for "
179 "write. Map name <%s>"),
180 fcb->name);
181 }
182}
#define OPEN_NEW_COMPRESSED
Definition R.h:102
#define OPEN_NEW_UNCOMPRESSED
Definition R.h:103
#define OPEN_OLD
Definition R.h:101
AMI_err name(char **stream_name)
Definition ami_stream.h:426
void void void void G_fatal_error(const char *,...) __attribute__((format(printf
void G_warning(const char *,...) __attribute__((format(printf
void G_set_window(struct Cell_head *)
Establishes window as the current working window (region).
void G__init_window(void)
Initialize window (region).
int G_is_initialized(int *)
Definition counter.c:60
void G_initialize_done(int *)
Definition counter.c:77
void G_adjust_Cell_head(struct Cell_head *, int, int)
Adjust cell header.
Definition adj_cellhd.c:51
int G_debug(int, const char *,...) __attribute__((format(printf
int Rast__check_for_auto_masking(void)
Checks for auto masking.
Definition auto_mask.c:33
void Rast_close(int)
Close a raster map.
void Rast__init(void)
Definition raster/init.c:61
#define _(str)
Definition glocale.h:10
void Rast__init_window(void)
void Rast_unset_window(void)
Unset current window.
void Rast_set_window(struct Cell_head *window)
Establishes 'window' as the current working window.
void Rast_set_output_window(struct Cell_head *window)
Establishes 'window' as the current working window for output.
void Rast_set_input_window(struct Cell_head *window)
Establishes 'window' as the current working window for input.
2D/3D raster map header (used also for region)
Definition gis.h:446
Definition G.h:11
struct Cell_head window
Definition G.h:12
Definition R.h:82
struct fileinfo * fileinfo
Definition R.h:96
int auto_mask
Definition R.h:85
int window_set
Definition R.h:90
int fileinfo_count
Definition R.h:95
int split_window
Definition R.h:91
int mask_fd
Definition R.h:84
struct Cell_head wr_window
Definition R.h:93
struct Cell_head rd_window
Definition R.h:92
Definition R.h:48