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