GRASS GIS 7 Programmer's Manual  7.9.dev(2021)-e5379bbd7
auto_mask.c
Go to the documentation of this file.
1 
2 /**
3  * \file auto_mask.c
4  *
5  * \brief Raster Library - Auto masking routines.
6  *
7  * (C) 2001-2008 by the GRASS Development Team
8  *
9  * This program is free software under the GNU General Public License
10  * (>=v2). Read the file COPYING that comes with GRASS for details.
11  *
12  * \author GRASS GIS Development Team
13  *
14  * \date 1999-2008
15  */
16 
17 #include <stdlib.h>
18 
19 #include <grass/gis.h>
20 #include <grass/raster.h>
21 #include <grass/glocale.h>
22 
23 #include "R.h"
24 
25 
26 /**
27  * \brief Checks for auto masking.
28  *
29  * On first call, opens the mask file if declared and available and
30  * allocates buffer for reading mask rows.
31  * On second call, returns 0 or 1.
32  *
33  * \return 0 if mask unset or unavailable
34  * \return 1 if mask set and available and ready to use
35  */
36 
38 {
39  struct Cell_head cellhd;
40 
41  Rast__init();
42 
43  /* if mask is switched off (-2) return -2
44  if R__.auto_mask is not set (-1) or set (>=0) recheck the MASK */
45 
46  if (R__.auto_mask < -1)
47  return R__.auto_mask;
48 
49  /* if(R__.mask_fd > 0) G_free (R__.mask_buf); */
50 
51  /* look for the existence of the MASK file */
52  R__.auto_mask = (G_find_raster("MASK", G_mapset()) != 0);
53 
54  if (R__.auto_mask <= 0)
55  return 0;
56 
57  /* check MASK projection/zone against current region */
58  Rast_get_cellhd("MASK", G_mapset(), &cellhd);
59  if (cellhd.zone != G_zone() || cellhd.proj != G_projection()) {
60  R__.auto_mask = 0;
61  return 0;
62  }
63 
64  if (R__.mask_fd >= 0)
66  R__.mask_fd = Rast__open_old("MASK", G_mapset());
67  if (R__.mask_fd < 0) {
68  R__.auto_mask = 0;
69  G_warning(_("Unable to open automatic MASK file"));
70  return 0;
71  }
72 
73  /* R__.mask_buf = Rast_allocate_c_buf(); */
74 
75  R__.auto_mask = 1;
76 
77  return 1;
78 }
79 
80 
81 /**
82  * \brief Suppresses masking.
83  *
84  * \return
85  */
86 
88 {
89  Rast__init();
90 
91  if (R__.auto_mask > 0) {
93  /* G_free (R__.mask_buf); */
94  R__.mask_fd = -1;
95  }
96  R__.auto_mask = -2;
97 }
98 
99 
100 /**
101  * \brief Unsuppresses masking.
102  *
103  * \return
104  */
105 
107 {
108  Rast__init();
109 
110  if (R__.auto_mask < -1) {
111  R__.mask_fd = -1;
113  }
114 }
int Rast__check_for_auto_masking(void)
Checks for auto masking.
Definition: auto_mask.c:37
int G_zone(void)
Query cartographic zone.
Definition: zone.c:25
Definition: R.h:88
2D/3D raster map header (used also for region)
Definition: gis.h:412
int G_projection(void)
Query cartographic projection.
Definition: proj1.c:32
int Rast__open_old(const char *, const char *)
Lower level function, open cell files, supercell files, and the MASK file.
Definition: raster/open.c:152
void Rast_unopen(int)
Unopen a raster map.
Definition: raster/close.c:132
void Rast__init(void)
Definition: raster/init.c:65
int zone
Projection zone (UTM)
Definition: gis.h:446
int proj
Projection code.
Definition: gis.h:444
int mask_fd
Definition: R.h:91
int auto_mask
Definition: R.h:92
void Rast_suppress_masking(void)
Suppresses masking.
Definition: auto_mask.c:87
const char * G_find_raster(char *, const char *)
Find a raster map.
Definition: find_rast.c:55
void Rast_get_cellhd(const char *, const char *, struct Cell_head *)
Read the raster header.
Definition: get_cellhd.c:41
const char * G_mapset(void)
Get current mapset name.
Definition: gis/mapset.c:33
void G_warning(const char *,...) __attribute__((format(printf
#define _(str)
Definition: glocale.h:10
void Rast_unsuppress_masking(void)
Unsuppresses masking.
Definition: auto_mask.c:106
void Rast_close(int)
Close a raster map.
Definition: raster/close.c:99