GRASS 8 Programmer's Manual 8.6.0dev(2026)-55de52a352
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 * SPDX-FileCopyrightText: 2001-2024 Vaclav Petras
7 * SPDX-FileCopyrightText: GRASS Development Team
8 * SPDX-License-Identifier: GPL-2.0-or-later
9 *
10 * \author GRASS Development Team
11 * \author Vaclav Petras (environmental variable and refactoring)
12 */
13
14#include <stdlib.h>
15
16#include <grass/gis.h>
17#include <grass/raster.h>
18#include <grass/glocale.h>
19
20#include "R.h"
21
22/**
23 * \brief Checks for auto masking.
24 *
25 * On first call, opens the mask file if declared and available and
26 * allocates buffer for reading mask rows.
27 * On second call, returns 0 or 1.
28 *
29 * \return 0 if mask unset or unavailable
30 * \return 1 if mask set and available and ready to use
31 */
33{
34 struct Cell_head cellhd;
35
36 Rast__init();
37
38 /* if mask is switched off (-2) return -2
39 if R__.auto_mask is not set (-1) or set (>=0) recheck the mask */
40
41 // TODO: This needs to be documented or modified accordingly.
42 if (R__.auto_mask < -1)
43 return R__.auto_mask;
44
45 /* if(R__.mask_fd > 0) G_free (R__.mask_buf); */
46
47 /* Decide between default mask name and env var specified one. */
48 char *mask_name = Rast_mask_name();
49 char *mask_mapset = "";
50
51 /* Check for the existence of the mask raster. */
53
54 if (R__.auto_mask <= 0)
55 return 0;
56
57 /* Check mask raster projection/zone against current region */
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)
67 if (R__.mask_fd < 0) {
68 R__.auto_mask = 0;
69 G_warning(_("Unable to open automatic mask <%s>"), mask_name);
70 return 0;
71 }
72
73 /* R__.mask_buf = Rast_allocate_c_buf(); */
74
75 R__.auto_mask = 1;
77
78 return 1;
79}
80
81/**
82 * \brief Suppresses masking.
83 *
84 * \return
85 */
87{
88 Rast__init();
89
90 if (R__.auto_mask > 0) {
92 /* G_free (R__.mask_buf); */
93 R__.mask_fd = -1;
94 }
95 R__.auto_mask = -2;
96}
97
98/**
99 * \brief Unsuppresses masking.
100 *
101 * \return
102 */
104{
105 Rast__init();
106
107 if (R__.auto_mask < -1) {
108 R__.mask_fd = -1;
110 }
111}
int Rast__check_for_auto_masking(void)
Checks for auto masking.
Definition auto_mask.c:32
void Rast_suppress_masking(void)
Suppresses masking.
Definition auto_mask.c:86
void Rast_unsuppress_masking(void)
Unsuppresses masking.
Definition auto_mask.c:103
void G_free(void *)
Free allocated memory.
Definition gis/alloc.c:145
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:73
int G_projection(void)
Query cartographic projection.
Definition proj1.c:30
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:59
void Rast_get_cellhd(const char *, const char *, struct Cell_head *)
Read the raster header.
Definition get_cellhd.c:39
#define _(str)
Definition glocale.h:10
2D/3D raster map header (used also for region)
Definition gis.h:443
int zone
Projection zone (UTM)
Definition gis.h:477
int proj
Projection code.
Definition gis.h:475
Definition R.h:82
int auto_mask
Definition R.h:85
int mask_fd
Definition R.h:84