GRASS GIS 7 Programmer's Manual  7.9.dev(2021)-e5379bbd7
quant_rw.c File Reference

Raster Library - Quantization rules (read/write). More...

#include <string.h>
#include <grass/gis.h>
#include <grass/raster.h>
#include <grass/glocale.h>
Include dependency graph for quant_rw.c:

Go to the source code of this file.

Functions

void Rast_truncate_fp_map (const char *name, const char *mapset)
 Writes the quant rules. More...
 
void Rast_round_fp_map (const char *name, const char *mapset)
 Writes the quant rules. More...
 
void Rast_quantize_fp_map (const char *name, const char *mapset, CELL min, CELL max)
 Write quant rules (f_quant) for floating-point raster map. More...
 
void Rast_quantize_fp_map_range (const char *name, const char *mapset, DCELL d_min, DCELL d_max, CELL min, CELL max)
 Write quant rules (f_quant) for floating-point raster map. More...
 
void Rast_write_quant (const char *name, const char *mapset, const struct Quant *quant)
 Writes the quant rule table for the raster map. More...
 
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. More...
 

Detailed Description

Raster Library - Quantization rules (read/write).

(C) 1999-2009 by the 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
USACERL and many others

Definition in file quant_rw.c.

Function Documentation

◆ Rast_quantize_fp_map()

void Rast_quantize_fp_map ( const char *  name,
const char *  mapset,
CELL  min,
CELL  max 
)

Write quant rules (f_quant) for floating-point raster map.

Writes the f_quant file for the raster map name with one rule. The rule is generated using the floating-point range in f_range producing the integer range [cmin,cmax].

Make a rule for map <name> that maps floating range (d_min, d_max) into integer range (min, max) This function is useful when the quant rule doesn't depend of the range of produced float data, for example the slope map whould want to have a quant rule: 0.0, 90.0 -> 0 , 90 no matter what the min and max slope of this map is.

Parameters
namemap name
mapsetmapset name
cminminimum value
cmaxmaximum value

Definition at line 81 of file quant_rw.c.

References _, G_fatal_error(), G_fully_qualified_name(), Rast_get_fp_range_min_max(), Rast_is_d_null_value, Rast_quantize_fp_map_range(), and Rast_read_fp_range().

◆ Rast_quantize_fp_map_range()

void Rast_quantize_fp_map_range ( const char *  name,
const char *  mapset,
DCELL  d_min,
DCELL  d_max,
CELL  min,
CELL  max 
)

Write quant rules (f_quant) for floating-point raster map.

Writes the f_quant file for the raster map name with one rule. The rule is generated using the floating-point range [dmin,dmax] and the integer range [min,max]. This routine differs from the one above in that the application controls the floating-point range. For example, r.slope.aspect will use this routine to quantize the slope map from [0.0, 90.0] to [0, 90] even if the range of slopes is not 0-90. The aspect map would be quantized from [0.0, 360.0] to [0, 360].

Make a rule for map <name> that maps floating range (d_min, d_max) into integer range (min, max) This function is useful when the quant rule doesn't depend of the range of produced float data, for example the slope map whould want to have a quant rule: 0.0, 90.0 -> 0 , 90 no matter what the min and max slope of this map is.

Parameters
namemap name
mapsetmapset name
d_minminimum fp value
d_maxmaximum fp value
minminimum value
maxmaximum value

Definition at line 124 of file quant_rw.c.

References Rast_quant_add_rule(), Rast_quant_init(), and Rast_write_quant().

Referenced by Rast_quantize_fp_map().

◆ Rast_read_quant()

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.

Parameters
name
mapset
q
Returns
-2 if raster map is of type integer
-1 if (!G_name_is_fully_qualified())
0 if quantization file does not exist, or the file is empty or has wrong format
1 if non-empty quantization file exists

Definition at line 186 of file quant_rw.c.

References Rast__quant_import(), and Rast_quant_init().

Referenced by Rast_read_range().

◆ Rast_round_fp_map()

void Rast_round_fp_map ( const char *  name,
const char *  mapset 
)

Writes the quant rules.

Writes the quant rules which indicate that all floating numbers should be rounded instead of applying any quant rules from floats to integers.

Parameters
namemap name
mapsetmapset name

Definition at line 51 of file quant_rw.c.

References Rast_quant_init(), Rast_quant_round(), and Rast_write_quant().

◆ Rast_truncate_fp_map()

void Rast_truncate_fp_map ( const char *  name,
const char *  mapset 
)

Writes the quant rules.

Writes the quant rules which indicate that all floating numbers should be truncated instead of applying any quant rules from floats to integers.

Parameters
namemap name
mapsetmapset name

Definition at line 31 of file quant_rw.c.

References Rast_quant_init(), Rast_quant_truncate(), and Rast_write_quant().

◆ Rast_write_quant()

void Rast_write_quant ( const char *  name,
const char *  mapset,
const struct Quant quant 
)

Writes the quant rule table for the raster map.

Writes the f_quant file for the raster map name from q. if mapset==G_mapset() i.e. the map is in current mapset, then the original quant file in cell_misc/map/f_quant is written. Otherwise q is written into quant2/mapset/name (much like colr2 element). This results in map being read using quant rules stored in q from G_mapset(). See Rast_read_quant() for detailes.

Parameters
namemap name
mapsetmapset name
quantpointer to Quant structure which hold quant rules info

Definition at line 150 of file quant_rw.c.

References _, CELL_TYPE, G_fatal_error(), G_warning(), Rast__quant_export(), Rast_map_type(), and Rast_quant_get_limits().

Referenced by Rast_quantize_fp_map_range(), Rast_round_fp_map(), and Rast_truncate_fp_map().