GRASS 8 Programmer's Manual 8.6.0dev(2026)-ddeab64dbf
Loading...
Searching...
No Matches
getvalue.c
Go to the documentation of this file.
1#include <grass/raster.h>
2#include "raster3d_intern.h"
3
4/*---------------------------------------------------------------------------*/
5
6/*!
7 * \brief
8 *
9 * Returns in <em>*value</em> the resampled cell-value of the cell with
10 * window-coordinate <em>(x, y, z)</em>. The value returned is of
11 * <em>type</em>. This function invokes a fatal error if an error occurs.
12 *
13 * \param map
14 * \param x
15 * \param y
16 * \param z
17 * \param value
18 * \param type
19 * \return void
20 */
21void Rast3d_get_value(RASTER3D_Map *map, int x, int y, int z, void *value,
22 int type)
23{
24 /* get the resampled value */
25 map->resampleFun(map, x, y, z, value, type);
26}
27
28/*---------------------------------------------------------------------------*/
29
30/*!
31 * \brief
32 *
33 * Is equivalent to
34 * <tt>Rast3d_get_value (map, x, y, z, &value, FCELL_TYPE);</tt> return value.
35 *
36 * \param map
37 * \param x
38 * \param y
39 * \param z
40 * \return float
41 */
42float Rast3d_get_float(RASTER3D_Map *map, int x, int y, int z)
43{
44 float value;
45
46 Rast3d_get_value(map, x, y, z, &value, FCELL_TYPE);
47 return value;
48}
49
50/*---------------------------------------------------------------------------*/
51
52/*!
53 * \brief
54 *
55 * Is equivalent
56 * to <tt>Rast3d_get_value (map, x, y, z, &value, DCELL_TYPE);</tt> return
57 * value.
58 *
59 * \param map
60 * \param x
61 * \param y
62 * \param z
63 * \return double
64 */
65double Rast3d_get_double(RASTER3D_Map *map, int x, int y, int z)
66{
67 double value;
68
69 Rast3d_get_value(map, x, y, z, &value, DCELL_TYPE);
70 return value;
71}
72
73/*---------------------------------------------------------------------------*/
74
75/*!
76 * \brief
77 *
78 * Returns in <em>value</em> the value of the <em>map</em> which corresponds to
79 * window coordinates <em>(north, east, top)</em>. The
80 * value is resampled using the resampling function specified for <em>map</em>.
81 * The <em>value</em> is of <em>type</em>.
82 *
83 * \param map
84 * \param north
85 * \param east
86 * \param top
87 * \param value
88 * \param type
89 * \return void
90 */
91void Rast3d_get_window_value(RASTER3D_Map *map, double north, double east,
92 double top, void *value, int type)
93{
94 int col, row, depth;
95
96 Rast3d_location2coord(&(map->window), north, east, top, &col, &row, &depth);
97
98 /* if (row, col, depth) outside window return NULL value */
99 if ((row < 0) || (row >= map->window.rows) || (col < 0) ||
100 (col >= map->window.cols) || (depth < 0) ||
101 (depth >= map->window.depths)) {
102 Rast3d_set_null_value(value, 1, type);
103 return;
104 }
105
106 /* Get the value from the map in map-region resolution */
107 map->resampleFun(map, col, row, depth, value, type);
108}
109
110/*---------------------------------------------------------------------------*/
111
112/*!
113 * \brief
114 *
115 * Returns in <em>value</em> the value of the <em>map</em> which corresponds to
116 * region coordinates <em>(north, east, top)</em>.
117 *
118 * \param map
119 * \param north
120 * \param east
121 * \param top
122 * \param value
123 * \param type
124 * \return void
125 */
126void Rast3d_get_region_value(RASTER3D_Map *map, double north, double east,
127 double top, void *value, int type)
128{
129 int row, col, depth;
130
131 Rast3d_location2coord(&(map->region), north, east, top, &col, &row, &depth);
132
133 /* if (row, col, depth) outside region return NULL value */
134 if ((row < 0) || (row >= map->region.rows) || (col < 0) ||
135 (col >= map->region.cols) || (depth < 0) ||
136 (depth >= map->region.depths)) {
137 Rast3d_set_null_value(value, 1, type);
138 return;
139 }
140
141 /* Get the value from the map in map-region resolution */
142 Rast3d_get_value_region(map, col, row, depth, value, type);
143}
144
145/*---------------------------------------------------------------------------*/
146
147/*!
148 * \brief
149 *
150 * Is equivalent to <tt>Rast3d_get_value_region (map, x, y, z, &value,
151 * FCELL_TYPE);</tt> return value.
152 *
153 * \param map
154 * \param x
155 * \param y
156 * \param z
157 * \return float
158 */
159float Rast3d_get_float_region(RASTER3D_Map *map, int x, int y, int z)
160{
161 int tileIndex, offs;
162 float *tile;
163 float value;
164
165 if (map->typeIntern == DCELL_TYPE)
166 return (float)Rast3d_get_double_region(map, x, y, z);
167
168 /* In case of region coordinates out of bounds, return the Null value */
169 if (x < 0 || y < 0 || z < 0 || x >= map->region.cols ||
170 y >= map->region.rows || z >= map->region.depths) {
172 return value;
173 }
174
175 Rast3d_coord2tile_index(map, x, y, z, &tileIndex, &offs);
176 tile = (float *)Rast3d_get_tile_ptr(map, tileIndex);
177
178 if (tile == NULL)
180 "Rast3d_get_float_region: error in Rast3d_get_tile_ptr."
181 "Region coordinates x %i y %i z %i tile index %i offset %i",
182 x, y, z, tileIndex, offs);
183
184 return tile[offs];
185}
186
187/*---------------------------------------------------------------------------*/
188
189/*!
190 * \brief
191 *
192 * Is equivalent to <tt>Rast3d_get_value_region (map, x, y, z, &value,
193 * DCELL_TYPE);</tt> return value.
194 *
195 * \param map
196 * \param x
197 * \param y
198 * \param z
199 * \return double
200 */
201double Rast3d_get_double_region(RASTER3D_Map *map, int x, int y, int z)
202{
203 int tileIndex, offs;
204 double *tile;
205 double value;
206
207 if (map->typeIntern == FCELL_TYPE)
208 return (double)Rast3d_get_float_region(map, x, y, z);
209
210 /* In case of region coordinates out of bounds, return the Null value */
211 if (x < 0 || y < 0 || z < 0 || x >= map->region.cols ||
212 y >= map->region.rows || z >= map->region.depths) {
214 return value;
215 }
216
217 Rast3d_coord2tile_index(map, x, y, z, &tileIndex, &offs);
218 tile = (double *)Rast3d_get_tile_ptr(map, tileIndex);
219
220 if (tile == NULL)
222 "Rast3d_get_double_region: error in Rast3d_get_tile_ptr."
223 "Region coordinates x %i y %i z %i tile index %i offset %i",
224 x, y, z, tileIndex, offs);
225
226 return tile[offs];
227}
228
229/*---------------------------------------------------------------------------*/
230
231/*!
232 * \brief
233 *
234 * Returns in <em>*value</em> the cell-value of the cell with
235 * region-coordinate <em>(x, y, z)</em>. The value returned is of
236 * <em>type</em>. Here <em>region</em> means the coordinate in the cube of data
237 * in the file, i.e. ignoring geographic coordinates. In case the region
238 * coordinates are out of bounds, the Null value will be returned. This function
239 * invokes a fatal error if an error occurs.
240 *
241 * \param map
242 * \param x
243 * \param y
244 * \param z
245 * \param value
246 * \param type
247 * \return void
248 */
249void Rast3d_get_value_region(RASTER3D_Map *map, int x, int y, int z,
250 void *value, int type)
251{
252 if (type == FCELL_TYPE) {
253 *((float *)value) = Rast3d_get_float_region(map, x, y, z);
254 return;
255 }
256
257 *((double *)value) = Rast3d_get_double_region(map, x, y, z);
258}
#define NULL
Definition ccmath.h:32
void Rast3d_location2coord(RASTER3D_Region *, double, double, double, int *, int *, int *)
Converts region-coordinates (north, east, top) into cell-coordinates (x, y, z).
Definition region.c:275
void * Rast3d_get_tile_ptr(RASTER3D_Map *, int)
This function returns a pointer to a tile which contains the data for the tile with index tileIndex....
Definition tileio.c:78
void Rast3d_set_null_value(void *, int, int)
Fills the vector pointed to by c with nofElts NULL-values of type.
Definition null.c:33
void Rast3d_fatal_error(const char *,...) __attribute__((format(printf
void Rast3d_coord2tile_index(RASTER3D_Map *, int, int, int, int *, int *)
Converts cell-coordinates (x, y, z) into tileIndex and the offset of the cell within the tile.
Definition tilemath.c:152
void Rast3d_get_region_value(RASTER3D_Map *map, double north, double east, double top, void *value, int type)
Returns in value the value of the map which corresponds to region coordinates (north,...
Definition getvalue.c:126
float Rast3d_get_float_region(RASTER3D_Map *map, int x, int y, int z)
Is equivalent to Rast3d_get_value_region (map, x, y, z, &value, FCELL_TYPE); return value.
Definition getvalue.c:159
float Rast3d_get_float(RASTER3D_Map *map, int x, int y, int z)
Is equivalent to Rast3d_get_value (map, x, y, z, &value, FCELL_TYPE); return value.
Definition getvalue.c:42
double Rast3d_get_double_region(RASTER3D_Map *map, int x, int y, int z)
Is equivalent to Rast3d_get_value_region (map, x, y, z, &value, DCELL_TYPE); return value.
Definition getvalue.c:201
void Rast3d_get_window_value(RASTER3D_Map *map, double north, double east, double top, void *value, int type)
Returns in value the value of the map which corresponds to window coordinates (north,...
Definition getvalue.c:91
double Rast3d_get_double(RASTER3D_Map *map, int x, int y, int z)
Is equivalent to Rast3d_get_value (map, x, y, z, &value, DCELL_TYPE); return value.
Definition getvalue.c:65
void Rast3d_get_value_region(RASTER3D_Map *map, int x, int y, int z, void *value, int type)
Returns in *value the cell-value of the cell with region-coordinate (x, y, z). The value returned is ...
Definition getvalue.c:249
void Rast3d_get_value(RASTER3D_Map *map, int x, int y, int z, void *value, int type)
Returns in *value the resampled cell-value of the cell with window-coordinate (x, y,...
Definition getvalue.c:21
#define FCELL_TYPE
Definition raster.h:12
#define DCELL_TYPE
Definition raster.h:13
resample_fn * resampleFun
Definition raster3d.h:88
RASTER3D_Region window
Definition raster3d.h:85
RASTER3D_Region region
Definition raster3d.h:82
#define x