GRASS GIS 7 Programmer's Manual
Go to the documentation of this file.
2 #include <stdio.h>
3 #include <stdlib.h>
4 #include <sys/types.h>
5 #include <unistd.h>
6 #include <grass/raster3d.h>
8 /*---------------------------------------------------------------------------*/
11 /*!
12  * \brief
13  *
14  * Makes a copy of <em>map</em> with name <em>nameOut</em> in which the
15  * cells are of type FCELL_TYPE if they are DCELL_TYPE in <em>map</em>,
16  * and in DCELL_TYPE otherwise.
17  * The source code can be found in <em>changetype.c</em>.
18  *
19  * \param map
20  * \param nameOut
21  * \return void
22  */
24 void Rast3d_change_type(void *map, const char *nameOut)
25 {
26  void *map2;
27  int x, y, z, saveType;
28  void *data, *data2;
29  RASTER3D_Region region;
30  int tileSize;
31  int tileX, tileY, tileZ, typeIntern, typeIntern2;
32  int tileXsave, tileYsave, tileZsave, nx, ny, nz;
34  saveType = Rast3d_get_file_type();
37  Rast3d_get_tile_dimension(&tileXsave, &tileYsave, &tileZsave);
38  Rast3d_get_tile_dimensions_map(map, &tileX, &tileY, &tileZ);
39  Rast3d_set_tile_dimension(tileX, tileY, tileZ);
41  Rast3d_get_region_struct_map(map, &region);
42  map2 =
43  Rast3d_open_cell_new(nameOut, FCELL_TYPE, RASTER3D_USE_CACHE_DEFAULT, &region);
45  if (map2 == NULL)
46  Rast3d_fatal_error("Rast3d_change_type: error in Rast3d_open_cell_new");
48  Rast3d_set_file_type(saveType);
49  Rast3d_set_tile_dimension(tileXsave, tileYsave, tileZsave);
51  data = Rast3d_alloc_tiles(map, 1);
52  if (data == NULL)
53  Rast3d_fatal_error("Rast3d_change_type: error in Rast3d_alloc_tiles");
54  data2 = Rast3d_alloc_tiles(map2, 1);
55  if (data2 == NULL)
56  Rast3d_fatal_error("Rast3d_change_type: error in Rast3d_alloc_tiles");
58  Rast3d_get_nof_tiles_map(map2, &nx, &ny, &nz);
59  typeIntern = Rast3d_tile_type_map(map);
60  typeIntern2 = Rast3d_tile_type_map(map2);
61  tileSize = tileX * tileY * tileZ;
63  for (z = 0; z < nz; z++)
64  for (y = 0; y < ny; y++)
65  for (x = 0; x < nx; x++) {
66  if (!Rast3d_read_tile(map, Rast3d_tile2tile_index(map, x, y, z), data,
67  typeIntern))
68  Rast3d_fatal_error("Rast3d_change_type: error in Rast3d_read_tile");
69  Rast3d_copy_values(data, 0, typeIntern, data2, 0, typeIntern2,
70  tileSize);
72  (map2, Rast3d_tile2tile_index(map2, x, y, z), data2,
73  typeIntern2))
74  Rast3d_fatal_error("Rast3d_change_type: error in Rast3d_write_tile");
75  }
77  Rast3d_free_tiles(data);
78  Rast3d_free_tiles(data2);
79  if (!Rast3d_close(map2))
80  Rast3d_fatal_error("Rast3d_change_type: error in Rast3d_close");
81 }
void * Rast3d_alloc_tiles(RASTER3D_Map *map, int nofTiles)
Is equivalent to Rast3d_alloc_tiles_type (map, nofTiles, Rast3d_file_type_map (map)).
Definition: tilealloc.c:50
Definition: raster3d.h:20
int Rast3d_file_type_map(RASTER3D_Map *map)
Returns the type with which tiles of map are stored on file.
Definition: headerinfo.c:281
int Rast3d_close(RASTER3D_Map *map)
Close 3D raster map files.
void Rast3d_copy_values(const void *src, int offsSrc, int typeSrc, void *dst, int offsDst, int typeDst, int nElts)
Definition: raster3d/misc.c:53
int Rast3d_tile2tile_index(RASTER3D_Map *map, int xTile, int yTile, int zTile)
Returns tile-index corresponding to tile-coordinates (xTile, yTile, zTile).
Definition: tilemath.c:52
void Rast3d_fatal_error(const char *msg,...)
Prints fatal error message.
int Rast3d_read_tile(RASTER3D_Map *map, int tileIndex, void *tile, int type)
Reads tile with index tileIndex into the tile buffer. The cells are stored with type type which must ...
Definition: tileread.c:145
int Rast3d_write_tile(RASTER3D_Map *map, int tileIndex, const void *tile, int type)
Writes tile with index tileIndex to the file corresponding to map. It is assumed that the cells in ti...
Definition: tilewrite.c:127
void Rast3d_free_tiles(void *tiles)
Is equivalent to Rast3d_free (tiles);
Definition: tilealloc.c:75
#define NULL
Definition: ccmath.h:32
#define x
void Rast3d_get_tile_dimensions_map(RASTER3D_Map *map, int *x, int *y, int *z)
Returns the tile dimensions used for map.
Definition: headerinfo.c:142
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:24
#define DCELL_TYPE
Definition: raster.h:13
void Rast3d_set_file_type(int type)
set G3d file type
Definition: defaults.c:210
void Rast3d_get_nof_tiles_map(RASTER3D_Map *map, int *nx, int *ny, int *nz)
Returns the dimensions of the tile-cube used to tile the region of map. These numbers include partial...
Definition: headerinfo.c:51
void Rast3d_get_region_struct_map(RASTER3D_Map *map, RASTER3D_Region *region)
Returns in region the region of map.
Definition: headerinfo.c:115
void Rast3d_set_tile_dimension(int tileX, int tileY, int tileZ)
set Tile Dimension
Definition: defaults.c:244
int Rast3d_tile_type_map(RASTER3D_Map *map)
Returns the type in which tiles of map are stored in memory.
Definition: headerinfo.c:161
#define FCELL_TYPE
Definition: raster.h:12
void * Rast3d_open_cell_new(const char *name, int typeIntern, int cache, RASTER3D_Region *region)
Opens new g3d-file with name in the current mapset. Tiles are stored in memory with type which must b...
void Rast3d_get_tile_dimension(int *tileX, int *tileY, int *tileZ)
get Tile Dimension
Definition: defaults.c:271
int Rast3d_get_file_type()
get G3d file type
Definition: defaults.c:227