GRASS GIS 8 Programmer's Manual  8.2.2dev(2023)-3d37ee165c
null_val.c File Reference

Raster Library - NULL value management. More...

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

Go to the source code of this file.

Functions

void Rast__set_null_value (void *rast, int numVals, int null_is_zero, RASTER_MAP_TYPE data_type)
 To set one or more raster values to null. More...
 
void Rast_set_null_value (void *buf, int numVals, RASTER_MAP_TYPE data_type)
 To set one or more raster values to null. More...
 
void Rast_set_c_null_value (CELL *cellVals, int numVals)
 To set a number of CELL raster values to NULL. More...
 
void Rast_set_f_null_value (FCELL *fcellVals, int numVals)
 To set a number of FCELL raster values to NULL. More...
 
void Rast_set_d_null_value (DCELL *dcellVals, int numVals)
 To set a number of DCELL raster values to NULL. More...
 
int Rast_is_null_value (const void *rast, RASTER_MAP_TYPE data_type)
 To check if a raster value is set to NULL. More...
 
void Rast_insert_null_values (void *rast, char *null_row, int ncols, RASTER_MAP_TYPE data_type)
 To check if a CELL raster value is set to NULL. More...
 
void Rast_insert_c_null_values (CELL *cellVal, char *null_row, int ncols)
 To insert null values into an integer raster map (CELL) More...
 
void Rast_insert_f_null_values (FCELL *fcellVal, char *null_row, int ncols)
 To insert null values into an floating-point raster map (FCELL) More...
 
void Rast_insert_d_null_values (DCELL *dcellVal, char *null_row, int ncols)
 To insert null values into an floating-point raster map (FCELL) More...
 
int Rast__check_null_bit (const unsigned char *flags, int bit_num, int n)
 Check NULL. More...
 
int G__set_flags_from_01_random (const char *zero_ones, unsigned char *flags, int col, int n, int ncols)
 Given array of 0/1 of length n starting from column. More...
 
void Rast__convert_01_flags (const char *zero_ones, unsigned char *flags, int n)
 ? More...
 
void Rast__convert_flags_01 (char *zero_ones, const unsigned char *flags, int n)
 ? More...
 
void Rast__init_null_bits (unsigned char *flags, int cols)
 ? More...
 

Detailed Description

Raster Library - NULL value management.

To provide functionality to handle NULL values for data types CELL, FCELL, and DCELL. May need more...

(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 unknown - probably CERL
Justin Hickey - Thailand - jhick.nosp@m.ey@h.nosp@m.pcc.n.nosp@m.ecte.nosp@m.c.or..nosp@m.th

Definition in file null_val.c.

Function Documentation

◆ G__set_flags_from_01_random()

int G__set_flags_from_01_random ( const char *  zero_ones,
unsigned char *  flags,
int  col,
int  n,
int  ncols 
)

Given array of 0/1 of length n starting from column.

Note: Only for internal use.

Given array of 0/1 of length n starting from column set the corresponding bits of flags; total number of bits in flags is ncols.

Parameters
zero_ones
flags
col
n
ncols
Returns
0
1

Definition at line 374 of file null_val.c.

References count, Rast__check_null_bit(), Rast__convert_01_flags(), and Rast__null_bitstream_size().

◆ Rast__check_null_bit()

int Rast__check_null_bit ( const unsigned char *  flags,
int  bit_num,
int  n 
)

Check NULL.

Note: Only for internal use.

Parameters
flagsnull bitmap
bit_numindex of bit to check
nsize of null bitmap (in bits)
Returns
1 if set, 0 if unset

Definition at line 338 of file null_val.c.

References G_fatal_error().

Referenced by G__set_flags_from_01_random().

◆ Rast__convert_01_flags()

void Rast__convert_01_flags ( const char *  zero_ones,
unsigned char *  flags,
int  n 
)

?

Note: Only for internal use.

Parameters
zero_ones
flags
n

Definition at line 423 of file null_val.c.

References count, and Rast__null_bitstream_size().

Referenced by G__set_flags_from_01_random().

◆ Rast__convert_flags_01()

void Rast__convert_flags_01 ( char *  zero_ones,
const unsigned char *  flags,
int  n 
)

?

Note: Only for internal use.

Parameters
zero_ones
flags
n

Definition at line 461 of file null_val.c.

References count, and Rast__null_bitstream_size().

◆ Rast__init_null_bits()

void Rast__init_null_bits ( unsigned char *  flags,
int  cols 
)

?

Note: Only for internal use.

Parameters
flags
cols

Definition at line 495 of file null_val.c.

References Rast__null_bitstream_size().

◆ Rast__set_null_value()

void Rast__set_null_value ( void *  rast,
int  numVals,
int  null_is_zero,
RASTER_MAP_TYPE  data_type 
)

To set one or more raster values to null.

It also sets null to zero if null_is_zero is TRUE.

Parameters
rastpointer to values to set to null
numValsnumber of values to set to null
null_is_zeroflag to indicate if NULL = 0
data_typetype of raster - CELL, FCELL, DCELL

Definition at line 80 of file null_val.c.

References G_zero(), Rast_cell_size(), and Rast_set_null_value().

◆ Rast_insert_c_null_values()

void Rast_insert_c_null_values ( CELL cellVal,
char *  null_row,
int  ncols 
)

To insert null values into an integer raster map (CELL)

For each of the count flags which is true(!=0), set the corresponding cell to the NULL value.

Parameters
rastpointer raster values
null_rownull row
ncolsnumber of columns

Definition at line 295 of file null_val.c.

◆ Rast_insert_d_null_values()

void Rast_insert_d_null_values ( DCELL dcellVal,
char *  null_row,
int  ncols 
)

To insert null values into an floating-point raster map (FCELL)

For each for the count flag which is true(!=0), set the corresponding dcell to the NULL value.

Parameters
dcellValpointer raster values
null_rownull row
ncolsnumber of columns

Definition at line 322 of file null_val.c.

◆ Rast_insert_f_null_values()

void Rast_insert_f_null_values ( FCELL fcellVal,
char *  null_row,
int  ncols 
)

To insert null values into an floating-point raster map (FCELL)

Parameters
fcellValpointer raster values
null_rownull row
ncolsnumber of columns

Definition at line 307 of file null_val.c.

◆ Rast_insert_null_values()

void Rast_insert_null_values ( void *  rast,
char *  null_row,
int  ncols,
RASTER_MAP_TYPE  data_type 
)

To check if a CELL raster value is set to NULL.

Returns 1 if cell is NULL, 0 otherwise. This will test if the value cell is the largest int.

Parameters
cellValCELL raster value to check
Returns
TRUE if CELL raster value is NULL
FALSE otherwise

To check if a FCELL raster value is set to NULL

Returns 1 if fcell is NULL, 0 otherwise. This will test if the value fcell is a NaN. It isn't good enough to test for a particular NaN bit pattern since the machine code may change this bit pattern to a different NaN. The test will be

if(fcell==0.0) return 0;
if(fcell>0.0) return 0;
if(fcell<0.0) return 0;
return 1;

or (as suggested by Mark Line)

return (fcell != fcell);
Parameters
fcellValFCELL raster value to check
Returns
TRUE if FCELL raster value is NULL
FALSE otherwise

To check if a DCELL raster value is set to NULL

Returns 1 if dcell is NULL, 0 otherwise. This will test if the value dcell is a NaN. Same test as in Rast_is_f_null_value().

Parameters
dcellValDCELL raster value to check
Returns
TRUE if DCELL raster value is NULL
FALSE otherwise

To insert null values into a map.

Parameters
rastpointer raster values
null_rownull row
ncolsnumber of columns
data_typetype of raster - CELL, FCELL, DCELL

Definition at line 279 of file null_val.c.

◆ Rast_is_null_value()

int Rast_is_null_value ( const void *  rast,
RASTER_MAP_TYPE  data_type 
)

To check if a raster value is set to NULL.

Parameters
rastraster value to check
data_typetype of raster - CELL, FCELL, DCELL
Returns
TRUE if raster value is NULL
FALSE otherwise

Definition at line 179 of file null_val.c.

References CELL_TYPE, DCELL_TYPE, FALSE, FCELL_TYPE, G_warning(), Rast_is_c_null_value, Rast_is_d_null_value, and Rast_is_f_null_value.

Referenced by Rast_get_f_value(), Rast_get_vrt_row(), Rast_map_to_img_str(), Rast_raster_cmp(), and Rast_row_update_fp_range().

◆ Rast_set_c_null_value()

void Rast_set_c_null_value ( CELL cellVals,
int  numVals 
)

To set a number of CELL raster values to NULL.

Parameters
cellValspointer to CELL values to set to null
numValsnumber of values to set to null

Definition at line 124 of file null_val.c.

Referenced by N_copy_array_2d(), Rast_fpreclass_perform_di(), Rast_fpreclass_perform_fi(), Rast_fpreclass_perform_ii(), Rast_get_range_min_max(), Rast_init_range(), Rast_quant_get_limits(), Rast_quant_perform_d(), Rast_quant_perform_f(), and Rast_set_null_value().

◆ Rast_set_d_null_value()

void Rast_set_d_null_value ( DCELL dcellVals,
int  numVals 
)

◆ Rast_set_f_null_value()

void Rast_set_f_null_value ( FCELL fcellVals,
int  numVals 
)

To set a number of FCELL raster values to NULL.

Parameters
fcellValspointer to FCELL values to set to null
numValsnumber of values to set to null

Definition at line 138 of file null_val.c.

Referenced by N_copy_array_2d(), Rast_fpreclass_perform_df(), Rast_fpreclass_perform_ff(), Rast_fpreclass_perform_if(), Rast_get_f_value(), and Rast_set_null_value().

◆ Rast_set_null_value()

void Rast_set_null_value ( void *  buf,
int  numVals,
RASTER_MAP_TYPE  data_type 
)

To set one or more raster values to null.

Parameters
bufpointer to values to set to null
numValsnumber of values to set to null
data_typetype of raster - CELL, FCELL, DCELL

Definition at line 98 of file null_val.c.

References _, CELL_TYPE, DCELL_TYPE, FCELL_TYPE, G_warning(), Rast_set_c_null_value(), Rast_set_d_null_value(), and Rast_set_f_null_value().

Referenced by Rast__set_null_value(), Rast_get_vrt_row(), and Rast_set_f_value().