GRASS GIS 8 Programmer's Manual  8.5.0dev(2024)-602118adcc
raster/range.c
Go to the documentation of this file.
1 /*!
2  * \file lib/raster/range.c
3  *
4  * \brief Raster Library - Raster range file management
5  *
6  * (C) 2001-2009 GRASS Development Team
7  *
8  * This program is free software under the GNU General Public License
9  * (>=v2). Read the file COPYING that comes with GRASS for details.
10  *
11  * \author Original author CERL
12  */
13 
14 #include <unistd.h>
15 
16 #include <grass/raster.h>
17 #include <grass/glocale.h>
18 
19 #include "R.h"
20 
21 #define DEFAULT_CELL_MIN 1
22 #define DEFAULT_CELL_MAX 255
23 
24 static void init_rstats(struct R_stats *);
25 
26 /*!
27  \brief Remove floating-point range
28 
29  Note: For internal use only.
30 
31  \param name map name
32  */
33 void Rast__remove_fp_range(const char *name)
34 {
35  G_remove_misc("cell_misc", "f_range", name);
36 }
37 
38 /*!
39  * \brief Construct default range
40  *
41  * Sets the integer range to [1,255]
42  *
43  * \param[out] r pointer to Range structure which holds range info
44  */
46 {
49 }
50 
51 /*!
52  * \brief Read floating-point range
53  *
54  * Read the floating point range file <i>drange</i>. This file is
55  * written in binary using XDR format.
56  *
57  * An empty range file indicates that the min, max are undefined. This
58  * is a valid case, and the result should be an initialized range
59  * struct with no defined min/max. If the range file is missing and
60  * the map is a floating-point map, this function will create a
61  * default range by calling G_construct_default_range().
62  *
63  * \param name map name
64  * \param mapset mapset name
65  * \param drange pointer to FPRange structure which holds fp range
66  *
67  * \return 1 on success
68  * \return 2 range is empty
69  * \return -1 on error
70  */
71 int Rast_read_fp_range(const char *name, const char *mapset,
72  struct FPRange *drange)
73 {
74  struct Range range;
75  int fd;
76  char xdr_buf[2][XDR_DOUBLE_NBYTES];
77  DCELL dcell1, dcell2;
78 
79  Rast_init();
80  Rast_init_fp_range(drange);
81 
82  if (Rast_map_type(name, mapset) == CELL_TYPE) {
83  /* if map is integer
84  read integer range and convert it to double */
85 
86  if (Rast_read_range(name, mapset, &range) >= 0) {
87  /* if the integer range is empty */
88  if (range.first_time)
89  return 2;
90 
91  Rast_update_fp_range((DCELL)range.min, drange);
92  Rast_update_fp_range((DCELL)range.max, drange);
93  return 1;
94  }
95  return -1;
96  }
97 
98  fd = -1;
99 
100  if (G_find_file2_misc("cell_misc", "f_range", name, mapset)) {
101  fd = G_open_old_misc("cell_misc", "f_range", name, mapset);
102  if (fd < 0) {
103  G_warning(_("Unable to read fp range file for <%s>"),
104  G_fully_qualified_name(name, mapset));
105  return -1;
106  }
107 
108  if (read(fd, xdr_buf, sizeof(xdr_buf)) != sizeof(xdr_buf)) {
109  /* if the f_range file exists, but empty file, meaning Nulls */
110  close(fd);
111  G_debug(1, "Empty fp range file meaning Nulls for <%s>",
112  G_fully_qualified_name(name, mapset));
113  return 2;
114  }
115 
116  G_xdr_get_double(&dcell1, xdr_buf[0]);
117  G_xdr_get_double(&dcell2, xdr_buf[1]);
118 
119  Rast_update_fp_range(dcell1, drange);
120  Rast_update_fp_range(dcell2, drange);
121  close(fd);
122  }
123  else {
124  /* "f_range" file does not exist */
125  G_warning(_("Missing fp range file for <%s> (run r.support -s)"),
126  G_fully_qualified_name(name, mapset));
127  return -1;
128  }
129 
130  return 1;
131 }
132 
133 /*!
134  * \brief Read raster range (CELL)
135  *
136  * This routine reads the range information for the raster map
137  * <i>name</i> in <i>mapset</i> into the <i>range</i> structure.
138  *
139  * A diagnostic message is printed and -1 is returned if there is an error
140  * reading the range file. Otherwise, 0 is returned.
141  *
142  * Old range file (those with 4 numbers) should treat zeros in this
143  * file as NULL-values. New range files (those with just 2 numbers)
144  * should treat these numbers as real data (zeros are real data in
145  * this case). An empty range file indicates that the min, max are
146  * undefined. This is a valid case, and the result should be an
147  * initialized range struct with no defined min/max. If the range file
148  * is missing and the map is a floating-point map, this function will
149  * create a default range by calling G_construct_default_range().
150  *
151  * \param name map name
152  * \param mapset mapset name
153  * \param[out] range pointer to Range structure which holds range info
154  *
155  * \return -1 on error
156  * \return 1 on success
157  * \return 2 if range is empty
158  * \return 3 if raster map is floating-point, get range from quant rules
159  */
160 int Rast_read_range(const char *name, const char *mapset, struct Range *range)
161 {
162  FILE *fd;
163  CELL x[4];
164  char buf[200];
165  int n, count;
166  struct Quant quant;
167  struct FPRange drange;
168 
169  Rast_init_range(range);
170  fd = NULL;
171 
172  /* if map is not integer, read quant rules, and get limits */
173  if (Rast_map_type(name, mapset) != CELL_TYPE) {
174  DCELL dmin, dmax;
175 
176  if (Rast_read_quant(name, mapset, &quant) < 0) {
177  G_warning(_("Unable to read quant rules for raster map <%s>"),
178  G_fully_qualified_name(name, mapset));
179  return -1;
180  }
181  if (Rast_quant_is_truncate(&quant) || Rast_quant_is_round(&quant)) {
182  if (Rast_read_fp_range(name, mapset, &drange) >= 0) {
183  Rast_get_fp_range_min_max(&drange, &dmin, &dmax);
184  if (Rast_quant_is_truncate(&quant)) {
185  x[0] = (CELL)dmin;
186  x[1] = (CELL)dmax;
187  }
188  else { /* round */
189 
190  if (dmin > 0)
191  x[0] = (CELL)(dmin + .5);
192  else
193  x[0] = (CELL)(dmin - .5);
194  if (dmax > 0)
195  x[1] = (CELL)(dmax + .5);
196  else
197  x[1] = (CELL)(dmax - .5);
198  }
199  }
200  else
201  return -1;
202  }
203  else
204  Rast_quant_get_limits(&quant, &dmin, &dmax, &x[0], &x[1]);
205 
206  Rast_update_range(x[0], range);
207  Rast_update_range(x[1], range);
208  return 3;
209  }
210 
211  if (G_find_file2_misc("cell_misc", "range", name, mapset)) {
212  fd = G_fopen_old_misc("cell_misc", "range", name, mapset);
213  if (!fd) {
214  G_warning(_("Unable to read range file for <%s>"),
215  G_fully_qualified_name(name, mapset));
216  return -1;
217  }
218 
219  /* if range file exists but empty */
220  if (!fgets(buf, sizeof buf, fd)) {
221  if (fd)
222  fclose(fd);
223  return 2;
224  }
225 
226  x[0] = x[1] = x[2] = x[3] = 0;
227  count = sscanf(buf, "%d%d%d%d", &x[0], &x[1], &x[2], &x[3]);
228 
229  /* if wrong format */
230  if (count <= 0) {
231  if (fd)
232  fclose(fd);
233 
234  G_warning(_("Unable to read range file for <%s>"),
235  G_fully_qualified_name(name, mapset));
236  return -1;
237  }
238 
239  for (n = 0; n < count; n++) {
240  /* if count==4, the range file is old (4.1) and 0's in it
241  have to be ignored */
242  if (count < 4 || x[n])
243  Rast_update_range((CELL)x[n], range);
244  }
245  fclose(fd);
246  }
247  else {
248  /* "range" file does not exist */
249  G_warning(_("Missing range file for <%s> (run r.support -s)"),
250  G_fully_qualified_name(name, mapset));
251  return -1;
252  }
253 
254  return 1;
255 }
256 
257 /*!
258  * \brief Read raster stats
259  *
260  * Read the stats file <i>stats</i>. This file is
261  * written in binary using XDR format.
262  *
263  * An empty stats file indicates that all cells are NULL. This
264  * is a valid case, and the result should be an initialized rstats
265  * struct with no defined stats. If the stats file is missing
266  * this function will create a default stats with count = 0.
267  *
268  * \param name map name
269  * \param mapset mapset name
270  * \param rstats pointer to R_stats structure which holds raster stats
271  *
272  * \return 1 on success
273  * \return 2 stats is empty
274  * \return -1 on error or stats file does not exist
275  */
276 int Rast_read_rstats(const char *name, const char *mapset,
277  struct R_stats *rstats)
278 {
279  int fd;
280  char xdr_buf[2][XDR_DOUBLE_NBYTES];
281  DCELL dcell1, dcell2;
282  unsigned char cc[8];
283  char nbytes;
284  int i;
286 
287  Rast_init();
288  init_rstats(rstats);
289 
290  fd = -1;
291 
292  if (!G_find_file2_misc("cell_misc", "stats", name, mapset)) {
293  G_debug(1, "Stats file does not exist");
294  return -1;
295  }
296 
297  fd = G_open_old_misc("cell_misc", "stats", name, mapset);
298  if (fd < 0) {
299  G_warning(_("Unable to read stats file for <%s>"),
300  G_fully_qualified_name(name, mapset));
301  return -1;
302  }
303 
304  if (read(fd, xdr_buf, sizeof(xdr_buf)) != sizeof(xdr_buf)) {
305  /* if the stats file exists, but empty file, meaning Nulls */
306  close(fd);
307  G_debug(1, "Empty stats file meaning Nulls for <%s>",
308  G_fully_qualified_name(name, mapset));
309  return 2;
310  }
311 
312  G_xdr_get_double(&dcell1, xdr_buf[0]);
313  G_xdr_get_double(&dcell2, xdr_buf[1]);
314 
315  rstats->sum = dcell1;
316  rstats->sumsq = dcell2;
317 
318  /* count; see cell_values_int() in get_row.c */
319  nbytes = 1;
320  if (read(fd, &nbytes, 1) != 1) {
321  /* if the stats file exists, but empty file, meaning Nulls */
322  close(fd);
323  G_debug(1, "Unable to read byte count in stats file for <%s>",
324  G_fully_qualified_name(name, mapset));
325  return -1;
326  }
327 
328  count = 0;
329  if (nbytes == 0)
330  return 1;
331 
332  if (nbytes < 1 || (unsigned char)nbytes > sizeof(grass_int64)) {
333  close(fd);
334  G_debug(1, "Invalid byte count in stats file for <%s>",
335  G_fully_qualified_name(name, mapset));
336  return -1;
337  }
338  if (read(fd, cc, nbytes) != nbytes) {
339  /* incorrect number of bytes for count */
340  close(fd);
341  G_debug(1, "Unable to read count in stats file for <%s>",
342  G_fully_qualified_name(name, mapset));
343  return -1;
344  }
345 
346  /* copy byte by byte */
347  for (i = nbytes - 1; i >= 0; i--) {
348  count = (count << 8);
349  count = count + cc[i];
350  }
351  rstats->count = count;
352 
353  close(fd);
354 
355  return 1;
356 }
357 
358 /*!
359  * \brief Write raster range file
360  *
361  * This routine writes the range information for the raster map
362  * <i>name</i> in the current mapset from the <i>range</i> structure.
363  * A diagnostic message is printed and -1 is returned if there is an
364  * error writing the range file. Otherwise, 0 is returned.
365  *
366  * This routine only writes 2 numbers (min,max) to the range
367  * file, instead of the 4 (pmin,pmax,nmin,nmax) previously written.
368  * If there is no defined min,max, an empty file is written.
369  *
370  * \param name map name
371  * \param range pointer to Range structure which holds range info
372  */
373 void Rast_write_range(const char *name, const struct Range *range)
374 {
375  FILE *fp;
376 
377  Rast_write_rstats(name, &(range->rstats));
378 
379  if (Rast_map_type(name, G_mapset()) != CELL_TYPE) {
380  G_remove_misc("cell_misc", "range",
381  name); /* remove the old file with this name */
382  G_fatal_error(_("Unable to write range file for <%s>"), name);
383  }
384 
385  fp = G_fopen_new_misc("cell_misc", "range", name);
386  if (!fp) {
387  G_remove_misc("cell_misc", "range",
388  name); /* remove the old file with this name */
389  G_fatal_error(_("Unable to write range file for <%s>"), name);
390  }
391 
392  /* if range has been updated */
393  if (!range->first_time)
394  fprintf(fp, "%ld %ld\n", (long)range->min, (long)range->max);
395 
396  fclose(fp);
397 }
398 
399 /*!
400  * \brief Write raster range file (floating-point)
401  *
402  * Write the floating point range file <tt>f_range</tt>. This file is
403  * written in binary using XDR format. If there is no defined min/max
404  * in <em>range</em>, an empty <tt>f_range</tt> file is created.
405  *
406  * \param name map name
407  * \param range pointer to FPRange which holds fp range info
408  */
409 void Rast_write_fp_range(const char *name, const struct FPRange *range)
410 {
411  int fd;
412  char xdr_buf[2][XDR_DOUBLE_NBYTES];
413 
414  Rast_init();
415 
416  Rast_write_rstats(name, &(range->rstats));
417 
418  fd = G_open_new_misc("cell_misc", "f_range", name);
419  if (fd < 0) {
420  G_remove_misc("cell_misc", "f_range", name);
421  G_fatal_error(_("Unable to write range file for <%s>"), name);
422  }
423 
424  /* if range hasn't been updated, write empty file meaning Nulls */
425  if (range->first_time) {
426  close(fd);
427  return;
428  }
429 
430  G_xdr_put_double(xdr_buf[0], &range->min);
431  G_xdr_put_double(xdr_buf[1], &range->max);
432 
433  if (write(fd, xdr_buf, sizeof(xdr_buf)) != sizeof(xdr_buf)) {
434  G_remove_misc("cell_misc", "f_range", name);
435  G_fatal_error(_("Unable to write range file for <%s>"), name);
436  }
437 
438  close(fd);
439 }
440 
441 /*!
442  * \brief Write raster stats file
443  *
444  * Write the stats file <tt>stats</tt>. This file is
445  * written in binary using XDR format. If the count is < 1
446  * in <em>rstats</em>, an empty <tt>stats</tt> file is created.
447  *
448  * \param name map name
449  * \param rstats pointer to R_stats which holds stats info
450  */
451 void Rast_write_rstats(const char *name, const struct R_stats *rstats)
452 {
453  int fd;
454  char xdr_buf[2][XDR_DOUBLE_NBYTES];
455  unsigned char cc[8];
456  char nbytes;
457  unsigned int i;
459 
460  Rast_init();
461 
462  fd = G_open_new_misc("cell_misc", "stats", name);
463  if (fd < 0) {
464  G_remove_misc("cell_misc", "stats", name);
465  G_fatal_error(_("Unable to write stats file for <%s>"), name);
466  }
467 
468  /* if count is zero, write empty file meaning Nulls */
469  if (rstats->count < 1) {
470  close(fd);
471  return;
472  }
473 
474  G_xdr_put_double(xdr_buf[0], &rstats->sum);
475  G_xdr_put_double(xdr_buf[1], &rstats->sumsq);
476 
477  if (write(fd, xdr_buf, sizeof(xdr_buf)) != sizeof(xdr_buf)) {
478  G_remove_misc("cell_misc", "stats", name);
479  G_fatal_error(_("Unable to write stats file for <%s>"), name);
480  }
481 
482  /* count; see convert_int() in put_row.c */
483  count = rstats->count;
484  nbytes = 0;
485  /* copy byte by byte */
486  for (i = 0; i < sizeof(grass_int64); i++) {
487  cc[i] = count & 0xff;
488  count >>= 8;
489  if (cc[i])
490  nbytes = i;
491  }
492  nbytes++;
493 
494  /* number of bytes needed for count */
495  if (write(fd, &nbytes, 1) != 1) {
496  G_remove_misc("cell_misc", "stats", name);
497  G_fatal_error(_("Unable to write stats file for <%s>"), name);
498  }
499 
500  if (nbytes > 0 && write(fd, cc, nbytes) != nbytes) {
501  G_remove_misc("cell_misc", "stats", name);
502  G_fatal_error(_("Unable to write stats file for <%s>"), name);
503  }
504 
505  close(fd);
506 }
507 
508 /*!
509  * \brief Update range structure (CELL)
510  *
511  * Compares the <i>cat</i> value with the minimum and maximum values
512  * in the <i>range</i> structure, modifying the range if <i>cat</i>
513  * extends the range.
514  *
515  * NULL-values must be detected and ignored.
516  *
517  * \param cat raster value
518  * \param range pointer to Range structure which holds range info
519  */
520 void Rast_update_range(CELL cat, struct Range *range)
521 {
522  if (!Rast_is_c_null_value(&cat)) {
523  if (range->first_time) {
524  range->first_time = 0;
525  range->min = cat;
526  range->max = cat;
527  return;
528  }
529  if (cat < range->min)
530  range->min = cat;
531  if (cat > range->max)
532  range->max = cat;
533  }
534 }
535 
536 /*!
537  * \brief Update range structure (floating-point)
538  *
539  * Compares the <i>cat</i> value with the minimum and maximum values
540  * in the <i>range</i> structure, modifying the range if <i>cat</i>
541  * extends the range.
542  *
543  * NULL-values must be detected and ignored.
544  *
545  * \param val raster value
546  * \param range pointer to Range structure which holds range info
547  */
548 void Rast_update_fp_range(DCELL val, struct FPRange *range)
549 {
550  if (!Rast_is_d_null_value(&val)) {
551  if (range->first_time) {
552  range->first_time = 0;
553  range->min = val;
554  range->max = val;
555  return;
556  }
557  if (val < range->min)
558  range->min = val;
559  if (val > range->max)
560  range->max = val;
561  }
562 }
563 
564 /*!
565  * \brief Update range structure based on raster row (CELL)
566  *
567  * This routine updates the <i>range</i> data just like
568  * Rast_update_range(), but for <i>n</i> values from the <i>cell</i>
569  * array.
570  *
571  * \param cell raster values
572  * \param n number of values
573  * \param range pointer to Range structure which holds range info
574  */
575 void Rast_row_update_range(const CELL *cell, int n, struct Range *range)
576 {
577  Rast__row_update_range(cell, n, range, 0);
578 }
579 
580 /*!
581  * \brief Update range structure based on raster row
582  *
583  * Note: for internal use only.
584  *
585  * \param cell raster values
586  * \param n number of values
587  * \param range pointer to Range structure which holds range info
588  * \param ignore_zeros ignore zeros
589  */
590 void Rast__row_update_range(const CELL *cell, int n, struct Range *range,
591  int ignore_zeros)
592 {
593  CELL cat;
594 
595  while (n-- > 0) {
596  cat = *cell++;
597  if (Rast_is_c_null_value(&cat) || (ignore_zeros && !cat))
598  continue;
599  if (range->first_time) {
600  range->first_time = 0;
601  range->min = cat;
602  range->max = cat;
603 
604  range->rstats.sum = cat;
605  range->rstats.sumsq = (DCELL)cat * cat;
606 
607  range->rstats.count = 1;
608 
609  continue;
610  }
611  if (cat < range->min)
612  range->min = cat;
613  if (cat > range->max)
614  range->max = cat;
615 
616  range->rstats.sum += cat;
617  range->rstats.sumsq += (DCELL)cat * cat;
618 
619  range->rstats.count += 1;
620  }
621 }
622 
623 /*!
624  * \brief Update range structure based on raster row (floating-point)
625  *
626  * This routine updates the <i>range</i> data just like
627  * Rast_update_range(), but for <i>n</i> values from the <i>cell</i>
628  * array.
629  *
630  * \param cell raster values
631  * \param n number of values
632  * \param range pointer to Range structure which holds range info
633  * \param data_type raster type (CELL, FCELL, DCELL)
634  */
635 void Rast_row_update_fp_range(const void *rast, int n, struct FPRange *range,
636  RASTER_MAP_TYPE data_type)
637 {
638  size_t size = Rast_cell_size(data_type);
639  DCELL val = 0.0;
640 
641  while (n-- > 0) {
642  switch (data_type) {
643  case CELL_TYPE:
644  val = (DCELL) * ((CELL *)rast);
645  break;
646  case FCELL_TYPE:
647  val = (DCELL) * ((FCELL *)rast);
648  break;
649  case DCELL_TYPE:
650  val = *((DCELL *)rast);
651  break;
652  }
653 
654  if (Rast_is_null_value(rast, data_type)) {
655  rast = G_incr_void_ptr(rast, size);
656  continue;
657  }
658  if (range->first_time) {
659  range->first_time = 0;
660  range->min = val;
661  range->max = val;
662 
663  range->rstats.sum = val;
664  range->rstats.sumsq = val * val;
665  range->rstats.count = 1;
666  }
667  else {
668  if (val < range->min)
669  range->min = val;
670  if (val > range->max)
671  range->max = val;
672 
673  range->rstats.sum += val;
674  range->rstats.sumsq += val * val;
675  range->rstats.count += 1;
676  }
677 
678  rast = G_incr_void_ptr(rast, size);
679  }
680 }
681 
682 /*!
683  * \brief Initialize range structure
684  *
685  * Initializes the <i>range</i> structure for updates by
686  * Rast_update_range() and Rast_row_update_range().
687  *
688  * Must set a flag in the range structure that indicates that no
689  * min/max have been defined - probably a <tt>"first"</tt> boolean
690  * flag.
691  *
692  * \param range pointer to Range structure which holds range info
693  */
694 void Rast_init_range(struct Range *range)
695 {
696  Rast_set_c_null_value(&(range->min), 1);
697  Rast_set_c_null_value(&(range->max), 1);
698 
699  init_rstats(&range->rstats);
700 
701  range->first_time = 1;
702 }
703 
704 /*!
705  * \brief Get range min and max
706  *
707  * The minimum and maximum CELL values are extracted from the
708  * <i>range</i> structure.
709  *
710  * If the range structure has no defined min/max (first!=0) there will
711  * not be a valid range. In this case the min and max returned must be
712  * the NULL-value.
713  *
714  * \param range pointer to Range structure which holds range info
715  * \param[out] min minimum value
716  * \param[out] max maximum value
717  */
718 void Rast_get_range_min_max(const struct Range *range, CELL *min, CELL *max)
719 {
720  if (range->first_time) {
723  }
724  else {
725  if (Rast_is_c_null_value(&(range->min)))
727  else
728  *min = range->min;
729 
730  if (Rast_is_c_null_value(&(range->max)))
732  else
733  *max = range->max;
734  }
735 }
736 
737 /*!
738  * \brief Initialize fp range
739  *
740  * Must set a flag in the range structure that indicates that no
741  * min/max have been defined - probably a <tt>"first"</tt> boolean
742  * flag.
743  *
744  * \param range pointer to FPRange which holds fp range info
745  */
746 void Rast_init_fp_range(struct FPRange *range)
747 {
748  Rast_set_d_null_value(&(range->min), 1);
749  Rast_set_d_null_value(&(range->max), 1);
750 
751  init_rstats(&range->rstats);
752 
753  range->first_time = 1;
754 }
755 
756 /*!
757  * \brief Get minimum and maximum value from fp range
758  *
759  * Extract the min/max from the range structure <i>range</i>. If the
760  * range structure has no defined min/max (first!=0) there will not be
761  * a valid range. In this case the min and max returned must be the
762  * NULL-value.
763  *
764  * \param range pointer to FPRange which holds fp range info
765  * \param[out] min minimum value
766  * \param[out] max maximum value
767  */
768 void Rast_get_fp_range_min_max(const struct FPRange *range, DCELL *min,
769  DCELL *max)
770 {
771  if (range->first_time) {
774  }
775  else {
776  if (Rast_is_d_null_value(&(range->min)))
778  else
779  *min = range->min;
780 
781  if (Rast_is_d_null_value(&(range->max)))
783  else
784  *max = range->max;
785  }
786 }
787 
788 static void init_rstats(struct R_stats *rstats)
789 {
792  rstats->count = 0;
793 }
#define XDR_DOUBLE_NBYTES
Definition: R.h:8
#define NULL
Definition: ccmath.h:32
FILE * G_fopen_old_misc(const char *, const char *, const char *, const char *)
open a database misc file for reading
Definition: open_misc.c:205
void void void void G_fatal_error(const char *,...) __attribute__((format(printf
void G_warning(const char *,...) __attribute__((format(printf
int G_open_old_misc(const char *, const char *, const char *, const char *)
open a database misc file for reading
Definition: open_misc.c:132
FILE * G_fopen_new_misc(const char *, const char *, const char *)
open a new database misc file
Definition: open_misc.c:178
const char * G_mapset(void)
Get current mapset name.
Definition: gis/mapset.c:33
const char * G_find_file2_misc(const char *, const char *, const char *, const char *)
Searches for a misc file from the mapset search list or in a specified mapset. (look but don't touch)
Definition: find_file.c:257
int G_remove_misc(const char *, const char *, const char *)
Remove a database misc file.
Definition: remove.c:65
void G_xdr_put_double(void *, const double *)
Definition: gis/xdr.c:94
char * G_fully_qualified_name(const char *, const char *)
Get fully qualified element name.
Definition: nme_in_mps.c:101
void G_xdr_get_double(double *, const void *)
Definition: gis/xdr.c:89
#define G_incr_void_ptr(ptr, size)
Definition: defs/gis.h:81
int G_open_new_misc(const char *, const char *, const char *)
open a new database misc file
Definition: open_misc.c:111
int G_debug(int, const char *,...) __attribute__((format(printf
int Rast_is_null_value(const void *, RASTER_MAP_TYPE)
To check if a raster value is set to NULL.
Definition: null_val.c:176
void Rast_init(void)
Initialize GRASS GIS engine.
Definition: raster/init.c:43
int Rast_quant_get_limits(const struct Quant *, DCELL *, DCELL *, CELL *, CELL *)
Returns the minimum and maximum cell and dcell values of all the ranges defined.
Definition: quant.c:281
void Rast_set_d_null_value(DCELL *, int)
To set a number of DCELL raster values to NULL.
Definition: null_val.c:153
int Rast_read_quant(const char *, const char *, struct Quant *)
Reads quantization rules for name in mapset and stores them in the quantization structure....
Definition: quant_rw.c:187
int Rast_quant_is_round(const struct Quant *)
Returns whether or not quant rules are set to round map.
Definition: quant.c:204
void Rast_set_c_null_value(CELL *, int)
To set a number of CELL raster values to NULL.
Definition: null_val.c:124
RASTER_MAP_TYPE Rast_map_type(const char *, const char *)
Determine raster data type.
Definition: raster/open.c:894
size_t Rast_cell_size(RASTER_MAP_TYPE)
Returns size of a raster cell in bytes.
Definition: alloc_cell.c:38
#define Rast_is_d_null_value(dcellVal)
Definition: defs/raster.h:408
#define Rast_is_c_null_value(cellVal)
Definition: defs/raster.h:404
int Rast_quant_is_truncate(const struct Quant *)
Returns whether or not quant rules are set to truncate map.
Definition: quant.c:192
#define min(x, y)
Definition: draw2.c:29
#define max(x, y)
Definition: draw2.c:30
float FCELL
Definition: gis.h:630
int64_t grass_int64
Definition: gis.h:635
double DCELL
Definition: gis.h:629
int CELL
Definition: gis.h:628
#define _(str)
Definition: glocale.h:10
int count
const char * name
Definition: named_colr.c:6
void Rast_write_fp_range(const char *name, const struct FPRange *range)
Write raster range file (floating-point)
Definition: raster/range.c:409
void Rast__row_update_range(const CELL *cell, int n, struct Range *range, int ignore_zeros)
Update range structure based on raster row.
Definition: raster/range.c:590
int Rast_read_range(const char *name, const char *mapset, struct Range *range)
Read raster range (CELL)
Definition: raster/range.c:160
void Rast__remove_fp_range(const char *name)
Remove floating-point range.
Definition: raster/range.c:33
void Rast_construct_default_range(struct Range *range)
Construct default range.
Definition: raster/range.c:45
void Rast_update_fp_range(DCELL val, struct FPRange *range)
Update range structure (floating-point)
Definition: raster/range.c:548
void Rast_write_rstats(const char *name, const struct R_stats *rstats)
Write raster stats file.
Definition: raster/range.c:451
int Rast_read_rstats(const char *name, const char *mapset, struct R_stats *rstats)
Read raster stats.
Definition: raster/range.c:276
void Rast_row_update_fp_range(const void *rast, int n, struct FPRange *range, RASTER_MAP_TYPE data_type)
Update range structure based on raster row (floating-point)
Definition: raster/range.c:635
void Rast_write_range(const char *name, const struct Range *range)
Write raster range file.
Definition: raster/range.c:373
void Rast_init_range(struct Range *range)
Initialize range structure.
Definition: raster/range.c:694
int Rast_read_fp_range(const char *name, const char *mapset, struct FPRange *drange)
Read floating-point range.
Definition: raster/range.c:71
void Rast_update_range(CELL cat, struct Range *range)
Update range structure (CELL)
Definition: raster/range.c:520
#define DEFAULT_CELL_MAX
Definition: raster/range.c:22
void Rast_init_fp_range(struct FPRange *range)
Initialize fp range.
Definition: raster/range.c:746
#define DEFAULT_CELL_MIN
Definition: raster/range.c:21
void Rast_get_range_min_max(const struct Range *range, CELL *min, CELL *max)
Get range min and max.
Definition: raster/range.c:718
void Rast_row_update_range(const CELL *cell, int n, struct Range *range)
Update range structure based on raster row (CELL)
Definition: raster/range.c:575
void Rast_get_fp_range_min_max(const struct FPRange *range, DCELL *min, DCELL *max)
Get minimum and maximum value from fp range.
Definition: raster/range.c:768
#define FCELL_TYPE
Definition: raster.h:12
#define DCELL_TYPE
Definition: raster.h:13
#define CELL_TYPE
Definition: raster.h:11
int RASTER_MAP_TYPE
Definition: raster.h:25
struct R_stats rstats
Definition: raster.h:222
DCELL min
Definition: raster.h:219
int first_time
Definition: raster.h:221
DCELL max
Definition: raster.h:220
Definition: raster.h:80
DCELL sumsq
Definition: raster.h:207
grass_int64 count
Definition: raster.h:208
DCELL sum
Definition: raster.h:206
Definition: raster.h:211
CELL min
Definition: raster.h:212
int first_time
Definition: raster.h:214
CELL max
Definition: raster.h:213
struct R_stats rstats
Definition: raster.h:215
#define x