GRASS 8 Programmer's Manual 8.6.0dev(2026)-ddeab64dbf
Loading...
Searching...
No Matches
auto_mask.c
Go to the documentation of this file.
1/**
2 * \file auto_mask.c
3 *
4 * \brief Raster Library - Auto masking routines.
5 *
6 * (C) 2001-2024 by Vaclav Petras and 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 GRASS Development Team
12 * \author Vaclav Petras (environmental variable and refactoring)
13 */
14
15#include <stdlib.h>
16
17#include <grass/gis.h>
18#include <grass/raster.h>
19#include <grass/glocale.h>
20
21#include "R.h"
22
23/**
24 * \brief Checks for auto masking.
25 *
26 * On first call, opens the mask file if declared and available and
27 * allocates buffer for reading mask rows.
28 * On second call, returns 0 or 1.
29 *
30 * \return 0 if mask unset or unavailable
31 * \return 1 if mask set and available and ready to use
32 */
34{
35 struct Cell_head cellhd;
36
37 Rast__init();
38
39 /* if mask is switched off (-2) return -2
40 if R__.auto_mask is not set (-1) or set (>=0) recheck the mask */
41
42 // TODO: This needs to be documented or modified accordingly.
43 if (R__.auto_mask < -1)
44 return R__.auto_mask;
45
46 /* if(R__.mask_fd > 0) G_free (R__.mask_buf); */
47
48 /* Decide between default mask name and env var specified one. */
49 char *mask_name = Rast_mask_name();
50 char *mask_mapset = "";
51
52 /* Check for the existence of the mask raster. */
54
55 if (R__.auto_mask <= 0)
56 return 0;
57
58 /* Check mask raster projection/zone against current region */
60 if (cellhd.zone != G_zone() || cellhd.proj != G_projection()) {
61 R__.auto_mask = 0;
62 return 0;
63 }
64
65 if (R__.mask_fd >= 0)
68 if (R__.mask_fd < 0) {
69 R__.auto_mask = 0;
70 G_warning(_("Unable to open automatic mask <%s>"), mask_name);
71 return 0;
72 }
73
74 /* R__.mask_buf = Rast_allocate_c_buf(); */
75
76 R__.auto_mask = 1;
78
79 return 1;
80}
81
82/**
83 * \brief Suppresses masking.
84 *
85 * \return
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 * \brief Unsuppresses masking.
101 *
102 * \return
103 */
105{
106 Rast__init();
107
108 if (R__.auto_mask < -1) {
109 R__.mask_fd = -1;
111 }
112}
int Rast__check_for_auto_masking(void)
Checks for auto masking.
Definition auto_mask.c:33
void Rast_suppress_masking(void)
Suppresses masking.
Definition auto_mask.c:87
void Rast_unsuppress_masking(void)
Unsuppresses masking.
Definition auto_mask.c:104
void G_free(void *)
Free allocated memory.
Definition gis/alloc.c:147
void G_warning(const char *,...) __attribute__((format(printf
int G_zone(void)
Query cartographic zone.
Definition zone.c:23
const char * G_find_raster2(const char *, const char *)
Find a raster map (look but don't touch)
Definition find_rast.c:76
int G_projection(void)
Query cartographic projection.
Definition proj1.c:32
void Rast_unopen(int)
Unopen a raster map.
void Rast_close(int)
Close a raster map.
char * Rast_mask_name(void)
Retrieves the name of the raster mask to use.
Definition mask_info.c:77
int Rast__open_old(const char *, const char *)
Lower level function, open cell files, supercell files, and the mask file.
void Rast__init(void)
Definition raster/init.c:61
void Rast_get_cellhd(const char *, const char *, struct Cell_head *)
Read the raster header.
Definition get_cellhd.c:41
#define _(str)
Definition glocale.h:10
2D/3D raster map header (used also for region)
Definition gis.h:446
int zone
Projection zone (UTM)
Definition gis.h:480
int proj
Projection code.
Definition gis.h:478
Definition R.h:82
int auto_mask
Definition R.h:85
int mask_fd
Definition R.h:84