GRASS GIS 7 Programmer's Manual  7.5.svn(2017)-r71793
 All Data Structures Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
range.c File Reference

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

#include <unistd.h>
#include <rpc/types.h>
#include <grass/raster.h>
#include <grass/glocale.h>
#include "R.h"
Include dependency graph for 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...
 
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_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 range.c.

Macro Definition Documentation

#define DEFAULT_CELL_MAX   255

Definition at line 23 of file range.c.

Referenced by Rast_construct_default_range().

#define DEFAULT_CELL_MIN   1

Definition at line 22 of file range.c.

Referenced by Rast_construct_default_range().

Function Documentation

void Rast__remove_fp_range ( const char *  name)

Remove floating-point range.

Note: For internal use only.

Parameters
namemap name

Definition at line 32 of file range.c.

References G_remove_misc().

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 402 of file range.c.

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

Referenced by Rast_row_update_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 44 of file range.c.

References DEFAULT_CELL_MAX, DEFAULT_CELL_MIN, and Rast_update_range().

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 556 of file range.c.

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

Referenced by gsd_put_legend(), Rast3d_range_min_max(), Rast3d_read_colors(), Rast_quantize_fp_map(), Rast_read_colors(), and Rast_read_range().

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 509 of file range.c.

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

Referenced by Gs_numtype(), gsd_put_legend(), Rast_get_max_c_cat(), and Rast_read_colors().

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 537 of file range.c.

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

Referenced by Rast3d_range_init(), and Rast_read_fp_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 488 of file range.c.

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

Referenced by Rast_read_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 70 of file range.c.

References _, CELL_TYPE, close(), dcell1, dcell2, fd, 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, Rast_init(), Rast_init_fp_range(), Rast_map_type(), Rast_read_range(), Rast_update_fp_range(), xdr_buf, and XDR_DOUBLE_NBYTES.

Referenced by gsd_put_legend(), Rast_quantize_fp_map(), Rast_read_colors(), and 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 153 of file range.c.

References _, CELL_TYPE, count, fclose(), fd, G_find_file2_misc(), G_fopen_old_misc(), G_fully_qualified_name(), G_warning(), 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 Gs_numtype(), gsd_put_legend(), I_compute_scatts(), Rast_get_max_c_cat(), Rast_read_colors(), and Rast_read_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 436 of file range.c.

References CELL_TYPE, DCELL_TYPE, FCELL_TYPE, FPRange::first_time, G_incr_void_ptr(), FPRange::max, min, FPRange::min, Rast_cell_size(), and Rast_is_null_value().

Referenced by Rast3d_range_update_from_tile().

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 387 of file range.c.

References Rast__row_update_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 360 of file range.c.

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

Referenced by Rast_read_fp_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 332 of file range.c.

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

Referenced by Rast_construct_default_range(), and Rast_read_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 290 of file range.c.

References _, close(), fd, FPRange::first_time, G_fatal_error(), G_open_new_misc(), G_remove_misc(), G_xdr_put_double(), FPRange::max, FPRange::min, Rast_init(), xdr_buf, and XDR_DOUBLE_NBYTES.

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 258 of file range.c.

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