GRASS 8 Programmer's Manual  8.5.0dev(2025)-c070206eb1
headerinfo.c
Go to the documentation of this file.
1 #include <grass/raster3d.h>
2 #include "raster3d_intern.h"
3 
4 /*---------------------------------------------------------------------------*/
5 
6 /*!
7  * \brief
8  *
9  * Returns the size of the region of <em>map</em> in cells.
10  *
11  * \param map
12  * \param rows
13  * \param cols
14  * \param depths
15  * \return void
16  */
17 void Rast3d_get_coords_map(RASTER3D_Map *map, int *rows, int *cols, int *depths)
18 {
19  *rows = map->region.rows;
20  *cols = map->region.cols;
21  *depths = map->region.depths;
22 }
23 
24 /*---------------------------------------------------------------------------*/
25 
26 void Rast3d_get_coords_map_window(RASTER3D_Map *map, int *rows, int *cols,
27  int *depths)
28 {
29  *rows = map->window.rows;
30  *cols = map->window.cols;
31  *depths = map->window.depths;
32 }
33 
34 /*---------------------------------------------------------------------------*/
35 
36 /*!
37  * \brief
38  *
39  * Returns the dimensions of the tile-cube used to tile the region of
40  * <em>map</em>. These numbers include partial tiles.
41  *
42  * \param map
43  * \param nx
44  * \param ny
45  * \param nz
46  * \return void
47  */
48 void Rast3d_get_nof_tiles_map(RASTER3D_Map *map, int *nx, int *ny, int *nz)
49 {
50  *nx = map->nx;
51  *ny = map->ny;
52  *nz = map->nz;
53 }
54 
55 /*---------------------------------------------------------------------------*/
56 
57 /*!
58  * \brief
59  *
60  * Returns the size of the region.
61  *
62  * \param map
63  * \param north
64  * \param south
65  * \param east
66  * \param west
67  * \param top
68  * \param bottom
69  * \return void
70  */
71 void Rast3d_get_region_map(RASTER3D_Map *map, double *north, double *south,
72  double *east, double *west, double *top,
73  double *bottom)
74 {
75  *north = map->region.north;
76  *south = map->region.south;
77  *east = map->region.east;
78  *west = map->region.west;
79  *top = map->region.top;
80  *bottom = map->region.bottom;
81 }
82 
83 /*---------------------------------------------------------------------------*/
84 
85 void Rast3d_get_window_map(RASTER3D_Map *map, double *north, double *south,
86  double *east, double *west, double *top,
87  double *bottom)
88 {
89  *north = map->window.north;
90  *south = map->window.south;
91  *east = map->window.east;
92  *west = map->window.west;
93  *top = map->window.top;
94  *bottom = map->window.bottom;
95 }
96 
97 /*---------------------------------------------------------------------------*/
98 
99 /*!
100  * \brief
101  *
102  * Returns in <em>region</em> the region of <em>map</em>.
103  *
104  * \param map
105  * \param region
106  * \return void
107  */
109 {
110  Rast3d_region_copy(region, &(map->region));
111 }
112 
113 /*---------------------------------------------------------------------------*/
114 
116 {
117  Rast3d_region_copy(window, &(map->window));
118 }
119 
120 /*---------------------------------------------------------------------------*/
121 
122 /*!
123  * \brief
124  *
125  * Returns the tile dimensions used for <em>map</em>.
126  *
127  * \param map
128  * \param x
129  * \param y
130  * \param z
131  * \return void
132  */
133 void Rast3d_get_tile_dimensions_map(RASTER3D_Map *map, int *x, int *y, int *z)
134 {
135  *x = map->tileX;
136  *y = map->tileY;
137  *z = map->tileZ;
138 }
139 
140 /*---------------------------------------------------------------------------*/
141 
142 /*!
143  * \brief
144  *
145  * Returns the type in which tiles of <em>map</em> are stored in memory.
146  *
147  * \param map
148  * \return int
149  */
151 {
152  return map->typeIntern;
153 }
154 
155 /*---------------------------------------------------------------------------*/
156 
157 /*!
158  * \brief
159  *
160  * Set the data unit defintiong
161  *
162  * \param map
163  * \param unit
164  * \return void
165  */
166 void Rast3d_set_unit(RASTER3D_Map *map, const char *unit)
167 {
168  map->unit = G_store(unit);
169 }
170 
171 /*---------------------------------------------------------------------------*/
172 
173 /*!
174  * \brief
175  *
176  * set Vertical unit from integer value defined in gis.h (U_METERS, ...)
177  *
178  * \param map
179  * \param vertical_unit
180  * \return void
181  */
182 void Rast3d_set_vertical_unit2(RASTER3D_Map *map, int vertical_unit)
183 {
184  map->vertical_unit = vertical_unit;
185 }
186 
187 /*---------------------------------------------------------------------------*/
188 
189 /*!
190  * \brief
191  *
192  * set Vertical unit from string
193  *
194  * \param map
195  * \param vertical_unit
196  * \return void
197  */
198 void Rast3d_set_vertical_unit(RASTER3D_Map *map, const char *vertical_unit)
199 {
200  map->vertical_unit = G_units(vertical_unit);
201 }
202 
203 /*---------------------------------------------------------------------------*/
204 
205 /*!
206  * \brief
207  *
208  * Return the data unit definition of <em>map</em>.
209  *
210  * \param map
211  * \return int
212  */
213 const char *Rast3d_get_unit(RASTER3D_Map *map)
214 {
215  return map->unit;
216 }
217 
218 /*---------------------------------------------------------------------------*/
219 
220 /*!
221  * \brief
222  *
223  * Returns the vertical unit of <em>map</em> as integer. Units are defined in
224  * gis.h.
225  *
226  * Vertical units may have temporal type
227  *
228  * \param map
229  * \return int
230  */
232 {
233  return map->vertical_unit;
234 }
235 
236 /*---------------------------------------------------------------------------*/
237 
238 /*!
239  * \brief
240  *
241  * Return the name of the unit of <em>map</em>. Units are defined in gis.h.
242  *
243  * Vertical units may have temporal type
244  *
245  * \param map
246  * \return int
247  */
249 {
250  return G_get_units_name(map->vertical_unit, 1, 0);
251 }
252 
253 /*---------------------------------------------------------------------------*/
254 
255 /*!
256  * \brief
257  *
258  * Returns the type with which tiles of <em>map</em> are stored on file.
259  *
260  * \param map
261  * \return int
262  */
264 {
265  return map->type;
266 }
267 
268 /*---------------------------------------------------------------------------*/
269 
270 /*!
271  * \brief
272  *
273  * Returns the precision used to store <em>map</em>.
274  *
275  * \param map
276  * \return int
277  */
279 {
280  return map->precision;
281 }
282 
283 /*---------------------------------------------------------------------------*/
284 
285 /*!
286  * \brief
287  *
288  * Returns 1 if <em>map</em> uses cache, returns 0 otherwise.
289  *
290  * \param map
291  * \return int
292  */
294 {
295  return map->useCache;
296 }
297 
298 /*!
299  * \brief
300  *
301  * Prints the header information of <em>map</em>.
302  *
303  * \param map
304  * \return void
305  */
307 {
308  double rangeMin, rangeMax;
309 
310  printf(
311  "File %s open for %sing:\n", map->fileName,
313  ? "writing"
314  : (map->operation == RASTER3D_READ_DATA ? "reading" : "unknown")));
315  printf("Version %i\n", map->version);
316  printf(" Fd = %d, Unit %s, Vertical Unit %s, Type: %s, ", map->data_fd,
317  map->unit, G_get_units_name(map->vertical_unit, 1, 0),
318  (map->type == FCELL_TYPE
319  ? "float"
320  : (map->type == DCELL_TYPE ? "double" : "unknown")));
321  printf("Type intern: %s\n",
322  (map->typeIntern == FCELL_TYPE
323  ? "float"
324  : (map->typeIntern == DCELL_TYPE ? "double" : "unknown")));
326  printf(" Compression: none\n");
327  else {
328  printf(" Compression:%s (%s%s) Precision: %s",
329  (map->compression ? "on" : "off"), (map->useLzw ? " lzw," : ""),
330  (map->useRle ? " rle," : ""),
331  (map->precision == -1 ? "all bits used\n" : "using"));
332  if (map->precision != -1)
333  printf(" %d bits\n", map->precision);
334  }
335 
336  if (!map->useCache)
337  printf(" Cache: none\n");
338  else {
339  printf(
340  " Cache: used%s\n",
341  (map->operation == RASTER3D_WRITE_DATA ? ", File Cache used" : ""));
342  }
343 
344  Rast3d_range_min_max(map, &rangeMin, &rangeMax);
345 
346  printf(" Region: (%f %f) (%f %f) (%f %f)\n", map->region.south,
347  map->region.north, map->region.west, map->region.east,
348  map->region.bottom, map->region.top);
349  printf(" (cols %5d rows %5d depths %5d)\n", map->region.cols,
350  map->region.rows, map->region.depths);
351  printf(" Num tiles (X %5d Y %5d Z %5d)\n", map->nx, map->ny,
352  map->nz);
353  printf(" Tile size (X %5d Y %5d Z %5d)\n", map->tileX,
354  map->tileY, map->tileZ);
355  printf(" Range (");
356  if (Rast3d_is_null_value_num(&rangeMin, DCELL_TYPE))
357  printf("NULL, ");
358  else
359  printf("%f, ", (double)rangeMin);
360  if (Rast3d_is_null_value_num(&rangeMax, DCELL_TYPE))
361  printf("NULL)\n");
362  else
363  printf("%f)\n", (double)rangeMax);
364  fflush(stdout);
365 }
const char * G_get_units_name(int, int, int)
Get localized units name.
Definition: units.c:202
int G_units(const char *)
Get units code by name.
Definition: units.c:406
char * G_store(const char *)
Copy string to allocated memory.
Definition: strings.c:87
int Rast3d_is_null_value_num(const void *, int)
Definition: null.c:12
void Rast3d_region_copy(RASTER3D_Region *, RASTER3D_Region *)
Copies the values of regionSrc into regionDst.
Definition: region.c:196
void Rast3d_range_min_max(RASTER3D_Map *, double *, double *)
Returns in min and max the minimum and maximum values of the range.
void Rast3d_get_coords_map_window(RASTER3D_Map *map, int *rows, int *cols, int *depths)
Definition: headerinfo.c:26
void Rast3d_get_window_map(RASTER3D_Map *map, double *north, double *south, double *east, double *west, double *top, double *bottom)
Definition: headerinfo.c:85
void Rast3d_getWindowStructMap(RASTER3D_Map *map, RASTER3D_Region *window)
Definition: headerinfo.c:115
void Rast3d_set_vertical_unit2(RASTER3D_Map *map, int vertical_unit)
set Vertical unit from integer value defined in gis.h (U_METERS, ...)
Definition: headerinfo.c:182
const char * Rast3d_get_vertical_unit(RASTER3D_Map *map)
Return the name of the unit of map. Units are defined in gis.h.
Definition: headerinfo.c:248
int Rast3d_file_type_map(RASTER3D_Map *map)
Returns the type with which tiles of map are stored on file.
Definition: headerinfo.c:263
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:48
int Rast3d_tile_use_cache_map(RASTER3D_Map *map)
Returns 1 if map uses cache, returns 0 otherwise.
Definition: headerinfo.c:293
int Rast3d_get_vertical_unit2(RASTER3D_Map *map)
Returns the vertical unit of map as integer. Units are defined in gis.h.
Definition: headerinfo.c:231
void Rast3d_get_region_struct_map(RASTER3D_Map *map, RASTER3D_Region *region)
Returns in region the region of map.
Definition: headerinfo.c:108
int Rast3d_tile_type_map(RASTER3D_Map *map)
Returns the type in which tiles of map are stored in memory.
Definition: headerinfo.c:150
int Rast3d_tile_precision_map(RASTER3D_Map *map)
Returns the precision used to store map.
Definition: headerinfo.c:278
void Rast3d_print_header(RASTER3D_Map *map)
Prints the header information of map.
Definition: headerinfo.c:306
void Rast3d_get_region_map(RASTER3D_Map *map, double *north, double *south, double *east, double *west, double *top, double *bottom)
Returns the size of the region.
Definition: headerinfo.c:71
void Rast3d_set_vertical_unit(RASTER3D_Map *map, const char *vertical_unit)
set Vertical unit from string
Definition: headerinfo.c:198
const char * Rast3d_get_unit(RASTER3D_Map *map)
Return the data unit definition of map.
Definition: headerinfo.c:213
void Rast3d_get_coords_map(RASTER3D_Map *map, int *rows, int *cols, int *depths)
Returns the size of the region of map in cells.
Definition: headerinfo.c:17
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:133
void Rast3d_set_unit(RASTER3D_Map *map, const char *unit)
Set the data unit defintiong.
Definition: headerinfo.c:166
#define RASTER3D_NO_COMPRESSION
Definition: raster3d.h:13
#define RASTER3D_WRITE_DATA
#define RASTER3D_READ_DATA
#define FCELL_TYPE
Definition: raster.h:12
#define DCELL_TYPE
Definition: raster.h:13
int precision
Definition: raster3d.h:109
int compression
Definition: raster3d.h:111
char * fileName
Definition: raster3d.h:74
RASTER3D_Region window
Definition: raster3d.h:85
RASTER3D_Region region
Definition: raster3d.h:82
int version
Definition: raster3d.h:72
char * unit
Definition: raster3d.h:91
int operation
Definition: raster3d.h:79
int vertical_unit
Definition: raster3d.h:92
int useCache
Definition: raster3d.h:160
int typeIntern
Definition: raster3d.h:150
double north
Definition: raster3d.h:49
double south
Definition: raster3d.h:49
double east
Definition: raster3d.h:50
double bottom
Definition: raster3d.h:51
double top
Definition: raster3d.h:51
double west
Definition: raster3d.h:50
#define x