GRASS GIS 8 Programmer's Manual  8.5.0dev(2024)-36359e2344
changeprecision.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> which is
13  * written with <em>precision</em>.
14  * The source code can be found in <em>changeprecision.c</em>.
15  *
16  * \param map
17  * \param precision
18  * \param nameOut
19  * \return void
20  */
21 
22 void Rast3d_change_precision(void *map, int precision, const char *nameOut)
23 {
24  void *map2;
25  int x, y, z, savePrecision, saveCompression;
26  char *data;
27  RASTER3D_Region region;
28  int typeIntern;
29  int nx, ny, nz;
30  int tileXsave, tileYsave, tileZsave, tileX, tileY, tileZ, saveType;
31 
32  saveType = Rast3d_get_file_type();
33  /* Rast3d_set_file_type (Rast3d_file_type_map (map)); */
34  Rast3d_get_compression_mode(&saveCompression, &savePrecision);
36  Rast3d_get_tile_dimension(&tileXsave, &tileYsave, &tileZsave);
37  Rast3d_get_tile_dimensions_map(map, &tileX, &tileY, &tileZ);
38  Rast3d_set_tile_dimension(tileX, tileY, tileZ);
39 
40  typeIntern = Rast3d_tile_type_map(map);
41  Rast3d_get_region_struct_map(map, &region);
42 
43  map2 = Rast3d_open_cell_new(nameOut, typeIntern, RASTER3D_USE_CACHE_DEFAULT,
44  &region);
45  if (map2 == NULL)
47  "Rast3d_change_precision: error in Rast3d_open_cell_new");
48 
49  Rast3d_set_file_type(saveType);
50  Rast3d_set_compression_mode(saveCompression, savePrecision);
51  Rast3d_set_tile_dimension(tileXsave, tileYsave, tileZsave);
52 
53  data = Rast3d_alloc_tiles(map, 1);
54  if (data == NULL)
56  "Rast3d_change_precision: error in Rast3d_alloc_tiles");
57  Rast3d_get_nof_tiles_map(map2, &nx, &ny, &nz);
58 
59  for (z = 0; z < nz; z++)
60  for (y = 0; y < ny; y++)
61  for (x = 0; x < nx; x++) {
62  if (!Rast3d_read_tile(map, Rast3d_tile2tile_index(map, x, y, z),
63  data, typeIntern))
65  "Rast3d_change_precision: error in Rast3d_read_tile");
66  if (!Rast3d_write_tile(map2,
67  Rast3d_tile2tile_index(map2, x, y, z),
68  data, typeIntern))
70  "Rast3d_change_precision: error in Rast3d_write_tile");
71  }
72 
73  Rast3d_free_tiles(data);
74  if (!Rast3d_close(map2))
75  Rast3d_fatal_error("Rast3d_change_precision: error in Rast3d_close");
76 }
#define NULL
Definition: ccmath.h:32
void Rast3d_change_precision(void *map, int precision, const char *nameOut)
Makes a copy of map with name nameOut which is written with precision. The source code can be found i...
int Rast3d_tile_type_map(RASTER3D_Map *)
Returns the type in which tiles of map are stored in memory.
Definition: headerinfo.c:156
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:50
void Rast3d_get_tile_dimensions_map(RASTER3D_Map *, int *, int *, int *)
Returns the tile dimensions used for map.
Definition: headerinfo.c:138
void Rast3d_get_tile_dimension(int *, int *, int *)
get Tile Dimension
Definition: defaults.c:262
void Rast3d_get_region_struct_map(RASTER3D_Map *, RASTER3D_Region *)
Returns in region the region of map.
Definition: headerinfo.c:112
void Rast3d_free_tiles(void *)
Is equivalent to Rast3d_free (tiles);
Definition: tilealloc.c:73
void Rast3d_set_tile_dimension(int, int, int)
set Tile Dimension
Definition: defaults.c:236
void Rast3d_set_file_type(int)
set G3d file type
Definition: defaults.c:204
int Rast3d_get_file_type(void)
get G3d file type
Definition: defaults.c:220
void * Rast3d_alloc_tiles(RASTER3D_Map *, int)
Is equivalent to Rast3d_alloc_tiles_type (map, nofTiles, Rast3d_file_type_map (map)).
Definition: tilealloc.c:49
int Rast3d_tile2tile_index(RASTER3D_Map *, int, int, int)
Returns tile-index corresponding to tile-coordinates (xTile, yTile, zTile).
Definition: tilemath.c:49
void Rast3d_get_compression_mode(int *, int *)
Gets compression mode.
Definition: defaults.c:127
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:151
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_compression_mode(int, int)
set compression mode
Definition: defaults.c:94
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:126
void Rast3d_fatal_error(const char *,...) __attribute__((format(printf
int Rast3d_close(RASTER3D_Map *)
Close 3D raster map files.
#define RASTER3D_COMPRESSION
Definition: raster3d.h:14
#define RASTER3D_USE_CACHE_DEFAULT
Definition: raster3d.h:19
#define x