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