GRASS GIS 7 Programmer's Manual  7.9.dev(2021)-e5379bbd7
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 
21 static void update_window_mappings(void);
22 static void check_write_window(void);
23 
25 {
27  return;
28 
30 
33  R__.split_window = 0;
34 
36 }
37 
38 /*!
39  * \brief Establishes 'window' as the current working window.
40  *
41  * \param window window to become operative window
42  */
43 void 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  \brief Unset current window
62 */
64 {
65  G_debug(4, "Rast_unset_window()");
66 
67  R__.window_set = 0;
68 }
69 /*!
70  * \brief Establishes 'window' as the current working window for output.
71  *
72  * \param window window to become operative window
73  */
74 void Rast_set_output_window(struct Cell_head *window)
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  */
95 
96 void Rast_set_input_window(struct Cell_head *window)
97 {
98  Rast__init();
99 
100  G_adjust_Cell_head(window, 0, 0);
101 
102  R__.rd_window = *window;
103  R__.split_window = 1;
104 
105  update_window_mappings();
106 }
107 
108 static void update_window_mappings(void)
109 {
110  int i;
111  int maskfd;
112 
113  /* adjust window, check for valid window */
114  /* adjust the real one, not a copy
115  G_copy (&twindow, window, sizeof(struct Cell_head));
116  window = &twindow;
117  */
118 
119  /* except for MASK, cell files open for read must have same projection
120  * and zone as new window
121  */
122  maskfd = R__.auto_mask > 0 ? R__.mask_fd : -1;
123  for (i = 0; i < R__.fileinfo_count; i++) {
124  struct fileinfo *fcb = &R__.fileinfo[i];
125 
126  if (fcb->open_mode == OPEN_OLD) {
127  if (fcb->cellhd.zone == R__.rd_window.zone &&
128  fcb->cellhd.proj == R__.rd_window.proj)
129  continue;
130  if (i != maskfd)
131  G_fatal_error(_("Rast_set_read_window(): projection/zone differs from that of "
132  "currently open raster maps"));
133  }
134  }
135 
136  /* close the mask */
137  if (R__.auto_mask > 0) {
138  Rast_close(maskfd);
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 opened
147  * 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 &&
155  continue;
156 
157  if (fcb->open_mode == OPEN_OLD)
158  G_fatal_error(_("Input window changed while maps are open for read. Map name <%s>"), fcb->name);
159  }
160 
161  /* turn masking (back) on if necessary */
163 }
164 
165 static void check_write_window(void)
166 {
167  int i;
168 
169  for (i = 0; i < R__.fileinfo_count; i++) {
170  struct fileinfo *fcb = &R__.fileinfo[i];
171 
172  if (fcb->open_mode == OPEN_NEW_UNCOMPRESSED ||
174  G_fatal_error(_("Output window changed while maps are open for write. Map name <%s>"), fcb->name);
175  }
176 }
177 
#define OPEN_NEW_COMPRESSED
Definition: R.h:109
struct Cell_head rd_window
Definition: R.h:99
void void void void G_fatal_error(const char *,...) __attribute__((format(printf
Definition: R.h:88
void Rast__init_window(void)
char * name
Definition: R.h:78
2D/3D raster map header (used also for region)
Definition: gis.h:412
void Rast_set_output_window(struct Cell_head *window)
Establishes &#39;window&#39; as the current working window for output.
void Rast_unset_window(void)
Unset current window.
#define OPEN_NEW_UNCOMPRESSED
Definition: R.h:110
void G_initialize_done(int *)
Definition: counter.c:76
struct Cell_head wr_window
Definition: R.h:100
struct Cell_head window
Definition: G.h:6
void G_set_window(struct Cell_head *)
Establishes window as the current working window (region).
Definition: G.h:4
void Rast_set_input_window(struct Cell_head *window)
Establishes &#39;window&#39; as the current working window for input.
void Rast__init(void)
Definition: raster/init.c:65
int open_mode
Definition: R.h:56
int zone
Projection zone (UTM)
Definition: gis.h:446
int proj
Projection code.
Definition: gis.h:444
void G_adjust_Cell_head(struct Cell_head *, int, int)
Adjust cell header.
Definition: adj_cellhd.c:51
int mask_fd
Definition: R.h:91
int fileinfo_count
Definition: R.h:102
struct fileinfo * fileinfo
Definition: R.h:103
#define OPEN_OLD
Definition: R.h:108
int auto_mask
Definition: R.h:92
int window_set
Definition: R.h:97
int G_is_initialized(int *)
Definition: counter.c:59
void G__init_window(void)
Initialize window (region).
struct Cell_head cellhd
Definition: R.h:57
void G_warning(const char *,...) __attribute__((format(printf
Definition: R.h:54
#define _(str)
Definition: glocale.h:10
void Rast_set_window(struct Cell_head *window)
Establishes &#39;window&#39; as the current working window.
int Rast__check_for_auto_masking(void)
Checks for auto masking.
Definition: auto_mask.c:37
int split_window
Definition: R.h:98
int G_debug(int, const char *,...) __attribute__((format(printf
void Rast_close(int)
Close a raster map.
Definition: raster/close.c:99