GRASS GIS 8 Programmer's Manual  8.5.0dev(2024)-bea8435a9e
raster/range.c File Reference

Raster Library - Raster range file management. More...

#include <unistd.h>
#include <grass/raster.h>
#include <grass/glocale.h>
#include "R.h"
Include dependency graph for raster/range.c:

Go to the source code of this file.

Macros

#define DEFAULT_CELL_MIN   1
 
#define DEFAULT_CELL_MAX   255
 

Functions

void Rast__remove_fp_range (const char *name)
 Remove floating-point range. More...
 
void Rast_construct_default_range (struct Range *range)
 Construct default range. More...
 
int Rast_read_fp_range (const char *name, const char *mapset, struct FPRange *drange)
 Read floating-point range. More...
 
int Rast_read_range (const char *name, const char *mapset, struct Range *range)
 Read raster range (CELL) More...
 
int Rast_read_rstats (const char *name, const char *mapset, struct R_stats *rstats)
 Read raster stats. More...
 
void Rast_write_range (const char *name, const struct Range *range)
 Write raster range file. More...
 
void Rast_write_fp_range (const char *name, const struct FPRange *range)
 Write raster range file (floating-point) More...
 
void Rast_write_rstats (const char *name, const struct R_stats *rstats)
 Write raster stats file. More...
 
void Rast_update_range (CELL cat, struct Range *range)
 Update range structure (CELL) More...
 
void Rast_update_fp_range (DCELL val, struct FPRange *range)
 Update range structure (floating-point) More...
 
void Rast_row_update_range (const CELL *cell, int n, struct Range *range)
 Update range structure based on raster row (CELL) More...
 
void Rast__row_update_range (const CELL *cell, int n, struct Range *range, int ignore_zeros)
 Update range structure based on raster row. More...
 
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) More...
 
void Rast_init_range (struct Range *range)
 Initialize range structure. More...
 
void Rast_get_range_min_max (const struct Range *range, CELL *min, CELL *max)
 Get range min and max. More...
 
void Rast_init_fp_range (struct FPRange *range)
 Initialize fp range. More...
 
void Rast_get_fp_range_min_max (const struct FPRange *range, DCELL *min, DCELL *max)
 Get minimum and maximum value from fp range. More...
 

Detailed Description

Raster Library - Raster range file management.

(C) 2001-2009 GRASS Development Team

This program is free software under the GNU General Public License (>=v2). Read the file COPYING that comes with GRASS for details.

Author
Original author CERL

Definition in file raster/range.c.

Macro Definition Documentation

◆ DEFAULT_CELL_MAX

#define DEFAULT_CELL_MAX   255

Definition at line 22 of file raster/range.c.

◆ DEFAULT_CELL_MIN

#define DEFAULT_CELL_MIN   1

Definition at line 21 of file raster/range.c.

Function Documentation

◆ Rast__remove_fp_range()

void Rast__remove_fp_range ( const char *  name)

Remove floating-point range.

Note: For internal use only.

Parameters
namemap name

Definition at line 33 of file raster/range.c.

References G_remove_misc(), and name.

◆ Rast__row_update_range()

void Rast__row_update_range ( const CELL cell,
int  n,
struct Range range,
int  ignore_zeros 
)

Update range structure based on raster row.

Note: for internal use only.

Parameters
cellraster values
nnumber of values
rangepointer to Range structure which holds range info
ignore_zerosignore zeros

Definition at line 590 of file raster/range.c.

References R_stats::count, Range::first_time, Range::max, Range::min, min, Rast_is_c_null_value, Range::rstats, R_stats::sum, and R_stats::sumsq.

Referenced by Rast_row_update_range().

◆ Rast_construct_default_range()

void Rast_construct_default_range ( struct Range range)

Construct default range.

Sets the integer range to [1,255]

Parameters
[out]rpointer to Range structure which holds range info

Definition at line 45 of file raster/range.c.

References DEFAULT_CELL_MAX, DEFAULT_CELL_MIN, and Rast_update_range().

◆ Rast_get_fp_range_min_max()

void Rast_get_fp_range_min_max ( const struct FPRange range,
DCELL min,
DCELL max 
)

Get minimum and maximum value from fp range.

Extract the min/max from the range structure range. If the range structure has no defined min/max (first!=0) there will not be a valid range. In this case the min and max returned must be the NULL-value.

Parameters
rangepointer to FPRange which holds fp range info
[out]minminimum value
[out]maxmaximum value

Definition at line 768 of file raster/range.c.

References FPRange::first_time, FPRange::max, max, FPRange::min, min, Rast_is_d_null_value, and Rast_set_d_null_value().

Referenced by Rast3d_range_min_max(), Rast_quantize_fp_map(), and Rast_read_range().

◆ Rast_get_range_min_max()

void Rast_get_range_min_max ( const struct Range range,
CELL min,
CELL max 
)

Get range min and max.

The minimum and maximum CELL values are extracted from the range structure.

If the range structure has no defined min/max (first!=0) there will not be a valid range. In this case the min and max returned must be the NULL-value.

Parameters
rangepointer to Range structure which holds range info
[out]minminimum value
[out]maxmaximum value

Definition at line 718 of file raster/range.c.

References Range::first_time, Range::max, max, Range::min, min, Rast_is_c_null_value, and Rast_set_c_null_value().

Referenced by Rast_get_max_c_cat().

◆ Rast_init_fp_range()

void Rast_init_fp_range ( struct FPRange range)

Initialize fp range.

Must set a flag in the range structure that indicates that no min/max have been defined - probably a "first" boolean flag.

Parameters
rangepointer to FPRange which holds fp range info

Definition at line 746 of file raster/range.c.

References FPRange::max, FPRange::min, and Rast_set_d_null_value().

Referenced by Rast3d_range_init(), Rast3d_read_range(), and Rast_read_fp_range().

◆ Rast_init_range()

void Rast_init_range ( struct Range range)

Initialize range structure.

Initializes the range structure for updates by Rast_update_range() and Rast_row_update_range().

Must set a flag in the range structure that indicates that no min/max have been defined - probably a "first" boolean flag.

Parameters
rangepointer to Range structure which holds range info

Definition at line 694 of file raster/range.c.

References Range::max, Range::min, and Rast_set_c_null_value().

Referenced by Rast_read_range().

◆ Rast_read_fp_range()

int Rast_read_fp_range ( const char *  name,
const char *  mapset,
struct FPRange drange 
)

Read floating-point range.

Read the floating point range file drange. This file is written in binary using XDR format.

An empty range file indicates that the min, max are undefined. This is a valid case, and the result should be an initialized range struct with no defined min/max. If the range file is missing and the map is a floating-point map, this function will create a default range by calling G_construct_default_range().

Parameters
namemap name
mapsetmapset name
drangepointer to FPRange structure which holds fp range
Returns
1 on success
2 range is empty
-1 on error

Definition at line 71 of file raster/range.c.

References _, CELL_TYPE, Range::first_time, G_debug(), G_find_file2_misc(), G_fully_qualified_name(), G_open_old_misc(), G_warning(), G_xdr_get_double(), Range::max, Range::min, name, Rast_init(), Rast_init_fp_range(), Rast_map_type(), Rast_read_range(), Rast_update_fp_range(), and XDR_DOUBLE_NBYTES.

Referenced by Rast_quantize_fp_map(), and Rast_read_range().

◆ Rast_read_range()

int Rast_read_range ( const char *  name,
const char *  mapset,
struct Range range 
)

Read raster range (CELL)

This routine reads the range information for the raster map name in mapset into the range structure.

A diagnostic message is printed and -1 is returned if there is an error reading the range file. Otherwise, 0 is returned.

Old range file (those with 4 numbers) should treat zeros in this file as NULL-values. New range files (those with just 2 numbers) should treat these numbers as real data (zeros are real data in this case). An empty range file indicates that the min, max are undefined. This is a valid case, and the result should be an initialized range struct with no defined min/max. If the range file is missing and the map is a floating-point map, this function will create a default range by calling G_construct_default_range().

Parameters
namemap name
mapsetmapset name
[out]rangepointer to Range structure which holds range info
Returns
-1 on error
1 on success
2 if range is empty
3 if raster map is floating-point, get range from quant rules

Definition at line 160 of file raster/range.c.

References _, CELL_TYPE, count, G_find_file2_misc(), G_fopen_old_misc(), G_fully_qualified_name(), G_warning(), name, NULL, Rast_get_fp_range_min_max(), Rast_init_range(), Rast_map_type(), Rast_quant_get_limits(), Rast_quant_is_round(), Rast_quant_is_truncate(), Rast_read_fp_range(), Rast_read_quant(), Rast_update_range(), and x.

Referenced by Rast_get_max_c_cat(), and Rast_read_fp_range().

◆ Rast_read_rstats()

int Rast_read_rstats ( const char *  name,
const char *  mapset,
struct R_stats rstats 
)

Read raster stats.

Read the stats file stats. This file is written in binary using XDR format.

An empty stats file indicates that all cells are NULL. This is a valid case, and the result should be an initialized rstats struct with no defined stats. If the stats file is missing this function will create a default stats with count = 0.

Parameters
namemap name
mapsetmapset name
rstatspointer to R_stats structure which holds raster stats
Returns
1 on success
2 stats is empty
-1 on error or stats file does not exist

Definition at line 276 of file raster/range.c.

References count, Rast_init(), and XDR_DOUBLE_NBYTES.

◆ Rast_row_update_fp_range()

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)

This routine updates the range data just like Rast_update_range(), but for n values from the cell array.

Parameters
cellraster values
nnumber of values
rangepointer to Range structure which holds range info
data_typeraster type (CELL, FCELL, DCELL)

Definition at line 635 of file raster/range.c.

References CELL_TYPE, R_stats::count, DCELL_TYPE, FCELL_TYPE, FPRange::first_time, G_incr_void_ptr, FPRange::max, FPRange::min, min, Rast_cell_size(), Rast_is_null_value(), FPRange::rstats, R_stats::sum, and R_stats::sumsq.

◆ Rast_row_update_range()

void Rast_row_update_range ( const CELL cell,
int  n,
struct Range range 
)

Update range structure based on raster row (CELL)

This routine updates the range data just like Rast_update_range(), but for n values from the cell array.

Parameters
cellraster values
nnumber of values
rangepointer to Range structure which holds range info

Definition at line 575 of file raster/range.c.

References Rast__row_update_range().

◆ Rast_update_fp_range()

void Rast_update_fp_range ( DCELL  val,
struct FPRange range 
)

Update range structure (floating-point)

Compares the cat value with the minimum and maximum values in the range structure, modifying the range if cat extends the range.

NULL-values must be detected and ignored.

Parameters
valraster value
rangepointer to Range structure which holds range info

Definition at line 548 of file raster/range.c.

References FPRange::first_time, FPRange::max, FPRange::min, min, and Rast_is_d_null_value.

Referenced by Rast3d_read_range(), and Rast_read_fp_range().

◆ Rast_update_range()

void Rast_update_range ( CELL  cat,
struct Range range 
)

Update range structure (CELL)

Compares the cat value with the minimum and maximum values in the range structure, modifying the range if cat extends the range.

NULL-values must be detected and ignored.

Parameters
catraster value
rangepointer to Range structure which holds range info

Definition at line 520 of file raster/range.c.

References Range::first_time, Range::max, Range::min, min, and Rast_is_c_null_value.

Referenced by Rast_construct_default_range(), and Rast_read_range().

◆ Rast_write_fp_range()

void Rast_write_fp_range ( const char *  name,
const struct FPRange range 
)

Write raster range file (floating-point)

Write the floating point range file f_range. This file is written in binary using XDR format. If there is no defined min/max in range, an empty f_range file is created.

Parameters
namemap name
rangepointer to FPRange which holds fp range info

Definition at line 409 of file raster/range.c.

References _, FPRange::first_time, G_fatal_error(), G_open_new_misc(), G_remove_misc(), G_xdr_put_double(), FPRange::max, FPRange::min, name, Rast_init(), Rast_write_rstats(), FPRange::rstats, and XDR_DOUBLE_NBYTES.

◆ Rast_write_range()

void Rast_write_range ( const char *  name,
const struct Range range 
)

Write raster range file.

This routine writes the range information for the raster map name in the current mapset from the range structure. A diagnostic message is printed and -1 is returned if there is an error writing the range file. Otherwise, 0 is returned.

This routine only writes 2 numbers (min,max) to the range file, instead of the 4 (pmin,pmax,nmin,nmax) previously written. If there is no defined min,max, an empty file is written.

Parameters
namemap name
rangepointer to Range structure which holds range info

Definition at line 373 of file raster/range.c.

References _, CELL_TYPE, Range::first_time, G_fatal_error(), G_fopen_new_misc(), G_mapset(), G_remove_misc(), Range::max, Range::min, name, Rast_map_type(), Rast_write_rstats(), and Range::rstats.

◆ Rast_write_rstats()

void Rast_write_rstats ( const char *  name,
const struct R_stats rstats 
)

Write raster stats file.

Write the stats file stats. This file is written in binary using XDR format. If the count is < 1 in rstats, an empty stats file is created.

Parameters
namemap name
rstatspointer to R_stats which holds stats info

Definition at line 451 of file raster/range.c.

References _, R_stats::count, count, G_fatal_error(), G_open_new_misc(), G_remove_misc(), G_xdr_put_double(), name, Rast_init(), FPRange::rstats, R_stats::sum, R_stats::sumsq, and XDR_DOUBLE_NBYTES.

Referenced by Rast_write_fp_range(), and Rast_write_range().