1
#include <grass/raster.h>
2
#include "raster3d_intern.h"
4
/*---------------------------------------------------------------------------*/
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 <em>type</em>.
11
* This function invokes a fatal error if an error occurs.
22
void Rast3d_get_value(RASTER3D_Map * map, int x, int y, int z, void *value, int type)
24
/* get the resampled value */
25
map->resampleFun(map, x, y, z, value, type);
28
/*---------------------------------------------------------------------------*/
34
* <tt>Rast3d_get_value (map, x, y, z, &value, FCELL_TYPE);</tt> return value.
43
float Rast3d_get_float(RASTER3D_Map * map, int x, int y, int z)
47
Rast3d_get_value(map, x, y, z, &value, FCELL_TYPE);
51
/*---------------------------------------------------------------------------*/
57
* to <tt>Rast3d_get_value (map, x, y, z, &value, DCELL_TYPE);</tt> return value.
66
double Rast3d_get_double(RASTER3D_Map * map, int x, int y, int z)
70
Rast3d_get_value(map, x, y, z, &value, DCELL_TYPE);
74
/*---------------------------------------------------------------------------*/
79
* Returns in <em>value</em> the value of the <em>map</em> which corresponds to
80
* window coordinates <em>(north, east, top)</em>. The
81
* value is resampled using the resampling function specified for <em>map</em>. The
82
* <em>value</em> is of <em>type</em>.
94
Rast3d_get_window_value(RASTER3D_Map * map, double north, double east, double top,
95
void *value, int type)
99
Rast3d_location2coord(&(map->window), north, east, top, &col, &row, &depth);
101
/* if (row, col, depth) outside window return NULL value */
102
if ((row < 0) || (row >= map->window.rows) ||
103
(col < 0) || (col >= map->window.cols) ||
104
(depth < 0) || (depth >= map->window.depths)) {
105
Rast3d_set_null_value(value, 1, type);
109
/* Get the value from the map in map-region resolution */
110
map->resampleFun(map, col, row, depth, value, type);
113
/*---------------------------------------------------------------------------*/
118
* Returns in <em>value</em> the value of the <em>map</em> which corresponds to
119
* region coordinates <em>(north, east, top)</em>.
131
Rast3d_get_region_value(RASTER3D_Map * map, double north, double east, double top,
132
void *value, int type)
136
Rast3d_location2coord(&(map->region), north, east, top, &col, &row, &depth);
138
/* if (row, col, depth) outside region return NULL value */
139
if ((row < 0) || (row >= map->region.rows) ||
140
(col < 0) || (col >= map->region.cols) ||
141
(depth < 0) || (depth >= map->region.depths)) {
142
Rast3d_set_null_value(value, 1, type);
146
/* Get the value from the map in map-region resolution */
147
Rast3d_get_value_region(map, col, row, depth, value, type);
150
/*---------------------------------------------------------------------------*/
155
* Is equivalent to <tt>Rast3d_get_value_region (map, x, y, z, &value, FCELL_TYPE);</tt>
165
float Rast3d_get_float_region(RASTER3D_Map * map, int x, int y, int z)
171
if (map->typeIntern == DCELL_TYPE)
172
return (float)Rast3d_get_double_region(map, x, y, z);
174
/* In case of region coordinates out of bounds, return the Null value */
175
if(x < 0 || y < 0 || z < 0 || x >= map->region.cols ||
176
y >= map->region.rows || z >= map->region.depths) {
177
Rast3d_set_null_value(&value, 1, FCELL_TYPE);
181
Rast3d_coord2tile_index(map, x, y, z, &tileIndex, &offs);
182
tile = (float *)Rast3d_get_tile_ptr(map, tileIndex);
185
Rast3d_fatal_error("Rast3d_get_float_region: error in Rast3d_get_tile_ptr."
186
"Region coordinates x %i y %i z %i tile index %i offset %i",
187
x, y, z, tileIndex, offs);
192
/*---------------------------------------------------------------------------*/
197
* Is equivalent to <tt>Rast3d_get_value_region (map, x, y, z, &value,
198
* DCELL_TYPE);</tt> return value.
207
double Rast3d_get_double_region(RASTER3D_Map * map, int x, int y, int z)
213
if (map->typeIntern == FCELL_TYPE)
214
return (double)Rast3d_get_float_region(map, x, y, z);
216
/* In case of region coordinates out of bounds, return the Null value */
217
if(x < 0 || y < 0 || z < 0 || x >= map->region.cols ||
218
y >= map->region.rows || z >= map->region.depths) {
219
Rast3d_set_null_value(&value, 1, DCELL_TYPE);
223
Rast3d_coord2tile_index(map, x, y, z, &tileIndex, &offs);
224
tile = (double *)Rast3d_get_tile_ptr(map, tileIndex);
227
Rast3d_fatal_error("Rast3d_get_double_region: error in Rast3d_get_tile_ptr."
228
"Region coordinates x %i y %i z %i tile index %i offset %i",
229
x, y, z, tileIndex, offs);
234
/*---------------------------------------------------------------------------*/
239
* Returns in <em>*value</em> the cell-value of the cell with
240
* region-coordinate <em>(x, y, z)</em>. The value returned is of <em>type</em>.
241
* Here <em>region</em> means the coordinate in the cube of data in the file, i.e.
242
* ignoring geographic coordinates.
243
* In case the region coordinates are out of bounds, the Null value will be returned.
244
* This function invokes a fatal error if an error occurs.
256
Rast3d_get_value_region(RASTER3D_Map * map, int x, int y, int z, void *value, int type)
258
if (type == FCELL_TYPE) {
259
*((float *)value) = Rast3d_get_float_region(map, x, y, z);
263
*((double *)value) = Rast3d_get_double_region(map, x, y, z);