GRASS Programmer's Manual  6.5.svn(2014)-r66266
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Pages
gis/cats.c File Reference
#include <stdlib.h>
#include <string.h>
#include <grass/gis.h>
#include <grass/glocale.h>
Include dependency graph for gis/cats.c:

Go to the source code of this file.

Functions

int G_read_cats (const char *name, const char *mapset, struct Categories *pcats)
 read raster category file More...
 
int G_read_raster_cats (const char *name, const char *mapset, struct Categories *pcats)
 Is the same as existing G_read_cats() More...
 
int G_read_vector_cats (const char *name, const char *mapset, struct Categories *pcats)
 read vector category file More...
 
CELL G_number_of_cats (const char *name, const char *mapset)
 
CELL G__read_cats (const char *element, const char *name, const char *mapset, struct Categories *pcats, int full)
 
char * G_get_cats_title (const struct Categories *pcats)
 get title from category structure struct More...
 
char * G_get_raster_cats_title (const struct Categories *pcats)
 get raster cats title More...
 
char * G_get_cat (CELL num, struct Categories *pcats)
 get a category label More...
 
char * G_get_c_raster_cat (CELL *rast, struct Categories *pcats)
 given a CELL value val Returns pointer to a string describing category. More...
 
char * G_get_f_raster_cat (FCELL *rast, struct Categories *pcats)
 given a FCELL value val Returns pointer to a string describing category. More...
 
char * G_get_d_raster_cat (DCELL *rast, struct Categories *pcats)
 given a DCELL value val Returns pointer to a string describing category. More...
 
char * G_get_raster_cat (void *rast, struct Categories *pcats, RASTER_MAP_TYPE data_type)
 given a raster value val of type data_type Returns pointer to a string describing category. More...
 
int 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. More...
 
int G_mark_c_raster_cats (CELL *rast_row, int ncols, struct Categories *pcats)
 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. More...
 
int G_mark_f_raster_cats (FCELL *rast_row, int ncols, struct Categories *pcats)
 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. More...
 
int G_mark_d_raster_cats (DCELL *rast_row, int ncols, struct Categories *pcats)
 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. More...
 
int G_mark_raster_cats (void *rast_row, int ncols, struct Categories *pcats, RASTER_MAP_TYPE data_type)
 Looks up the category label for each raster value in the rast_row (row of raster cell value) 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. More...
 
int G_rewind_raster_cats (struct Categories *pcats)
 after call to this function G_get_next_marked_raster_cat() returns the first marked cat label. More...
 
char * G_get_next_marked_d_raster_cat (struct Categories *pcats, DCELL *rast1, DCELL *rast2, long *count)
 
char * G_get_next_marked_c_raster_cat (struct Categories *pcats, CELL *rast1, CELL *rast2, long *count)
 
char * G_get_next_marked_f_raster_cat (struct Categories *pcats, FCELL *rast1, FCELL *rast2, long *count)
 
char * G_get_next_marked_raster_cat (struct Categories *pcats, void *rast1, void *rast2, long *count, RASTER_MAP_TYPE data_type)
 
int G_set_cat (CELL num, char *label, struct Categories *pcats)
 set a category label More...
 
int G_set_c_raster_cat (CELL *rast1, CELL *rast2, char *label, struct Categories *pcats)
 Adds the label for range rast1 through rast2 in category structure pcats. More...
 
int G_set_f_raster_cat (FCELL *rast1, FCELL *rast2, char *label, struct Categories *pcats)
 Adds the label for range rast1 through rast2 in category structure pcats. More...
 
int G_set_d_raster_cat (DCELL *rast1, DCELL *rast2, char *label, struct Categories *pcats)
 Adds the label for range rast1 through rast2 in category structure pcats. More...
 
int G_set_raster_cat (void *rast1, void *rast2, char *label, struct Categories *pcats, RASTER_MAP_TYPE data_type)
 Adds the label for range rast1 through rast2 in category structure pcats. More...
 
int G_write_cats (char *name, struct Categories *cats)
 write raster category file More...
 
int G_write_raster_cats (char *name, struct Categories *cats)
 Same as existing G_write_cats() More...
 
int G_write_vector_cats (char *name, struct Categories *cats)
 write vector category file More...
 
int G__write_cats (char *element, char *name, struct Categories *cats)
 
char * G_get_ith_d_raster_cat (const struct Categories *pcats, int i, DCELL *rast1, DCELL *rast2)
 Returns i-th description and i-th data range from the list of category descriptions with corresponding data ranges. end points of data interval in rast1 and rast2. More...
 
char * G_get_ith_f_raster_cat (const struct Categories *pcats, int i, void *rast1, void *rast2)
 Returns i-th description and i-th data range from the list of category descriptions with corresponding data ranges. end points of data interval in rast1 and rast2. More...
 
char * G_get_ith_c_raster_cat (const struct Categories *pcats, int i, void *rast1, void *rast2)
 Returns i-th description and i-th data range from the list of category descriptions with corresponding data ranges. end points of data interval in rast1 and rast2. More...
 
char * G_get_ith_raster_cat (const struct Categories *pcats, int i, void *rast1, void *rast2, RASTER_MAP_TYPE data_type)
 Returns i-th description and i-th data range from the list of category descriptions with corresponding data ranges. Stores end points of data interval in rast1 and rast2 (after converting them to data_type. More...
 
int G_init_cats (CELL num, const char *title, struct Categories *pcats)
 initialize category structure More...
 
int G_init_raster_cats (const 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. More...
 
int G_set_cats_title (const char *title, struct Categories *pcats)
 set title in category structure More...
 
int G_set_raster_cats_title (const char *title, struct Categories *pcats)
 Same as existing G_set_cats_title() More...
 
int G_set_cats_fmt (const char *fmt, double m1, double a1, double m2, double a2, struct Categories *pcats)
 
int G_set_raster_cats_fmt (const char *fmt, double m1, double a1, double m2, double a2, struct Categories *pcats)
 Same as existing G_set_cats_fmt() More...
 
int G_free_cats (struct Categories *pcats)
 free category structure memory More...
 
int G_free_raster_cats (struct Categories *pcats)
 Same as existing G_free_cats() More...
 
int G_copy_raster_cats (struct Categories *pcats_to, const struct Categories *pcats_from)
 Allocates NEW space for quant rules and labels n pcats_to and copies all info from pcats_from cats to pcats_to cats. returns: 0 if successful -1 on fail. More...
 
int G_number_of_raster_cats (struct Categories *pcats)
 
int G_sort_cats (struct Categories *pcats)
 

Function Documentation

CELL G__read_cats ( const char *  element,
const char *  name,
const char *  mapset,
struct Categories *  pcats,
int  full 
)
int G__write_cats ( char *  element,
char *  name,
struct Categories *  cats 
)
int G_copy_raster_cats ( struct Categories *  pcats_to,
const struct Categories *  pcats_from 
)

Allocates NEW space for quant rules and labels n pcats_to and copies all info from pcats_from cats to pcats_to cats. returns: 0 if successful -1 on fail.

Parameters
pcats_to
pcats_from
Returns
int

Definition at line 1598 of file gis/cats.c.

References G_get_ith_d_raster_cat(), G_init_raster_cats(), and G_set_d_raster_cat().

Referenced by E_edit_fp_cats(), and G_sort_cats().

int G_free_cats ( struct Categories *  pcats)

free category structure memory

Frees memory allocated byG_read_cats, G_init_cats andG_set_cat.

Parameters
cats
Returns
int

Definition at line 1540 of file gis/cats.c.

References G_free_raster_cats().

Referenced by Gs_get_cat_label(), and gsd_put_legend().

int G_free_raster_cats ( struct Categories *  pcats)

Same as existing G_free_cats()

Parameters
pcats
Returns
int

Definition at line 1556 of file gis/cats.c.

References G_free(), G_quant_free(), and NULL.

Referenced by E_edit_fp_cats(), G_free_cats(), and G_sort_cats().

char* G_get_c_raster_cat ( CELL *  rast,
struct Categories *  pcats 
)

given a CELL value val Returns pointer to a string describing category.

Parameters
val
pcats
Returns
char *

Definition at line 600 of file gis/cats.c.

References G_get_raster_cat().

Referenced by G_get_cat(), and Gs_get_cat_label().

char* G_get_cat ( CELL  num,
struct Categories *  pcats 
)

get a category label

This routine looks up category n in the cats structure and returns a pointer to a string which is the label for the category. A legal pointer is always returned. If the category does not exist in cats, then a pointer to the empty string "" is returned. Warning. The pointer that is returned points to a hidden static buffer. Successive calls to G_get_cat( ) overwrite this buffer.

Parameters
n
cats
Returns
char *

Definition at line 583 of file gis/cats.c.

References G_get_c_raster_cat().

Referenced by E_edit_cats(), G_get_raster_sample_bilinear(), G_get_raster_sample_cubic(), G_get_raster_sample_nearest(), and gsd_put_legend().

char* G_get_cats_title ( const struct Categories *  pcats)

get title from category structure struct

Map layers store a one-line title in the category structure as well. This routine returns a pointer to the title contained in the cats structure. A legal pointer is always returned. If the map layer does not have a title, then a pointer to the empty string "" is returned.

Parameters
cats
Returns
char *

Definition at line 545 of file gis/cats.c.

References G_get_raster_cats_title().

char* G_get_d_raster_cat ( DCELL *  rast,
struct Categories *  pcats 
)

given a DCELL value val Returns pointer to a string describing category.

Parameters
val
pcats
Returns
char *

Definition at line 634 of file gis/cats.c.

References G_get_raster_cat().

Referenced by Gs_get_cat_label(), and gsd_put_legend().

char* G_get_f_raster_cat ( FCELL *  rast,
struct Categories *  pcats 
)

given a FCELL value val Returns pointer to a string describing category.

Parameters
val
pcats
Returns
char *

Definition at line 617 of file gis/cats.c.

References G_get_raster_cat().

char* G_get_ith_c_raster_cat ( const struct Categories *  pcats,
int  i,
void *  rast1,
void *  rast2 
)

Returns i-th description and i-th data range from the list of category descriptions with corresponding data ranges. end points of data interval in rast1 and rast2.

Parameters
pcats
i
rast1
rast2
Returns
char *

Definition at line 1355 of file gis/cats.c.

References G_get_ith_d_raster_cat(), G_set_raster_value_d(), val1, and val2.

char* G_get_ith_d_raster_cat ( const struct Categories *  pcats,
int  i,
DCELL *  rast1,
DCELL *  rast2 
)

Returns i-th description and i-th data range from the list of category descriptions with corresponding data ranges. end points of data interval in rast1 and rast2.

Parameters
pcats
i
rast1
rast2
Returns
char *

Definition at line 1298 of file gis/cats.c.

References G_quant_get_ith_rule(), and G_set_d_null_value().

Referenced by G3d_writeCats(), G__write_cats(), G_copy_raster_cats(), G_get_ith_c_raster_cat(), G_get_ith_f_raster_cat(), G_get_ith_raster_cat(), G_get_next_marked_d_raster_cat(), G_set_d_raster_cat(), and G_sort_cats().

char* G_get_ith_f_raster_cat ( const struct Categories *  pcats,
int  i,
void *  rast1,
void *  rast2 
)

Returns i-th description and i-th data range from the list of category descriptions with corresponding data ranges. end points of data interval in rast1 and rast2.

Parameters
pcats
i
rast1
rast2
Returns
char *

Definition at line 1327 of file gis/cats.c.

References G_get_ith_d_raster_cat(), G_set_raster_value_d(), val1, and val2.

char* G_get_ith_raster_cat ( const struct Categories *  pcats,
int  i,
void *  rast1,
void *  rast2,
RASTER_MAP_TYPE  data_type 
)

Returns i-th description and i-th data range from the list of category descriptions with corresponding data ranges. Stores end points of data interval in rast1 and rast2 (after converting them to data_type.

Parameters
pcats
i
rast1
rast2
data_type
Returns
char *

Definition at line 1385 of file gis/cats.c.

References G_get_ith_d_raster_cat(), G_set_raster_value_d(), val1, and val2.

char* G_get_next_marked_c_raster_cat ( struct Categories *  pcats,
CELL *  rast1,
CELL *  rast2,
long *  count 
)

Definition at line 890 of file gis/cats.c.

References G_get_next_marked_raster_cat().

char* G_get_next_marked_d_raster_cat ( struct Categories *  pcats,
DCELL *  rast1,
DCELL *  rast2,
long *  count 
)

Definition at line 860 of file gis/cats.c.

References G_get_ith_d_raster_cat(), G_quant_nof_rules(), and NULL.

Referenced by G_get_next_marked_raster_cat().

char* G_get_next_marked_f_raster_cat ( struct Categories *  pcats,
FCELL *  rast1,
FCELL *  rast2,
long *  count 
)

Definition at line 898 of file gis/cats.c.

References G_get_next_marked_raster_cat().

char* G_get_next_marked_raster_cat ( struct Categories *  pcats,
void *  rast1,
void *  rast2,
long *  count,
RASTER_MAP_TYPE  data_type 
)
char* G_get_raster_cat ( void *  rast,
struct Categories *  pcats,
RASTER_MAP_TYPE  data_type 
)

given a raster value val of type data_type Returns pointer to a string describing category.

Parameters
val
pcats
data_type
Returns
char *

Definition at line 652 of file gis/cats.c.

References G_debug(), G_get_raster_value_d(), G_is_c_null_value(), G_is_null_value(), G_quant_get_cell_value(), l, tools::label, NULL, and sprintf().

Referenced by G_get_c_raster_cat(), G_get_d_raster_cat(), and G_get_f_raster_cat().

char* G_get_raster_cats_title ( const struct Categories *  pcats)

get raster cats title

Returns pointer to a string with title.

Parameters
pcats
Returns
char *

Definition at line 560 of file gis/cats.c.

Referenced by G_get_cats_title().

int G_init_cats ( CELL  num,
const char *  title,
struct Categories *  pcats 
)

initialize category structure

To construct a new category file, the structure must first be initialized. This routine initializes the cats structure, and copies the title into the structure. The number of categories is set initially to n. For example:

struct Categories cats;
G_init_cats ( (CELL)0, "", &cats);
Parameters
n
title
cats
Returns
int

Definition at line 1417 of file gis/cats.c.

References G_init_raster_cats(), and num.

int G_init_raster_cats ( const 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.

Parameters
title
pcats
Returns
int

Definition at line 1437 of file gis/cats.c.

References G_quant_init(), G_set_raster_cats_title(), and NULL.

Referenced by E_edit_fp_cats(), G__read_cats(), G_copy_raster_cats(), G_init_cats(), and G_sort_cats().

int G_mark_c_raster_cats ( CELL *  rast_row,
int  ncols,
struct Categories *  pcats 
)

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.

Parameters
rast_row
ncols
pcats
Returns
int

Definition at line 755 of file gis/cats.c.

References G_mark_raster_cats().

int G_mark_d_raster_cats ( DCELL *  rast_row,
int  ncols,
struct Categories *  pcats 
)

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.

Parameters
rast_row
ncols
pcats
Returns
int

Definition at line 799 of file gis/cats.c.

References G_mark_raster_cats().

int G_mark_f_raster_cats ( FCELL *  rast_row,
int  ncols,
struct Categories *  pcats 
)

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.

Parameters
rast_row
ncols
pcats
Returns
int

Definition at line 777 of file gis/cats.c.

References G_mark_raster_cats().

int G_mark_raster_cats ( void *  rast_row,
int  ncols,
struct Categories *  pcats,
RASTER_MAP_TYPE  data_type 
)

Looks up the category label for each raster value in the rast_row (row of raster cell value) 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.

Parameters
rast_row
ncols
pcats
data_type
Returns
int

Definition at line 823 of file gis/cats.c.

References G_get_raster_value_d(), G_incr_void_ptr(), G_is_c_null_value(), G_quant_get_cell_value(), and G_raster_size().

Referenced by G_mark_c_raster_cats(), G_mark_d_raster_cats(), and G_mark_f_raster_cats().

CELL G_number_of_cats ( const char *  name,
const char *  mapset 
)

Definition at line 422 of file gis/cats.c.

References G_get_range_min_max(), G_is_c_null_value(), G_read_range(), max, and min.

int G_number_of_raster_cats ( struct Categories *  pcats)

Definition at line 1613 of file gis/cats.c.

int G_read_cats ( const char *  name,
const char *  mapset,
struct Categories *  pcats 
)

read raster category file

The category file for raster map name in mapset is read into the cats structure. If there is an error reading the category file, a diagnostic message is printed and -1 is returned. Otherwise, 0 is returned.

Parameters
name
mapset
cats
Returns
int

Definition at line 347 of file gis/cats.c.

References G_read_raster_cats().

Referenced by Gs_get_cat_label(), and gsd_put_legend().

int G_read_raster_cats ( const char *  name,
const char *  mapset,
struct Categories *  pcats 
)

Is the same as existing G_read_cats()

Parameters
name
mapset
pcats
Returns
int

Definition at line 365 of file gis/cats.c.

References G__read_cats(), G_warning(), and dialogs::type.

Referenced by G_read_cats().

int G_read_vector_cats ( const char *  name,
const char *  mapset,
struct Categories *  pcats 
)

read vector category file

The category file for vector map name in mapset is read into the cats structure. If there is an error reading the category file, a diagnostic message is printed and -1 is returned. Otherwise, 0 is returned.

Parameters
name
mapset
cats
Returns
int

Definition at line 401 of file gis/cats.c.

References G__read_cats(), G_warning(), and dialogs::type.

int G_rewind_raster_cats ( struct Categories *  pcats)

after call to this function G_get_next_marked_raster_cat() returns the first marked cat label.

Parameters
pcats
Returns
int

Definition at line 854 of file gis/cats.c.

int G_set_c_raster_cat ( CELL *  rast1,
CELL *  rast2,
char *  label,
struct Categories *  pcats 
)

Adds the label for range rast1 through rast2 in category structure pcats.

Parameters
rast1
rast2
pcats
Returns
int

Definition at line 1021 of file gis/cats.c.

References G_set_raster_cat().

Referenced by G_set_cat().

int G_set_cat ( CELL  num,
char *  label,
struct Categories *  pcats 
)

set a category label

The label is copied into the cats structure for category n.

Parameters
n
label
cats
Returns
int

Definition at line 1001 of file gis/cats.c.

References G_set_c_raster_cat(), and num.

Referenced by E_edit_cats(), for(), and G__read_cats().

int G_set_cats_fmt ( const char *  fmt,
double  m1,
double  a1,
double  m2,
double  a2,
struct Categories *  pcats 
)

Definition at line 1493 of file gis/cats.c.

References G_set_raster_cats_fmt().

int G_set_cats_title ( const char *  title,
struct Categories *  pcats 
)

set title in category structure

The title is copied into the cats structure.

Parameters
title
cats
Returns
int

Definition at line 1466 of file gis/cats.c.

References G_set_raster_cats_title().

int G_set_d_raster_cat ( DCELL *  rast1,
DCELL *  rast2,
char *  label,
struct Categories *  pcats 
)

Adds the label for range rast1 through rast2 in category structure pcats.

Parameters
rast1
rast2
pcats
Returns
int

Definition at line 1059 of file gis/cats.c.

References G_free(), G_get_ith_d_raster_cat(), G_is_d_null_value(), G_newlines_to_spaces(), G_quant_add_rule(), G_store(), G_strip(), int, and NULL.

Referenced by E_edit_fp_cats(), G_copy_raster_cats(), G_set_raster_cat(), and G_sort_cats().

int G_set_f_raster_cat ( FCELL *  rast1,
FCELL *  rast2,
char *  label,
struct Categories *  pcats 
)

Adds the label for range rast1 through rast2 in category structure pcats.

Parameters
rast1
rast2
pcats
Returns
int

Definition at line 1040 of file gis/cats.c.

References G_set_raster_cat().

int G_set_raster_cat ( void *  rast1,
void *  rast2,
char *  label,
struct Categories *  pcats,
RASTER_MAP_TYPE  data_type 
)

Adds the label for range rast1 through rast2 in category structure pcats.

Parameters
rast1
rast2
pcats
data_type
Returns
int

Definition at line 1160 of file gis/cats.c.

References G_get_raster_value_d(), G_set_d_raster_cat(), val1, and val2.

Referenced by for(), G__read_cats(), G_set_c_raster_cat(), and G_set_f_raster_cat().

int G_set_raster_cats_fmt ( const char *  fmt,
double  m1,
double  a1,
double  m2,
double  a2,
struct Categories *  pcats 
)

Same as existing G_set_cats_fmt()

Parameters
fmt
m1
a1
m2
a2
pcats
Returns
int

Definition at line 1515 of file gis/cats.c.

References G_newlines_to_spaces(), G_store(), and G_strip().

Referenced by G__read_cats(), and G_set_cats_fmt().

int G_set_raster_cats_title ( const char *  title,
struct Categories *  pcats 
)

Same as existing G_set_cats_title()

Parameters
title
pcats
Returns
int

Definition at line 1483 of file gis/cats.c.

References G_newlines_to_spaces(), G_store(), G_strip(), and NULL.

Referenced by G_init_raster_cats(), and G_set_cats_title().

int G_sort_cats ( struct Categories *  pcats)
int 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.

Parameters
pcats
Returns
int

Definition at line 731 of file gis/cats.c.

int G_write_cats ( char *  name,
struct Categories *  cats 
)

write raster category file

Writes the category file for the raster map name in the current mapset from the cats structure. Returns 1 if successful. Otherwise, -1 is returned (no diagnostic is printed).

Parameters
name
cats
Returns
int

Definition at line 1185 of file gis/cats.c.

References G__write_cats().

int G_write_raster_cats ( char *  name,
struct Categories *  cats 
)

Same as existing G_write_cats()

Parameters
name
pcats
Returns
int

Definition at line 1201 of file gis/cats.c.

References G__write_cats().

int G_write_vector_cats ( char *  name,
struct Categories *  cats 
)

write vector category file

Writes the category file for the vector map name in the current mapset from the cats structure. Returns 1 if successful. Otherwise, -1 is returned (no diagnostic is printed).

Parameters
name
cats
Returns
int

Definition at line 1221 of file gis/cats.c.

References G__write_cats().