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