GRASS GIS 7 Programmer's Manual
7.8.2(2019)-exported
|
Go to the documentation of this file.
20 #include <grass/N_pde.h>
21 #include <grass/raster.h>
22 #include <grass/glocale.h>
50 int x, y, cols, rows, type;
53 struct Cell_head region;
64 map = Rast_open_old(
name,
"");
66 type = Rast_get_map_type(map);
71 if (type == DCELL_TYPE) {
74 if (type == FCELL_TYPE) {
77 if (type == CELL_TYPE) {
83 if (data->cols != cols)
85 (
"N_read_rast_to_array_2d: the data array size is different from the current region settings");
86 if (data->rows != rows)
88 (
"N_read_rast_to_array_2d: the data array size is different from the current region settings");
91 rast = Rast_allocate_buf(type);
95 for (y = 0; y < rows; y++) {
98 Rast_get_row(map, rast, y, type);
100 for (
x = 0, ptr = rast;
x < cols;
102 if (type == CELL_TYPE) {
103 if (Rast_is_c_null_value(ptr)) {
107 if (data->type == CELL_TYPE)
109 (CELL) * (CELL *) ptr);
110 if (data->type == FCELL_TYPE)
112 (FCELL) * (CELL *) ptr);
113 if (data->type == DCELL_TYPE)
115 (DCELL) * (CELL *) ptr);
118 if (type == FCELL_TYPE) {
119 if (Rast_is_f_null_value(ptr)) {
123 if (data->type == CELL_TYPE)
125 (CELL) * (FCELL *) ptr);
126 if (data->type == FCELL_TYPE)
128 (FCELL) * (FCELL *) ptr);
129 if (data->type == DCELL_TYPE)
131 (DCELL) * (FCELL *) ptr);
134 if (type == DCELL_TYPE) {
135 if (Rast_is_d_null_value(ptr)) {
139 if (data->type == CELL_TYPE)
141 (CELL) * (DCELL *) ptr);
142 if (data->type == FCELL_TYPE)
144 (FCELL) * (DCELL *) ptr);
145 if (data->type == DCELL_TYPE)
147 (DCELL) * (DCELL *) ptr);
176 int x, y, cols, rows,
count, type;
180 struct Cell_head region;
193 map = Rast_open_new(
name, type);
195 if (type == CELL_TYPE)
196 rast = Rast_allocate_buf(type);
197 if (type == FCELL_TYPE)
198 frast = Rast_allocate_buf(type);
199 if (type == DCELL_TYPE)
200 drast = Rast_allocate_buf(type);
205 for (y = 0; y < rows; y++) {
207 for (
x = 0;
x < cols;
x++) {
208 if (type == CELL_TYPE)
210 if (type == FCELL_TYPE)
212 if (type == DCELL_TYPE)
215 if (type == CELL_TYPE)
216 Rast_put_c_row(map, rast);
217 if (type == FCELL_TYPE)
218 Rast_put_f_row(map, frast);
219 if (type == DCELL_TYPE)
220 Rast_put_d_row(map, drast);
258 int x, y, z, cols, rows, depths, type;
259 double d1 = 0, f1 = 0;
261 RASTER3D_Region region;
265 Rast3d_get_window(®ion);
269 depths = region.depths;
273 Rast3d_fatal_error(_(
"3D raster map <%s> not found"),
name);
278 RASTER3D_TILE_SAME_AS_FILE, RASTER3D_USE_CACHE_DEFAULT);
281 Rast3d_fatal_error(_(
"Unable to open 3D raster map <%s>"),
name);
283 type = Rast3d_tile_type_map(map);
288 if (type == FCELL_TYPE) {
291 if (type == DCELL_TYPE) {
297 if (data->
cols != cols)
299 (
"N_read_rast_to_array_3d: the data array size is different from the current region settings");
300 if (data->
rows != rows)
302 (
"N_read_rast_to_array_3d: the data array size is different from the current region settings");
303 if (data->
depths != depths)
305 (
"N_read_rast_to_array_3d: the data array size is different from the current region settings");
313 if (Rast3d_mask_file_exists()) {
315 if (Rast3d_mask_is_off(map)) {
322 for (z = 0; z < depths; z++) {
324 for (y = 0; y < rows; y++) {
325 for (
x = 0;
x < cols;
x++) {
326 if (type == FCELL_TYPE) {
327 Rast3d_get_value(map,
x, y, z, &f1, type);
328 if (Rast_is_f_null_value((
void *)&f1)) {
332 if (data->
type == FCELL_TYPE)
334 if (data->
type == DCELL_TYPE)
339 Rast3d_get_value(map,
x, y, z, &d1, type);
340 if (Rast_is_d_null_value((
void *)&d1)) {
344 if (data->
type == FCELL_TYPE)
346 if (data->
type == DCELL_TYPE)
357 if (Rast3d_mask_file_exists())
358 if (Rast3d_mask_is_on(map) && changemask)
359 Rast3d_mask_off(map);
363 if (!Rast3d_close(map))
364 Rast3d_fatal_error(map,
NULL, 0, _(
"Error closing g3d file"));
389 int x, y, z, cols, rows, depths,
count, type;
390 double d1 = 0.0, f1 = 0.0;
392 RASTER3D_Region region;
395 Rast3d_get_window(®ion);
399 depths = region.depths;
403 if (data->
cols != cols)
405 (
"N_write_array_3d_to_rast3d: the data array size is different from the current region settings");
406 if (data->
rows != rows)
408 (
"N_write_array_3d_to_rast3d: the data array size is different from the current region settings");
409 if (data->
depths != depths)
411 (
"N_write_array_3d_to_rast3d: the data array size is different from the current region settings");
414 if (type == DCELL_TYPE)
415 map = Rast3d_open_new_opt_tile_size(
name, RASTER3D_USE_CACHE_XY, ®ion, DCELL_TYPE, 32);
416 else if (type == FCELL_TYPE)
417 map = Rast3d_open_new_opt_tile_size(
name, RASTER3D_USE_CACHE_XY, ®ion, FCELL_TYPE, 32);
420 Rast3d_fatal_error(_(
"Error opening g3d map <%s>"),
name);
426 if (Rast3d_mask_file_exists()) {
428 if (Rast3d_mask_is_off(map)) {
436 for (z = 0; z < depths; z++) {
438 for (y = 0; y < rows; y++) {
439 for (
x = 0;
x < cols;
x++) {
440 if (type == FCELL_TYPE) {
442 Rast3d_put_float(map,
x, y, z, f1);
444 else if (type == DCELL_TYPE) {
446 Rast3d_put_double(map,
x, y, z, d1);
454 if (Rast3d_mask_file_exists())
455 if (Rast3d_mask_is_on(map) && changemask)
456 Rast3d_mask_off(map);
460 if (!Rast3d_flush_all_tiles(map))
461 Rast3d_fatal_error(
"Error flushing tiles with Rast3d_flush_all_tiles");
463 if (!Rast3d_close(map))
464 Rast3d_fatal_error(map,
NULL, 0, _(
"Error closing g3d file"));
N_array_2d * N_read_rast_to_array_2d(char *name, N_array_2d *array)
Read a raster map into a N_array_2d structure.
FCELL N_get_array_2d_f_value(N_array_2d *data, int col, int row)
Returns the value of type FCELL at position col, row.
void N_put_array_3d_d_value(N_array_3d *data, int col, int row, int depth, double value)
Writes a double value to the N_array_3d struct at position col, row, depth.
void N_put_array_2d_c_value(N_array_2d *data, int col, int row, CELL value)
Writes a CELL value to the N_array_2d struct at position col, row.
void N_put_array_3d_value_null(N_array_3d *data, int col, int row, int depth)
This function writes a null value to the N_array_3d data at position col, row, depth.
void G_fatal_error(const char *msg,...)
Print a fatal error message to stderr.
void N_put_array_2d_value_null(N_array_2d *data, int col, int row)
Writes the null value to the N_array_2d struct at position col, row.
float N_get_array_3d_f_value(N_array_3d *data, int col, int row, int depth)
This function returns the value of type float at position col, row, depth.
void N_put_array_2d_f_value(N_array_2d *data, int col, int row, FCELL value)
Writes a FCELL value to the N_array_2d struct at position col, row.
double N_get_array_3d_d_value(N_array_3d *data, int col, int row, int depth)
This function returns the value of type float at position col, row, depth.
void G_message(const char *msg,...)
Print a message to stderr.
void N_put_array_3d_f_value(N_array_3d *data, int col, int row, int depth, float value)
This function writes a float value to the N_array_3d data at position col, row, depth.
void G_percent(long n, long d, int s)
Print percent complete messages.
CELL N_get_array_2d_c_value(N_array_2d *data, int col, int row)
Returns the value of type CELL at position col, row.
void N_write_array_2d_to_rast(N_array_2d *array, char *name)
Write a N_array_2d struct to a raster map.
void G_get_set_window(struct Cell_head *window)
Get the current working window (region)
N_array_3d * N_read_rast3d_to_array_3d(char *name, N_array_3d *array, int mask)
Read a volume map into a N_array_3d structure.
void N_write_array_3d_to_rast3d(N_array_3d *array, char *name, int mask)
Write a N_array_3d struct to a volume map.
const char * G_find_raster3d(const char *name, const char *mapset)
Search for a 3D raster map in current search path or in a specified mapset.
N_array_3d * N_alloc_array_3d(int cols, int rows, int depths, int offset, int type)
Allocate memory for a N_array_3d data structure.
N_array_2d * N_alloc_array_2d(int cols, int rows, int offset, int type)
Allocate memory for a N_array_2d data structure.
void N_put_array_2d_d_value(N_array_2d *data, int col, int row, DCELL value)
Writes a DCELL value to the N_array_2d struct at position col, row.
void * G_incr_void_ptr(const void *ptr, size_t size)
Advance void pointer.
DCELL N_get_array_2d_d_value(N_array_2d *data, int col, int row)
Returns the value of type DCELL at position col, row.