81 #include <rpc/types.h>
84 #include <grass/glocale.h>
85 #define DEFAULT_CELL_MIN 1
86 #define DEFAULT_CELL_MAX 255
156 if (range.first_time)
180 if (!xdr_double(&xdr_str, &dcell1) || !xdr_double(&xdr_str, &dcell2))
192 sprintf(buf, _(
"can't read f_range file for [%s in %s]"), name, mapset);
233 struct FPRange drange;
244 "G_read_range(): can't read quant rules for fp map %s@%s",
259 x[0] = (CELL) (dmin + .5);
261 x[0] = (CELL) (dmin - .5);
263 x[1] = (CELL) (dmax + .5);
265 x[1] = (CELL) (dmax - .5);
285 if (!fgets(buf,
sizeof buf, fd))
288 x[0] = x[1] = x[2] = x[3] = 0;
289 count = sscanf(buf,
"%d%d%d%d", &x[0], &x[1], &x[2], &x[3]);
295 for (n = 0; n <
count; n++) {
298 if (count < 4 || x[n])
308 sprintf(buf, _(
"can't read range file for [%s in %s]"), name, mapset);
340 sprintf(buf,
"G_write_range(): the map is floating point!");
347 if (range->first_time)
353 fprintf(fd,
"%ld %ld\n", (
long)range->min, (
long)range->max);
359 sprintf(buf, _(
"can't write range file for [%s in %s]"),
386 sprintf(buf,
"cell_misc/%s", name);
391 if (range->first_time)
401 if (!xdr_double(&xdr_str, (
double *)&(range->min)))
403 if (!xdr_double(&xdr_str, (
double *)&(range->max)))
406 write(fd, xdr_buf, XDR_DOUBLE_NBYTES * 2);
412 sprintf(buf, _(
"can't write range file for [%s in %s]"),
439 if (range->first_time) {
440 range->first_time = 0;
445 if (cat < range->
min)
447 if (cat > range->max)
459 if (range->first_time) {
460 range->first_time = 0;
465 if (val < range->
min)
467 if (val > range->max)
499 struct Range *
range,
int ignore_zeros)
507 if (range->first_time) {
508 range->first_time = 0;
513 if (cat < range->
min)
515 if (cat > range->max)
525 struct FPRange *
range, RASTER_MAP_TYPE data_type)
532 val = (DCELL) * ((CELL *) rast);
535 val = (DCELL) * ((FCELL *) rast);
538 val = *((DCELL *) rast);
546 if (range->first_time) {
547 range->first_time = 0;
552 if (val < range->
min)
554 if (val > range->max)
583 range->first_time = 1;
610 if (range->first_time) {
646 range->first_time = 1;
670 if (range->first_time) {
char * G_mapset(void)
current mapset name
int G_is_c_null_value(const CELL *cellVal)
Returns 1 if cell is NULL, 0 otherwise. This will test if the value cell is the largest int...
sprintf(buf2,"%s", G3D_CATS_ELEMENT)
void G_set_d_null_value(DCELL *dcellVals, int numVals)
int G_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 "quant"...
int G_quant_is_truncate(const struct Quant *quant)
char * G_find_file2_misc(const char *dir, const char *element, const char *name, const char *mapset)
int G_write_fp_range(const char *name, const struct FPRange *range)
Write the floating point range file f_range. This file is written in binary using XDR format...
FILE * G_fopen_old_misc(const char *dir, const char *element, const char *name, const char *mapset)
open a database file for reading
int G_update_range(CELL cat, struct Range *range)
update range structure
void * G_incr_void_ptr(const void *ptr, const size_t size)
Advance void pointer.
int G_row_update_fp_range(const void *rast, int n, struct FPRange *range, RASTER_MAP_TYPE data_type)
int G_update_fp_range(DCELL val, struct FPRange *range)
int G_read_range(const char *name, const char *mapset, struct Range *range)
read raster range
int G_open_old_misc(const char *dir, const char *element, const char *name, const char *mapset)
open a database file for reading
int G_get_range_min_max(const struct Range *range, CELL *min, CELL *max)
get range min and max
int G__row_update_range(const CELL *cell, int n, struct Range *range, int ignore_zeros)
int G_is_d_null_value(const DCELL *dcellVal)
Returns 1 if dcell is NULL, 0 otherwise. This will test if the value dcell is a NaN. Same test as in G_is_f_null_value().
int G_row_update_range(const CELL *cell, int n, struct Range *range)
update range structure
int G_quant_get_limits(const struct Quant *q, DCELL *dMin, DCELL *dMax, CELL *cMin, CELL *cMax)
Extracts the minimum and maximum floating-point and integer values from all the rules (except the "in...
size_t G_raster_size(RASTER_MAP_TYPE data_type)
Returns size of a raster CELL in bytes.
int G_quant_is_round(const struct Quant *quant)
int G_remove(const char *element, const char *name)
Remove a database file.
char buf[GNAME_MAX+sizeof(G3D_DIRECTORY)+2]
int G_init_range(struct Range *range)
initialize range structure
G_warning("category support for [%s] in mapset [%s] %s", name, mapset, type)
int G_construct_default_range(struct Range *range)
Sets the integer range r to [1,255].
int G_get_fp_range_min_max(const struct FPRange *range, DCELL *min, DCELL *max)
Extract the min/max from the range structure r. If the range structure has no defined min/max (first!...
int G_open_new(const char *element, const char *name)
Open a new database file.
#define XDR_DOUBLE_NBYTES
FILE * G_fopen_new_misc(const char *dir, const char *element, const char *name)
open a new database file
int G_read_fp_range(const char *name, const char *mapset, struct FPRange *drange)
Read the floating point range file f_range. This file is written in binary using XDR format...
void G_set_c_null_value(CELL *cellVals, int numVals)
int G_remove_misc(const char *dir, const char *element, const char *name)
Remove a database misc file.
int G__remove_fp_range(const char *name)
RASTER_MAP_TYPE G_raster_map_type(const char *name, const char *mapset)
Determine raster data type.
int G_write_range(const char *name, const struct Range *range)
write raster range file
int G_is_null_value(const void *rast, RASTER_MAP_TYPE data_type)
If the data_type is CELL_TYPE, calls G_is_c_null_value ((CELL *) rast); If the data_type is FCELL_TYP...