16 #include <grass/raster.h> 17 #include <grass/glocale.h> 21 #define DEFAULT_CELL_MIN 1 22 #define DEFAULT_CELL_MAX 255 24 static void init_rstats(
struct R_stats *);
103 G_warning(
_(
"Unable to read fp range file for <%s>"),
108 if (read(fd, xdr_buf,
sizeof(xdr_buf)) !=
sizeof(xdr_buf)) {
111 G_debug(1,
"Empty fp range file meaning Nulls for <%s>",
125 G_warning(
_(
"Missing fp range file for <%s> (run r.support -s)"),
176 G_warning(
_(
"Unable to read quant rules for raster map <%s>"),
190 x[0] = (
CELL) (dmin + .5);
192 x[0] = (
CELL) (dmin - .5);
194 x[1] = (
CELL) (dmax + .5);
196 x[1] = (
CELL) (dmax - .5);
213 G_warning(
_(
"Unable to read range file for <%s>"),
219 if (!fgets(buf,
sizeof buf, fd)) {
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]);
233 G_warning(
_(
"Unable to read range file for <%s>"),
238 for (n = 0; n <
count; n++) {
241 if (count < 4 || x[n])
248 G_warning(
_(
"Missing range file for <%s> (run r.support -s)"),
280 DCELL dcell1, dcell2;
292 G_debug(1,
"Stats file does not exist");
298 G_warning(
_(
"Unable to read stats file for <%s>"),
303 if (read(fd, xdr_buf,
sizeof(xdr_buf)) !=
sizeof(xdr_buf)) {
306 G_debug(1,
"Empty stats file meaning Nulls for <%s>",
314 rstats->
sum = dcell1;
315 rstats->
sumsq = dcell2;
319 if (read(fd, &nbytes, 1) != 1) {
322 G_debug(1,
"Unable to read byte count in stats file for <%s>",
331 if (nbytes < 1 || nbytes >
sizeof(grass_int64)) {
333 G_debug(1,
"Invalid byte count in stats file for <%s>",
337 if (read(fd, cc, nbytes) != nbytes) {
340 G_debug(1,
"Unable to read count in stats file for <%s>",
346 for (i = nbytes - 1; i >= 0; i--) {
347 count = (count << 8);
348 count = count + cc[i];
391 fprintf(fp,
"%ld %ld\n", (
long)range->
min, (
long)range->
max);
430 if (write(fd, xdr_buf,
sizeof(xdr_buf)) !=
sizeof(xdr_buf)) {
466 if (rstats->
count < 1) {
474 if (write(fd, xdr_buf,
sizeof(xdr_buf)) !=
sizeof(xdr_buf)) {
480 count = rstats->
count;
483 for (i = 0; i <
sizeof(grass_int64); i++) {
484 cc[i] = count & 0xff;
492 if (write(fd, &nbytes, 1) != 1) {
497 if (nbytes > 0 && write(fd, cc, nbytes) != nbytes) {
526 if (cat < range->
min)
528 if (cat > range->
max)
554 if (val < range->
min)
556 if (val > range->
max)
588 struct Range *range,
int ignore_zeros)
607 if (cat < range->
min)
609 if (cat > range->
max)
646 val = *((
DCELL *) rast);
664 if (val < range->
min)
666 if (val > range->
max)
695 init_rstats(&range->
rstats);
747 init_rstats(&range->
rstats);
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_fp_range(const char *name, const struct FPRange *range)
Write raster range file (floating-point)
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't touch) ...
void Rast_init(void)
Initialize GRASS GIS engine.
int Rast_read_rstats(const char *name, const char *mapset, struct R_stats *rstats)
Read raster stats.
int Rast_quant_is_truncate(const struct Quant *quant)
Returns whether or not quant rules are set to truncate map.
FILE * G_fopen_old_misc(const char *dir, const char *element, const char *name, const char *mapset)
open a database file for reading
int Rast_is_c_null_value(const CELL *cellVal)
To check if a CELL raster value is set to NULL.
int Rast_read_range(const char *name, const char *mapset, struct Range *range)
Read raster range (CELL)
void G_fatal_error(const char *msg,...)
Print a fatal error message to stderr.
int G_open_old_misc(const char *dir, const char *element, const char *name, const char *mapset)
open a database file for reading
size_t Rast_cell_size(RASTER_MAP_TYPE data_type)
Returns size of a raster cell in bytes.
void Rast_update_fp_range(DCELL val, struct FPRange *range)
Update range structure (floating-point)
RASTER_MAP_TYPE Rast_map_type(const char *name, const char *mapset)
Determine raster data type.
void Rast_set_c_null_value(CELL *cellVals, int numVals)
To set a number of CELL raster values to NULL.
void Rast_init_range(struct Range *range)
Initialize range structure.
void Rast_row_update_range(const CELL *cell, int n, struct Range *range)
Update range structure based on raster row (CELL)
void G_xdr_put_double(void *dst, const double *src)
int G_debug(int level, const char *msg,...)
Print debugging message.
void Rast_write_range(const char *name, const struct Range *range)
Write raster range file.
int G_open_new_misc(const char *dir, const char *element, const char *name)
open a new database file
int Rast_is_null_value(const void *rast, RASTER_MAP_TYPE data_type)
To check if a raster value is set to NULL.
#define XDR_DOUBLE_NBYTES
int Rast_quant_is_round(const struct Quant *quant)
Returns whether or not quant rules are set to round map.
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.
void Rast_set_d_null_value(DCELL *dcellVals, int numVals)
To set a number of DCELL raster values to NULL.
void Rast__row_update_range(const CELL *cell, int n, struct Range *range, int ignore_zeros)
Update range structure based on raster row.
void Rast_write_rstats(const char *name, const struct R_stats *rstats)
Write raster stats file.
void Rast__remove_fp_range(const char *name)
Remove floating-point range.
void * G_incr_void_ptr(const void *ptr, size_t size)
Advance void pointer.
FILE * G_fopen_new_misc(const char *dir, const char *element, const char *name)
open a new database file
char * G_fully_qualified_name(const char *name, const char *mapset)
Get fully qualified element name.
int Rast_read_fp_range(const char *name, const char *mapset, struct FPRange *drange)
Read floating-point range.
const char * G_mapset(void)
Get current mapset name.
int G_remove_misc(const char *dir, const char *element, const char *name)
Remove a database misc file.
void Rast_get_fp_range_min_max(const struct FPRange *range, DCELL *min, DCELL *max)
Get minimum and maximum value from fp range.
void G_xdr_get_double(double *dst, const void *src)
void G_warning(const char *msg,...)
Print a warning message to stderr.
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.
void Rast_init_fp_range(struct FPRange *range)
Initialize fp range.
void Rast_get_range_min_max(const struct Range *range, CELL *min, CELL *max)
Get range min and max.
int Rast_is_d_null_value(const DCELL *dcellVal)
To check if a DCELL raster value is set to NULL.
void Rast_update_range(CELL cat, struct Range *range)
Update range structure (CELL)
void Rast_construct_default_range(struct Range *range)
Construct default range.