GRASS 8 Programmer's Manual 8.6.0dev(2026)-f6f2c534ea
Loading...
Searching...
No Matches
changetype.c
Go to the documentation of this file.
1#include <stdio.h>
2#include <stdlib.h>
3#include <sys/types.h>
4#include <unistd.h>
5#include <grass/raster3d.h>
6
7/*---------------------------------------------------------------------------*/
8
9/*!
10 * \brief
11 *
12 * Makes a copy of <em>map</em> with name <em>nameOut</em> in which the
13 * cells are of type FCELL_TYPE if they are DCELL_TYPE in <em>map</em>,
14 * and in DCELL_TYPE otherwise.
15 * The source code can be found in <em>changetype.c</em>.
16 *
17 * \param map
18 * \param nameOut
19 * \return void
20 */
21void Rast3d_change_type(void *map, const char *nameOut)
22{
23 void *map2;
24 int x, y, z, saveType;
25 void *data, *data2;
26 RASTER3D_Region region;
27 int tileSize;
28 int tileX, tileY, tileZ, typeIntern, typeIntern2;
29 int tileXsave, tileYsave, tileZsave, nx, ny, nz;
30
33 : FCELL_TYPE);
35 Rast3d_get_tile_dimensions_map(map, &tileX, &tileY, &tileZ);
36 Rast3d_set_tile_dimension(tileX, tileY, tileZ);
37
38 Rast3d_get_region_struct_map(map, &region);
40 &region);
41
42 if (map2 == NULL)
43 Rast3d_fatal_error("Rast3d_change_type: error in Rast3d_open_cell_new");
44
47
48 data = Rast3d_alloc_tiles(map, 1);
49 if (data == NULL)
50 Rast3d_fatal_error("Rast3d_change_type: error in Rast3d_alloc_tiles");
52 if (data2 == NULL)
53 Rast3d_fatal_error("Rast3d_change_type: error in Rast3d_alloc_tiles");
54
55 Rast3d_get_nof_tiles_map(map2, &nx, &ny, &nz);
56 typeIntern = Rast3d_tile_type_map(map);
58 tileSize = tileX * tileY * tileZ;
59
60 for (z = 0; z < nz; z++)
61 for (y = 0; y < ny; y++)
62 for (x = 0; x < nx; x++) {
63 if (!Rast3d_read_tile(map, Rast3d_tile2tile_index(map, x, y, z),
64 data, typeIntern))
66 "Rast3d_change_type: error in Rast3d_read_tile");
67 Rast3d_copy_values(data, 0, typeIntern, data2, 0, typeIntern2,
68 tileSize);
73 "Rast3d_change_type: error in Rast3d_write_tile");
74 }
75
78 if (!Rast3d_close(map2))
79 Rast3d_fatal_error("Rast3d_change_type: error in Rast3d_close");
80}
#define NULL
Definition ccmath.h:32
void Rast3d_change_type(void *map, const char *nameOut)
Makes a copy of map with name nameOut in which the cells are of type FCELL_TYPE if they are DCELL_TYP...
Definition changetype.c:21
void Rast3d_copy_values(const void *, int, int, void *, int, int, int)
int Rast3d_file_type_map(RASTER3D_Map *)
Returns the type with which tiles of map are stored on file.
Definition headerinfo.c:263
int Rast3d_tile_type_map(RASTER3D_Map *)
Returns the type in which tiles of map are stored in memory.
Definition headerinfo.c:150
void Rast3d_get_nof_tiles_map(RASTER3D_Map *, int *, int *, int *)
Returns the dimensions of the tile-cube used to tile the region of map. These numbers include partial...
Definition headerinfo.c:48
void Rast3d_get_tile_dimensions_map(RASTER3D_Map *, int *, int *, int *)
Returns the tile dimensions used for map.
Definition headerinfo.c:133
void Rast3d_get_tile_dimension(int *, int *, int *)
get Tile Dimension
Definition defaults.c:252
void Rast3d_get_region_struct_map(RASTER3D_Map *, RASTER3D_Region *)
Returns in region the region of map.
Definition headerinfo.c:108
void * Rast3d_alloc_tiles(RASTER3D_Map *, int)
Is equivalent to Rast3d_alloc_tiles_type (map, nofTiles, Rast3d_file_type_map (map)).
Definition tilealloc.c:47
void Rast3d_free_tiles(void *)
Is equivalent to Rast3d_free (tiles);
Definition tilealloc.c:70
void Rast3d_set_tile_dimension(int, int, int)
set Tile Dimension
Definition defaults.c:227
void * Rast3d_open_cell_new(const char *, int, int, RASTER3D_Region *)
Opens new g3d-file with name in the current mapset. Tiles are stored in memory with type which must b...
void Rast3d_set_file_type(int)
set G3d file type
Definition defaults.c:197
int Rast3d_get_file_type(void)
get G3d file type
Definition defaults.c:212
int Rast3d_tile2tile_index(RASTER3D_Map *, int, int, int)
Returns tile-index corresponding to tile-coordinates (xTile, yTile, zTile).
Definition tilemath.c:47
int Rast3d_read_tile(RASTER3D_Map *, int, void *, int)
Reads tile with index tileIndex into the tile buffer. The cells are stored with type type which must ...
Definition tileread.c:150
int Rast3d_write_tile(RASTER3D_Map *, int, const void *, int)
Writes tile with index tileIndex to the file corresponding to map. It is assumed that the cells in ti...
Definition tilewrite.c:129
void Rast3d_fatal_error(const char *,...) __attribute__((format(printf
int Rast3d_close(RASTER3D_Map *)
Close 3D raster map files.
#define RASTER3D_USE_CACHE_DEFAULT
Definition raster3d.h:19
#define FCELL_TYPE
Definition raster.h:12
#define DCELL_TYPE
Definition raster.h:13
#define x