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