Contents
fcell
directory and an empty file created in the
cell
directory.
float
, unless the user sets the
Unix environment variable GRASS_FP_DOUBLE, which changes the default
to double
.
int
to float
or to double
will
be by C-language promotion.
double
to float
will be by C-language
demotion (with subsequent loss of precision)
float
or double
to int
will be by
a flexible on-the-fly quantization.
int
,
float
, double
) can be used to
write to the raster map, but if the type doesn't match the
resultant storage type
(which is determined when the map is opened),
the following rules apply:
int
to float
or to double
will be by
C-language promotion.
double
to
float
will be by by C-language
demotion (with subsequent loss of precision)
float
or double
to int
will be by
C-language truncation to integer.
floats
or 8-byte doubles
. The user should have some
control as to whether floating-point values are be written
as doubles
(greater precision at higher disk
use) or floats
(less precision as lower disk
use).
int
, float
, double
)
cat1:red:grn:blu cat2:red:grn:bluthe format is now
value1:red:grn:blu value2:red:grn:bluwhere
value1
and value2
are floating-point
numbers.
Also now color table file can contain entries of the form
*:red:grn:bludefault color (this sets the rgb for all values for which no explicit rgb values were defined in the color table)
nv:red:grn:blu(this sets color for drawing "no data" cells
cat1:descriptionthe format is the same for integer maps, but in addition the new format for floating point map is supported.
val1:val2:descriptionor
val1:descriptionwhere
value1
and value2
are floating-point
numbers.
cell_misc
directory:
cell_misc/<map>/f_format
type: float byte_order: xdr lzw_compression_bits: 9This file is read and written using the Key_Value functions in the
GISLIB
.
The byte_order and lzw_compression are write-only
and are for documentation (and future upgrades). The type
is one of float
or double
and
indicates the storage type for the floating-point values in the
map.
cell_misc/<map>/f_range
cell_misc/<map>/f_quant
value1:value2:cat1:cat2where value1 and value2 are a range of floating point values, with * indicating (positive or negative) infinity; cat1 and cat2 are a range of integer values, with cat2 optional. The rule is a linear interpolation from a floating-point value in the range [value1,value2] to an integer in the range [cat1,cat2].
cell_misc
directory as
cell_misc/<map>/null
.
This file will be a bitmap
with ones indicating that the corresponding cell contains valid data,
and zeros indicating that the corresponding cell contains a NULL
value.
typedef float FCELL typedef double DCELL typedef int RASTER_MAP_TYPE; #define CELL_TYPE 0 #define FCELL_TYPE 1 #define DCELL_TYPE 2Also gis.h will contain the definitions for new structures:
struct FPReclass; struct FPRange; struct Quant;Some of the old structures such as
struct Categories struct Cell_stats; struct Range; struct _Color_Rule_; struct _Color_Info_; struct Colors;were modified, so it is very important to use functional interface to access and set elements of these structures instead of accessing elements of the structures directly. Because some former elements such as for example (struct Range range.pmin ) do not exist anymore. I made sure non of the former elements have different meaning, so that the programs which do access the old elements directly either do not compile or work exactly the same way as prior to change.
G_set_null_value (void *rast, int count, RASTER_MAP_TYPE data_type)
If the data_type is FCELL_TYPE, calls G_set_f_null_value((FCELL *) rast, count);
If the data_type is DCELL_TYPE, calls G_set_d_null_value((DCELL *) rast, count);
G_set_c_null_value (CELL *cell, int count)
G_set_f_null_value (FCELL *fcell, int count)
float
NaN - 32 bits of 1's).
G_set_d_null_value (DCELL *dcell, int count)
double
NaN - 64 bits of 1's).
G_insert_null_values (rast, flags, count, data_type)
- void *rast;
- char *flags;
- int count;
- RASTER_MAP_TYPE data_type;
If the data_type is FCELL_TYPE, calls G_insert_f_null_values ((FCELL *) rast, flags, count);
If the data_type is DCELL_TYPE, calls G_insert_d_null_values ((DCELL *) rast, flags, count);
G_insert_c_null_values (cell, flags, count)
- CELL *cell;
- char *flags;
- int count;
G_insert_f_null_values (fcell, flags, count)
- FCELL *fcell;
- char *flags;
- int count;
G_insert_d_null_values (dcell, flags, count)
- DCELL *dcell;
- char *flags;
- int count;
G_is_null_value (void *rast, RASTER_MAP_TYPE data_type)
If the data_type is FCELL_TYPE, calls G_is_f_null_value (*(FCELL *) rast);
If the data_type is DCELL_TYPE, calls G_is_d_null_value ((DCELL *) rast);
G_is_c_null_value (CELL *cell)
int
.
G_is_f_null_value (FCELL *fcell)
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);
G_is_d_null_value (DCELL *dcell)
G_is_f_null_value()
.
char *G_allocate_null_buf()
G_get_null_value_row (int fd, char *flags, int row)
If map_type == FCELL_TYPE, calls
G_set_fp_type (FCELL_TYPE);
G_open_fp_map_new[_uncompressed](name);
If map_type == DCELL_TYPE, calls
G_set_fp_type (DCELL_TYPE);
G_open_fp_map_new[_uncompressed](name);
The use of this routine by applications is discouraged since its
use would override user preferences (what precision to use).
If data_type is FCELL_TYPE, returns
sizeof(FCELL)
If data_type is DCELL_TYPE, returns
sizeof(DCELL)
If data_type is FCELL_TYPE, calls
G_get_f_raster_row(fd, (FCELL *) rast, row);
If data_type is DCELL_TYPE, calls
G_get_d_raster_row(fd, (DCELL *) rast, row);
If data_type is FCELL_TYPE, calls
G_put_f_raster_row(fd, (FCELL *) rast);
If data_type is DCELL_TYPE, calls
G_put_d_raster_row(fd, (DCELL *) rast);
These routines are in the
If the map is floating-point, arrange for quantization to integer
for
If the programmer wants to read the floating point map using
uing quant rules other than the ones stored in map's quant file,
he should call G_set_quant_rules() after the call to G_open_cell_old().
NULL values are converted to zeros.
This routine is deprecated .
This routine is deprecated .
These routines are in the
These routines are in the
If the cell_type is FCELL_TYPE, calls
G_lookup_f_raster_colors(FCELL *)cell, r, g, b, set, n, colors);
If the cell_type is DCELL_TYPE, calls
G_lookup_d_raster_colors(DCELL *)cell, r, g, b, set, n, colors);
If map_type is FCELL_TYPE, calls
G_add_f_raster_color_rule ((FCELL *) v1, r1, g1, b1, (FCELL *) v2, r2, g2, b2, colors);
If map_type is DCELL_TYPE, calls
G_add_d_raster_color_rule ((DCELL *) v1, r1, g1, b1, (DCELL *) v2, r2, g2, b2, colors);
If either v1 or v2 is the NULL-value,
this call is converted into
If either v1 or v2 is the NULL-value,
this call is converted into
In particular
if this flag is set, the routine
These routines are in the
If map_type is FCELL_TYPE, calls
D_f_raster((FCELL *) rast, ncols, nrows, colors);
If map_type is DCELL_TYPE, calls
D_d_raster((DCELL *) rast, ncols, nrows, colors);
If the data_type is FCELL_TYPE, calls
D_f_color((FCELL *value, colors);
If the data_type is DCELL_TYPE, calls
D_d_color((DCELL *value, colors);
If the data_type is FCELL_TYPE, calls
D_lookup_f_raster_colors((FCELL *) rast, colornum, n, colors);
If the data_type is DCELL_TYPE, calls
D_lookup_d_raster_colors((DCELL *) rast, colornum, n, colors);
If map_type is FCELL_TYPE, calls
D_draw_f_cell (A_row, (FCELL *) xarray, colors);
If map_type is DCELL_TYPE, calls
D_draw_d_cell (A_row, (DCELL *) xarray, colors);
Modifications to the
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
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
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.
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@mapset
being read using quant rules stored in q from G_mapset().
Seee G_read_quant() for detailes.
Return codes:
-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.
Rules that are added later have higher precedence when
searching.
If any of of
dmin, dmax
cmin, or cmax
is the NULL-value,
this rule is not added and 0 is returned. Otherwise return 1.
if the fp_lookup is organized, destroy it.
This rule has lower precedence than rules added with
This rule has lower precedence than rules added with
The order of the rules returned by increasing n is the
order in which the rules are applied when quantizing a value - the
first rule applicable is used.
NOTE: see G_quant_organize_fp_lookup() for details on how
the values are looked up from fp_lookup table when it is active.
(Right now fp_lookup is automatically organized during the
first call to G_quant_get_cell_value()
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].
3.2. New Floating-point and type-independant functions
G_raster_map_is_fp(char *name, char *mapset)
G_raster_map_type(char *name, char *mapset)
CELL_TYPE
(int);
FCELL_TYPE
(float); or
DCELL_TYPE
(double)
G_open_raster_new[_uncompressed](char *name, RASTER_MAP_TYPE map_type)
G_set_fp_type (RASTER_MAP_TYPE type)
G_open_fp_map_new()
.
The type must be one of
FCELL_TYPE
(float) or DCELL_TYPE
(double).
The use of this routine by applications is discouraged since its
use would override user preferences.
G_open_fp_map_new (char *name)
.tmp
)
and returns
a file descriptor. The storage type (float
or
double
) is determined by the last call to
G_set_fp_type()
or the default (float
-
unless the Unix env variable GRASS_FP_DOUBLE is set).
void *G_allocate_raster_buf(RASTER_MAP_TYPE data_type)
CELL *G_allocate_c_raster_buf()
FCELL *G_allocate_f_raster_buf()
DCELL *G_allocate_d_raster_buf()
void *G_incr_void_ptr (void *ptr, int size)
int G_raster_size (RASTER_MAP_TYPE data_type)
int G_raster_cmp (void *p, *q, RASTER_MAP_TYPE data_type)
int G_raster_cpy (void *p, *q, RASTER_MAP_TYPE data_type)
G_set_raster_value_c (void *p, CELL val, RASTER_MAP_TYPE data_type)
G_set_raster_value_f (void *p, FCELL val, RASTER_MAP_TYPE data_type)
G_set_raster_value_d (void *p, DCELL val, RASTER_MAP_TYPE data_type)
CELL G_get_raster_value_c (void *p, RASTER_MAP_TYPE data_type)
FCELL G_get_raster_value_f (void *p, RASTER_MAP_TYPE data_type)
DCELL G_get_raster_value_d (void *p, RASTER_MAP_TYPE data_type)
G_get_raster_row (int fd, void *rast, int row, RASTER_MAP_TYPE data_type)
G_get_raster_row_nomask (fd, fcell, row, map_type)
G_get_f_raster_row()
except no masking occurs.
G_get_f_raster_row (int fd, FCELL fcell, int row)
float
array fcell performing
type conversions as necessary based on the actual storage
type of the map. Masking, resampling into the current
region. NULL-values are always embedded in fcell
(never converted to a value).
G_get_f_raster_row_nomask (fd, fcell, row)
G_get_f_raster_row()
except no masking occurs.
G_get_d_raster_row (int fd, DCELL dcell, int row)
G_get_f_raster_row()
except that the array dcell is double
.
G_get_d_raster_row_nomask (fd, dcell, row)
G_get_d_raster_row()
except no masking occurs.
G_get_c_raster_row (int fd, CELL buf, int row)
G_get_map_row()
which converts
NULL values to zero.)
NOTE: when the raster map is old and null file doesn't exist,
it is assumed that all 0-cells are no-data.
When map is floating point, uses quant rules set explicitly
by G_set_quant_rules or stored in map's quant file to convert
floats to integers.
G_get_c_raster_row_nomask (int fd, CELL buf, int row)
G_get_c_raster_row()
except no masking occurs.
G_put_raster_row (int fd, void *rast, RASTER_MAP_TYPE data_type)
G_put_f_raster_row (int fd, FCELL *fcell)
float
array fcell, performing
type conversion to the actual storage type of the
resultant map. Keep track of the range of floating-point
values. Also writes the NULL-value bitmap from the
NULL-values embedded in the fcell array.
G_put_d_raster_row (int fd, DCELL *dcell)
G_put_f_raster_row()
except that the array dcell is double
.
G_put_c_raster_row (int fd, CELL buf)
G_put_map_row()
which treats
zero values also as NULL.)
G_zero_raster_row (void *rast, RASTER_MAP_TYPE data_type)
3.3. Upgrades to Raster Functions
These routines will be modified (internally) to work with floating-point
and NULL-values.
GISLIB
.
G_close_cell()
.tmp
file
into the fcell
element, create an empty
file in the cell
directory; write the
floating-point range file; write a default quantization file
quantization
file is set here to round fp numbers (this is a default for
now).
create an empty category file, with max cat = max value (for
backwards compatibility).
Move the .tmp
NULL-value bitmap file
to the cell_misc
directory.
G_open_cell_old()
G_get_c_raster_row()
, et. al.,
by reading the quantization rules for the
map using G_read_quant()
.
G_get_map_row()
G_put_map_row()
D_LIB
.
Dcell()
G_get_d_map_row()
and plot using D_draw_d_cell()
.
If the map is an integer map, read the map using G_get_c_raster_row()
and plot using D_draw_cell()
.
3.4. Color Functions (new and upgraded)
3.4.0 Upgraded Colors structures
struct _Color_Rule_
{
struct
{
DCELL value;
unsigned char red,grn,blu;
} low, high;
struct _Color_Rule_ *next;
struct _Color_Rule_ *prev;
};
struct _Color_Info_
{
struct _Color_Rule_ *rules;
int n_rules;
struct
{
unsigned char *red;
unsigned char *grn;
unsigned char *blu;
unsigned char *set;
int nalloc;
int active;
} lookup;
struct
{
DCELL *vals;
/* pointers to color rules corresponding to the intervals btwn vals */
struct _Color_Rule_ **rules;
int nalloc;
int active;
} fp_lookup;
DCELL min, max;
};
struct Colors
{
int version; /* set by read_colors: -1=old,1=new */
DCELL shift;
int invert;
int is_float; /* defined on floating point raster data? */
int null_set; /* the colors for null are set? */
unsigned char null_red, null_grn, null_blu;
int undef_set; /* the colors for cells not in range are set? */
unsigned char undef_red, undef_grn, undef_blu;
struct _Color_Info_ fixed, modular;
DCELL cmin, cmax;
};
3.4.1 New functions to support colors for floating-point.
GISLIB
.
G_lookup_raster_colors (rast, r, g, b, set, n, colors, cell_type)
G_lookup_c_raster_colors (cell, r, g, b, set, n, colors)
G_lookup_f_raster_colors (fcell, r, g, b, set, n, colors)
G_lookup_d_raster_colors (dcell, r, g, b, set, n, colors)
G_add_raster_color_rule (v1, r1, g1, b1, v2, r2, g2, b2, colors, map_type)
G_add_c_raster_color_rule (v1, r1, g1, b1, v2, r2, g2, b2, colors)
G_add_f_raster_color_rule (v1, r1, g1, b1, v2, r2, g2, b2, colors)
G_set_null_value_color (r1, g1, b1, colors)
G_add_d_raster_color_rule (v1, r1, g1, b1, v2, r2, g2, b2, colors)
G_set_null_value_color (r1, g1, b1, colors)
G_get_raster_color (v, r, g, b, colors, data_type)
G_get_c_raster_color (v, r, g, b, colors)
G_get_f_raster_color (v, r, g, b, colors)
G_get_d_raster_color (v, r, g, b, colors)
G_set_raster_color (v, r, g, b, colors, data_type)
G_add_raster_color_rule (v, r, g, b, v, r, g, r, colors, data_type);
G_set_c_raster_color (v, r, g, b, colors)
G_set_f_raster_color (v, r, g, b, colors)
G_add_f_raster_color_rule (v, r, g, b, v, r, g, r, colors);
G_set_d_raster_color (v, r, g, b, colors)
G_add_d_raster_color_rule (v, r, g, b, v, r, g, r, colors);
G_mark_colors_as_fp (struct Colors *colors)
G_get_colors_min_max()
should return min=-255^3 and max=255^3.
DISPLAYLIB
.
D_raster_of_type (rast, ncols, nrows, colors, data_type)
D_f_raster (fcell, ncols, nrows, colors)
D_raster()
except that the
fcell array is type FCELL
. This implies
that the floating-point interfaces to the colors are
used by this routine.
D_d_raster (dcell, ncols, nrows, colors)
D_raster()
except that the
dcell array is type DCELL
. This implies
that the floating-point interfaces to the colors are
used by this routine.
D_color_of_type (value, colors, data_type)
D_f_color (value, colors)
D_color()
except that the
value is type FCELL
. This implies
that the floating-point interfaces to the colors are
used by this routine.
D_d_color (value, colors)
D_color()
except that the
value is type DCELL
. This implies
that the floating-point interfaces to the colors are
used by this routine.
D_lookup_raster_colors (rast, colornum, n, colors, data_type)
D_lookup_c_raster_colors (dcell, colornum, n, colors)
D_lookup_colors()
except that the
resultant color numbers are placed into a separate colornum
array (which the caller must allocate).
D_lookup_f_raster_colors (fcell, colornum, n, colors)
D_lookup_colors()
except that the
fcell array is type FCELL
and that the
resultant color numbers are placed into a separate colornum
array (which the caller must allocate).
D_lookup_d_raster_colors (dcell, colornum, n, colors)
D_lookup_colors()
except that the
dcell array is type DCELL
and that the
resultant color numbers are placed into a separate colornum
array (which the caller must allocate).
D_draw_cell_of_type(A_row, xarray, colors, map_type)
D_draw_f_cell (A_row, xarray, colors)
D_draw_cell()
except that the
xarray array is type FCELL
which implies
a call to D_f_raster()
instead of a call to
D_raster()
.
D_draw_d_cell (A_row, xarray, colors)
D_draw_cell()
except that the
xarray array is type DCELL
which implies
a call to D_d_raster()
instead of a call to
D_raster()
.
3.4.2. New functions to support a color for the NULL-value.
G_set_null_value_color (r, g, b, colors)
G_get_null_value_color (r, g, b, colors)
3.4.3. New functions to support a default color.
G_set_default_color (r, g, b, colors)
G_get_default_color (r, g, b, colors)
3.4.4. Upgraded color functions
G_read_colors()
G_mark_colors_as_fp()
.
G_write_colors()
G_get_colors_min_max()
G_lookup_colors()
G_get_color()
3.4.5. Changes to the
Colors
structure
Colors
structure to support colors for
floating-point data and the NULL-value consist of
3.4.6. Changes to the
colr
file
1.3:255:0:0 5:0:255:0
nv:red:grn:blu
*:red:grn:blu
3.5. Range functions (new and upgraded)
3.5.1. Modified range functions
G_read_range()
G_construct_default_range()
.
G_init_range()
G_update_range()
G_get_range_min_max()
G_write_range()
3.5.2. New range functions
G_construct_default_range (struct Range *r)
G_read_raster_range (void *r, char *name, char *mapset, RASTER_MAP_TYPE map_type)
G_read_fp_range (struct FPRange *r, char *name, char *mapset)
f_range
.
This file is written in binary using XDR format.
If there is no defined min/max in r, an
empty f_range
file is created.
G_construct_default_range()
.
G_init_raster_range (FPRange *r, RASTER_MAP_TYPE map_type)
G_init_fp_range (FPRange *r)
G_update_f_range (FPRange *r, FCELL *fcell, int n)
FCELL
values in fcell
NULL-values must be detected and ignored.
G_update_d_range (FPRange *r, DCELL *dcell, int n)
DCELL
values in dcell
NULL-values must be detected and ignored.
G_get_fp_range_min_max (FPRange *r, DCELL *min, DCELL *max)
G_write_fp_range (FPRange *r)
f_range
.
This file is written in binary using XDR format.
If there is no defined min/max in r, an
empty f_range
file is created.
3.6. New and Upgraded Cell_stats functions
Modified Cell_stats
functions to handle NULL-values:
G_init_cell_stats()
G_update_cell_stats()
G_next_cell_stat()
G_find_cell_stat()
G_get_stats_for_null_value(int *count, struct Cell_stats *s)
3.7. New Quantization Functions
New functions to support quantization of floating-point to integer.
These next two functions are convenience functions to allow applications
to easily create quantization rules other than the defaults.
G_write_quant (char *name, char *mapset, struct Quant *q)
f_quant
file for the raster map
name from q.
G_set_quant_rules (int fd, struct Quant *q)
G_read_quant (char *name, char *mapset, struct Quant *q)
G_quant_init (struct Quant *q)
G_quant_free (struct Quant *q)
G_quant_init()
.
G_quant_truncate (struct Quant *q)
G_quant_truncate (struct Quant *q)
G_quant_organize_fp_lookup (struct Quant *quant)
G_quant_add_rule (q, dmin, dmax, cmin, cmax)
G_quant_set_positive_infinite_rule (q, dmax, c)
G_quant_add_rule()
.
G_quant_get_positive_infinite_rule (q, dmax, c)
G_quant_set_negative_infinite_rule (q, dmin, c)
G_quant_add_rule()
.
G_quant_get_negative_infinite_rule (q, dmin, c)
G_quant_get_limits (q, dmin, dmax, cmin, cmax)
G_quant_nrules (struct Quant *q)
G_quant_get_rule (q, n, dmin, dmax, cmin, cmax)
CELL G_quant_get_cell_value (struct Quant *q, DCELL value)
G_quant_perform_d (q, dcell, cell, n)
DCELL
values in the dcell array
and puts the results into the cell array.
G_quant_perform_f (q, fcell, cell, n)
FCELL
values in the fcell array
and puts the results into the cell array.
G_quantize_fp_map (char *name, CELL cmin, CELL cmax)
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].
G_quantize_fp_map_range (name, dmin, dmax, cmin, cmax)
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].
We made sure that all old fields in Categories structure are either missing in new Categories structure or have exactly the same meaning. We did it so that the programs using Categories structure directly either do not compile with new gis library or work exactly the same as bnefore. A programmer might want to read the data in a floating point map in a way that each cell value stores index of it's category label and data range. The way to do it is to call G_set_quant_rules(fd, &pcats->q) after openning the map.
This is helpful when trying to collect statistics (how many cells of each category are in the map. (although there is another new mechanism to collect such stats - see G_mark_raster_cats()). Another reason to get a category index instead of fp values is that this index will be the FID into GRASS-DBMS link. Also he can use G_get_ith_raster_cat() to get the category information for each cell using this index.
Here is the new Categories structure defined in gis.h:
struct Categories { CELL ncats ; /* total number of categories */ CELL num ; /* the highest cell values. Only exists for backwards compatibility = (CELL) max_fp_values in quant rules */ char *title ; /* name of data layer */ char *fmt ; /* printf-like format to generate labels */ float m1 ; /* Multiplication coefficient 1 */ float a1 ; /* Addition coefficient 1 */ float m2 ; /* Multiplication coefficient 2 */ float a2 ; /* Addition coefficient 2 */ struct Quant q ; /* rules mapping cell values to index in list of labels */ char **labels ; /* array of labels of size num */ int * marks ; /* was the value with this label was used? */ int nalloc; int last_marked_rule ; } ;
cats file
cat:descriptionIn addition label entries of new format is supported for floating point maps.
val:descr (where val is a floating point number)or
val1:val2:descr (where val1, val2 is a floating point range)Internally the labels are stored for fp ranges of data. However when the cats file is written, all the decimal zeros are stripped so that integer values appear as integers in the file. Also if values are the same, only 1 value is written (i.e. first format).
This way even though the old cats files will be processed differently internally, the user or application programmer will not notice this difference as long as the proper api is used and the elements of Categories structure are not accessed directly without API calls.
G_read_raster_cats (char *name, *mapset, struct Categories *pcats)
G_copy_raster_cats (struct Categories *pcats_to, struct Categories *pcats_from)
returns: 0 if successful -1 on fail
char *G_get_raster_cat (val, pcats, data_type)
- void *val;
- struct Categories *pcats;
- RASTER_MAP_TYPE data_type;
char *G_get_c_raster_cat (val, pcats)
- CELL *val;
- struct Categories *pcats;
char *G_get_d_raster_cat (val, pcats)
- DCELL *val;
- struct Categories *pcats;
char *G_get_f_raster_cat (val, pcats)
- FCELL *val;
- struct Categories *pcats;
G_set_raster_cat (rast1, rast2, pcats, data_type)
- void *rast1, *rast2;
- struct Categories *pcats;
- RASTER_MAP_TYPE data_type;
G_set_c_raster_cat (rast1, rast2, pcats)
- CELL *rast1, *rast2;
- struct Categories *pcats;
G_set_f_raster_cat (rast1, rast2, pcats)
- FCELL *rast1, *rast2;
- struct Categories *pcats;
G_set_d_raster_cat (rast1, rast2, pcats)
- DCELL *rast1, *rast2;
- struct Categories *pcats;
int *G_number_of_raster_cats (pcats)
char *G_get_ith_raster_cat (pcats, i, rast1, rast2, data_type)
- void *rast1, *rast2; /* value range */
- struct Categories *pcats;
- int i;
- RASTER_MAP_TYPE data_type;
char *G_get_ith_c_raster_cat (pcats, i, rast1, rast2)
- CELL *rast1, *rast2; /* value range */
- struct Categories *pcats;
- int i;
char *G_get_ith_d_raster_cat (pcats, i, rast1, rast2)
- DCELL *rast1, *rast2; /* value range */
- struct Categories *pcats;
- int i;
char *G_get_ith_f_raster_cat (pcats, i, rast1, rast2)
- FCELL *rast1, *rast2; /* value range */
- struct Categories *pcats;
- int i;
char *G_get_raster_cats_title (struct Categories *pcats)
- Returns pointer to a string with title.
-
G_unmark_raster_cats (struct Categories *pcats)
- Sets marks for all categories to 0. This initializes Categories
structure for subsequest calls to G_mark_raster_cats (rast_row,...)
for each row of data,
where non-zero mark for i-th label means
that some of the cells in rast_row are labeled with i-th label
and fall into i-th data range.
These marks help determine from the Categories structure which labels
were used and which weren't.
-
G_get_next_marked_raster_cat(pcats, rast1, rast2, stats, data_type)
- void *rast1, *rast2; /* value range */
- struct Categories *pcats;
- long *stats;
- RASTER_MAP_TYPE data_type;
- Finds the next label and corresponding data range in the list of
marked categories. The category (label + data range) is marked by
G_mark_raster_cats (). End points of the data range are converted to
data_type and returned in rast1, rast2. the number of times
value from i-th cat. data range appeared so far is returned in stats.
See G_unmark_raster_cats(), G_rewind_raster_cats()
and G_mark_raster_cats ().
-
G_get_next_marked_c_raster_cat(pcats, rast1, rast2, stats)
- CELL *rast1, *rast2; /* value range */
- struct Categories *pcats;
- long *stats;
- Finds the next label and corresponding data range in the list of
marked categories. The category (label + data range) is marked by
G_mark_raster_cats (). End points of the data range are converted to
data_type and returned in rast1, rast2. the number of times
value from i-th cat. data range appeared so far is returned in stats.
See G_unmark_raster_cats(), G_rewind_raster_cats()
and G_mark_raster_cats ().
-
G_get_next_marked_f_raster_cat(pcats, rast1, rast2, stats)
- FCELL *rast1, *rast2; /* value range */
- struct Categories *pcats;
- long *stats;
- Finds the next label and corresponding data range in the list of
marked categories. The category (label + data range) is marked by
G_mark_raster_cats (). End points of the data range are converted to
data_type and returned in rast1, rast2. the number of times
value from i-th cat. data range appeared so far is returned in stats.
See G_unmark_raster_cats(), G_rewind_raster_cats()
and G_mark_raster_cats ().
-
G_get_next_marked_d_raster_cat(pcats, rast1, rast2, stats)
- DCELL *rast1, *rast2; /* value range */
- struct Categories *pcats;
- long *stats;
- Finds the next label and corresponding data range in the list of
marked categories. The category (label + data range) is marked by
G_mark_raster_cats (). End points of the data range are converted to
data_type and returned in rast1, rast2. the number of times
value from i-th cat. data range appeared so far is returned in stats.
See G_unmark_raster_cats(), G_rewind_raster_cats()
and G_mark_raster_cats ().
-
G_mark_raster_cats (rast_row, ncols, pcats, data_type)
- void *rast_row; /* row of rtaster cell values */
- struct Categories *pcats;
- int ncols;
- RASTER_MAP_TYPE data_type;
- Looks up the category label for each raster value in the
rast_row and updates the marks for labels found.
NOTE: non-zero mark for i-th label stores the number of
of raster cells read so far which are labeled with i-th label
and fall into i-th data range.
-
G_mark_c_raster_cats (rast_row, ncols, pcats)
- CELL *rast_row; /* row of rtaster cell values */
- struct Categories *pcats;
- int ncols;
- Looks up the category label for each raster value in the
rast_row and updates the marks for labels found.
NOTE: non-zero mark for i-th label stores the number of
of raster cells read so far which are labeled with i-th label
and fall into i-th data range.
-
G_mark_f_raster_cats (rast_row, ncols, pcats)
- FCELL *rast_row; /* row of rtaster cell values */
- struct Categories *pcats;
- int ncols;
- Looks up the category label for each raster value in the
rast_row and updates the marks for labels found.
NOTE: non-zero mark for i-th label stores the number of
of raster cells read so far which are labeled with i-th label
and fall into i-th data range.
-
G_mark_d_raster_cats (rast_row, ncols, pcats)
- DCELL *rast_row; /* row of rtaster cell values */
- struct Categories *pcats;
- int ncols;
- Looks up the category label for each raster value in the
rast_row and updates the marks for labels found.
NOTE: non-zero mark for i-th label stores the number of
of raster cells read so far which are labeled with i-th label
and fall into i-th data range.
-
G_rewind_raster_cats ( struct Categories *pcats)
- after calll to this function G_get_next_marked_raster_cat() returns
rhe first marked cat label.
-
G_init_raster_cats (char *title, struct Categories *pcats)
- Same as existing G_init_raster_cats()
only ncats argument is missign.
ncats has no meaning in new Categories structure
and only stores (int) largets
data value for backwards compatibility.
-
G_set_raster_cats_fmt (char *fmt, float m1, a1, m2, a2, struct Categories *pcats)
- Same as existing G_set_cats_fmt()
-
G_set_raster_cats_title (char *title, struct Categories *pcats)
- Same as existing G_set_cats_title()
-
G_write_raster_cats (char *name, struct Categories *pcats)
- Same as existing G_write_cats()
-
G_free_raster_cats (struct Categories *pcats)
- Same as existing G_free_cats()
G_get_map_row()
To be replaced by G_get_c_raster_row()
.
G_get_map_row_nomask()
To be replaced by G_get_c_raster_row_nomask()
.
G_put_map_row()
To be replaced by G_put_c_raster_row()
.
These functions are deprecated, since they can not be upgraded to support NULL-values, and should be eliminated from GRASS code.
G_open_map_new_random()
G_put_map_row_random()
Also,
no support for random writing of floating-point rasters will be provided.
NOTE: There will be programs for which there is no recommedation
given. This is because I didn't have time to examine these programs. The
lack of specific recommendations should not be taken to mean that
no upgrades are necessary, but that someone should examine the program
and make recommendations.
Exception: Programs that process raster colors
or the programs which report on raster categories labels
should either always read the maps as floating-point,
or read the maps
as integer if the map is integer and floating-point if the map is
floating-point.
Programs that use
For example if cells 3.4 12.9 and 30.78 of cover map coinside with
cells 100.4, 100.5 and of base map all falling into category range
"100.0 - 102.0 Fist category" in the bae map cats file.
Also suppose in cover map there are category ranges:
This is because r.stats is used to collect relative stats for
covar and base maps, and r.stats can only collect stats for cats
ranges, not for each cell value.
If in the same situation -c flag is used, then the resulting average
will be (.1 + .2 + .4)/3
NOTE:
it is an error for both
where type could be log, histoeq, mmse
(mimimum median squared error),
linear, etc.
new optionfor fp maps: nsteps
reports floating point ranges with non-zero statistics.
if nsteps option is used, it breaks the data range into
nsteps subranges and looks for values in these subranges.
(for example if data range is .5-4.5 and nsteps is 8, nv= "NULL", and there are
values in the ranges .5-1, 1-1.5, 1.5-2, and 4-4.5 and Null values,
it will report "NULL 0.5-2 4-4.5")
If the map is integer, r.describe reports integer ranges and null
value string if there are any null values in the map.
Lines 38-43 of
Exceptions
This is a non-backward-compatible change and should be
noted in the manual entry for r.mapcalc as well as in
any release notes.
This is a non-backward-compatible change and should be
noted in the manual entry for r.mapcalc as well as in
any release notes.
This is a non-backward-compatible change and should be
noted in the manual entry for r.mapcalc as well as in
any release notes.
Even though this is also true for the
Exceptions:
The (new) function
Examples:
Exception:
The command-line options here could be:
When the map is floating point,
Unless -1 option is used (in which case output is stream of actuall cell values)
r.stats reports stats for floating point subranges of the map.
if nsteps option is used, it breaks the data range into
nsteps subranges and collects stats for these subranges.
NOTE: when -1 option is used nsteps will be ignored, because the actuall floating
point values are the output.
When -C flag is used it will report stats for the fp ranges specified in
cats file. When both -C and -r are used, it will report stats for indexes
of fp. ranges in cats file. This is mostly used by r.report calling r.stats.
When -i flag is used, reads data as integer using quant rules.
This could be handled by writing a creating a new
program
??
If the map is floating-point
??
These changes are for the
In particular, the comment at line 23 should be changed from
Line 67 should be changed from
Warning!
This last item could result in too few pixels (zero for the means, zero or
one for the variances) which will invalidate the class. This
will not be so simple to remedy. I recommend that if the number of pixels
is get this small, that the program abort. This behavior should
be documented as a bug in the manual entry.
The comments for
In
The function of
The design is flexible. Ranges of values can be
set to NULL and/or the NULL value can be eliminated
and replace with a specified value.
Note that value is restricted to integer if the map is
an integer map.
This program would create a raster map with cells set to
values for input row/col pairs (based on the current region). This
program would be used by other programs that produce raster maps from
site data.
The input file format would be:
This program should be implemented using a paging scheme like
that used by
If the input is from stdin, it would be copied to a tempfile first
and then process from the tempfile. This is due to the above
sequential-write requirement. The input may have to be read more
than once.
If all the values
in the input are integers, the map should be
create as integer and the optional labels put into the
category file. Missing labels do not update the catgeory label.
This allows the input to have one label for the one occurrence of
a value without having to label every occurrence
If any of the values are non-integer, the map should be created as
floating-point and the optional labels ignored. No explicit
category file would created for the resultant floating-point map.
This routine produces the quantization file for a floating-point map
If rules is specified, the input has the form:
4. Upgrades to existing GRASS programs
Contents of this section
This section provides guidelines for upgrading GRASS programs
to process floating-point values and NULL-values. It also
provides specific recommendations for many of the GRASS programs
regarding user-interface and functional changes.
4.1. Guidelines for upgrading GRASS programs
double
(DCELL
) arrays
instead of float
(FCELL
) arrays.
4.2. Upgrades to raster programs
In general programs that use
G_get_map_row()
.
should use G_get_c_raster_row()
instead.
G_put_map_row()
.
should use G_put_c_raster_row()
instead.
r.allocate
r.average
*
which represents NULL).
1 - 10 .1
10 - 20 .2
20 - 30 .3
30 - 40 .4
<\pre>
then the resulting average will not be (3.4 + 12.9 + 30.78)/3
but (5 + 15 + 35)/3
r.basins.fill
r.binfer
r.buffer
read_input_map
should look for NULLs instead of zeros. Line 49 of read_map.c
should be changed from
if(*ptr++ = (*cell++ != 0))
to
if(*ptr++ = !G_is_c_null_value(cell++))
r.cats
G_get_raster_row()
.
And to lookup labels using G_get_raster_cat().
No other
changes are required to treat zero as a normal number and to ignore
NULLs. The code uses the Cell_stats
functions which
have been upgraded to suppress reporting NULLs.
New argument: vallist: a comma-separated list of values to show labels for.
If map is floating point, and vals areen't used, program exists with an error.
r.clump
clump.c
line 68-74 should be changed from
/* fake a previous row which is all zero */
G_zero (prev_in, len);
G_zero (prev_clump, len);
/* create a left edge of zero */
cur_in[0] = 0;
cur_clump[0] = 0;
to
/* fake a previous row which is all NULLs */
G_set_c_null_value (prev_in, ncols+1);
G_set_c_null_value (prev_clump, ncols+1);
/* create a left edge of NULLs */
G_set_c_null_value(cur_in,1);
G_set_c_null_value(cur_clump,1);
and lines 86-95 from
X = 0;
for (col = 1; col <= ncols; col++)
{
LEFT = X;
X = cur_in[col];
if (X == 0) /* don't clump zero data */
{
cur_clump[col] = 0;
continue;
}
to
G_set_null_value(&X,1);
for (col = 1; col <= ncols; col++)
{
LEFT = X;
X = cur_in[col];
if (G_is_c_null_value(&X)) /* don't clump NULL data */
{
cur_clump[col] = 0;
continue;
}
r.coin
r.colors
r.colors maps=name[,name...] [basemap=name] [range=min,max]
maps=
basemap=map
or
range=min,max
is specified.
basemap=name
range=min,max
basemap
and range
to be specified.
r.colors maps=name [quant=type]
r.colors.paint
r.combine
r.compress
G_set_fp_type()
should be called to preserve the storage type
of the map.
r.contour
r.cost
r.covar
-m
flag should be eliminated.
r.cross
r.describe
new option: nv (a string representing "no_data" )
r.digit
r.in.poly
.
r.distance
find_edge_cells()
should be modified
to look for NULLs instead of zeros.
edges.c
should be changed from
for (col = 0; col < (ncols+2); col++)
{
buf0[col] = 0;
buf1[col] = 0;
buf2[col] = 0;
}
to
G_set_c_null_value (buf0, ncols+2);
G_set_c_null_value (buf1, ncols+2);
G_set_c_null_value (buf2, ncols+2);
And lines 66 of edges.c
should be changed from
if (buf1[col] /* is a valid category */
to
if (!G_is_c_null_value(&buf1[col]) /* is a valid category */
r.drain
r.flow
r.gdbase
r.grow
This code needs attention. It seems to me that it is not
coded correctly.
main.c
:
if (*c2 > 0)
if (binmap) *c4++ = 1;
else *c4++ = *c2;
else *c4++ = 0;
This could be coded as:
if (!G_is_c_null_value(c2)))
if (binmap) *c4++ = 1;
else *c4++ = *c2;
else G_set_c_null_value(c4++ ,1);
or even better
if (binmap && !G_is_c_null_value(c2)))
*c4++ = 1;
else *c4++ = *c2;
if (*c2 == 0)
{
if ( *(c2+1) > 0 || *c3 > 0)
*c4 = 1; <--- this looks wrong
}
r.in.ascii
Can now produce floating point and integer maps with embedded null value cells.
There are new flags: -f,-d produce float/double, -i produce integer.
And new option: nv="string representing no-data cells in the input file"
if -f -d or -i are not used, r.in.ascii looks into the header of input file.
The header now can have entries:
multiplier, null, and type.
If type is not set in the header, the new map is created integer if all of
the values in the input file are integer, and float otherwise.
r.in.elas
r.in.ll
r.in.poly
r.in.sunrast
r.infer
r.info
r.kappa
removed -z and -m flags
r.line
r.los
r.mask
r.mapcalc
if()
function,
if()
is spelled out here for clarification:
if(x)
x
is NULL;
0 if x
is zero;
1 otherwise
if(x,a)
x
is NULL;
a
if x
is non-zero;
0 otherwise
if(x,a,b)
x
is NULL;
a
if x
is non-zero;
b
otherwise
if(x,n,z,p)
x
is NULL;
n
if x
is negative;
z
if x
is zero;
p
if x
is positive
isnull(x)
returns:
1 if x
is NULL; 0 otherwise.
The (new) function null()
(which has no arguments) returns an integer NULL.
log(-2)
pow(a,b)
where a
is negative and
b
is not an integer
sqrt(-n)
returns -sqrt(n)
r.mask.points
r.median
r.mfilter
r.mode
r.neighbors
now works with fp data
r.out.ascii
New options: nv (a string representing no-data cells) and dp (number
of decimal places when reporting floating point values).
New flag: -i (means read the map using map's quant rules and report integers.
r.out.elas
r.out.mpeg
r.out.tga
r.patch
works with floating point raster maps and null vallues
overwrites nulls in input maps with non-null data in other input maps
when the map is floating point, copies all the category and files to make
new category file, and takes the first color file to be the new color files.
(this is because it's very hard to combine all color rules in one file)
creating new one.
The output type of the map is the highest precision
of all input maps.
r.poly
r.profile
r.random
r.reclass
the rules n1 [thru n2] = null
* = n
* = null
* = *
where "*" means "every other value" and "=*" means "stays the same"
r.report
(In the case of a single map, -n
-N
-C
-i
nsteps=int
-n
or -N
give the
same result).
-m flag should be removed as in r.stats
r.resample
r.resample is now modified to do resampling on floating point maps as well.
It preserves all the null values and creates the category file which contains
only the labels for the values which appear in the new map.
r.resample.tps.float
Should handle cats file in the same manner as r.resample and work with floating
numbers and no-data
r.rescale
r.rescale.eq
r.slope.aspect
r.stats
-m
should be eliminated. The code that reads the
MASK should be removed.
-n
should be added to request that NULLs be reported.
NULLs should be represented by *. For example
r.stats -cn soils
*:200
1:3040
2:6000
7:3456
r.support
r.null
r.surf.contour
r.surf.idw
r.surf.idw2
r.surf.voronoi
r.thin
r.transect
r.volume
r.watershed
r.watershed4.0
r.weight
r.weight.new
r.what
r.what.new
4.2. Upgrades to vector programs
v.to.rast
v.digit
xdigit
4.3. Upgrades to sites programs
General Guidelines:
The conversion of sites to raster should be modified in all
sites programs as follows:
v.to.rast
employs.
r.in.rowcol
that implements the in-memory paging.
s.menu
G_get_c_raster_row()
and replace any special processing of zero by NULL.
s.gdbase
s.in.ascii
s.out.ascii
s.reclass
s.surf.2d.float
s.surf.2d.float.alt
s.surf.2df
s.surf.idw
s.surf.tps
s.to.rast
processes new site format and creates a raster map of the same type
as site data.
4.4. Upgrades to display programs
d.3d
can draw both interger and floating point raster maps.
Raster maps of any type can be used as base map and elevation map.
-z flag changed to -n flag.
Argument "draw zero elevation" changed to "draw null elevation".
d.colors
lets edit null color for integer maps.
Refuses to execute for fp maps
d.colortable
Shows null color box, otherwise
works the same way for integer maps, ignores lines and cols arguments
and draws color ramp for fp maps with first 5 pixels drawn in null
value color
d.display
d.his
d.histogram
-n flag to include nulls
-C report for cats ranges
nsteps (default 255)
-z flag removed.
d.histogram now displays bars for each category.
In case of floating point map for each category range the bar
is split itno 1-pixel think lines and each line is displayed
in color computed for corresponding value form category range.
The result is that the bar is not one color, but smooth color range
showing colors of values in category range.
d.legend
d.paint.labels
d.profile
d.rast
-o
overlay flag should suppress the plotting
of NULLs instead of zeros.
d.rast.arrow
d.rast.edit
allows editing all types of maps with considering null values
d.rast.num
d.rgb
d.what.rast
Now reports wether or not the cell is "no data".
Also for floating point maps reports the actuall value, the label
and the quantized value.
4.5. Upgrades to hardcopy output programs
p.map
setcolor
command to allow
setting the color for fp numbers and ranges,
also user can now say "setcolor null color" and "setcolor default color"
also for NULL as well as the default color.
ps.map
p.map
p.colors
4.5. Upgrades to g.* programs
g.copy
g.list
g.remove
g.rename
Element_List
file
in src/general/manage/lib
is changed to make the fcell
directory visible and part
of the cell type, as follows:
cell:rast:raster:raster files
cellhd:header
cats:category
colr:color
hist:history
cell_misc:misc
fcell:fcell
fcell:fprast:fp raster:floating-point raster files
cell:cell
cellhd:header
cats:category
colr:color
hist:history
cell_misc:misc
g.region
zoom=map
must read the null-value bitmap using
G_get_null_value_row()
and look for non-NULL instead of non-zero.
4.6. Upgrades to m.* programs
m.clump
m.dem.extract
changed to write out null values for no data instead of zeros
m.dmaUSGSread
m.dted.extract
m.lulc.USGS
m.lulc.read
4.7. Upgrades to imagery programs
General Guidelines:
i.cca
i.class
i.cluster
i.colors
i.composite
i.fft
i.gensig
cmd
version.
G_get_map_row()
with
get_train.c
remove any checking for category 0. (This code
uses Cell_stats
functions that process zeros as real data
and suppress NULLs.)
/* determine the non-zero categories in the map */
to
/* determine the categories in the map */
Line 39, which checks for zero,
if (cat != 0)
should be deleted. (The block which is part of the if
will become the block for the while
above it,
which is the right thing.
if (cat != 0 && count > 1)
to
if (count > 1)
lookup_class.c
line 17 should be changed from
if (c == 0)
to
if (G_is_c_null_value(&c))
means.c
and covariance.c
NULLs should
be excluded from the calculations. This will require some care.
If any of the pixels in the band files are NULL, then this reduces the
number of points when calculating the means and variances. Three things need to
be done.
i.gensigset
i.gensig
apply here since
i.gensigset
shares a lot of code with i.gensig
.
The principle difference is that all the data is read into
memory before processing.
read_data.c
test for NULLs
and do not count them or insert them into the Data
array.
The same Warning! applies as for i.gensig
.
i.grey.scale
i.his.rgb
i.ifft
i.in.erdas
i.kappa
i.maxlik
i.ortho.photo
i.pca
i.points
i.points3
I can't find it
i.vpoints
i.quantize
i.rectify
i.rectify2
i.rectify3
I can't find
i.rgb.his
i.smap
i.tape.mss
i.tape.other
i.tape.spot
i.tape.tm
i.tape.tm.fast
i.tape.tm3
I can't find
G_put_c_raster_row()
instead of
G_put_map_row()
since zeros are valid data.
i.zc
4.8. Upgrades to shell scripts
3d.view.sh
blend.sh
dcorrelate.sh
demo.scripts
demo.sh
hsv.rgb.sh
intens.sh
rgb.hsv.sh
shade.clr.sh
shade.rel.sh
4.9. New Programs
These are programs that have been identified as needed to support
the upgrade to floating-point raster maps as well is the introduction
of a NULL-value.
r.null -fin maps=name[,name...] [setnull=range,[range]] [null=value]
r.null
is to explicitly
create the NULL-value bitmap file. The intended usage is to
fix "old" maps that don't have a NULL-value bitmap file (i.e. to
indicate if zero is valid value or is to be converted to NULL).
-f
-i
setnull=range[,range...]
null
argument is requested.
null=value
setnull
argument.
r.in.rowcol map=name [input=name]
The input would be from stdin if not specified or specified
as column row value [label]
input=-
.
v.to.rast
to allow the row/col
lines to be unordered, yet write the resultant map using
sequential raster writes.
r.recode input=name output=name title=name [-a]
Creates a new map in which cell values are results of applying user specified
rules to the coresponding values in the input map. User is asked to enter
the rules interactively. If some values on the right-hand side of the rules
are floating point, the new map is double, otherwise it is integer.
r.quant map=name[,map...] [basemap=map] [-tr] [fprange=min,max] [range=min,max]
NOTE:
it is an error for both map=name
basemap=map
or
fprange=min,max
is specified.
basemap=map
fprange=min,max
-t flag
-r flag
range=min,max
quant rules
where value1:value2:cat1:[cat2]
value1
and value2
are floating point
values and cat1
cand cat2
are integers.
If cat2
is missing, it is taken to be equal to
cat1
. All values can be "*" which means infinity.
basemap
and fprange
to be specified.