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

Go to the source code of this file.

Functions

struct line_cats * Vect__new_cats_struct ()
 Creates and initializes line_cats structure (lower level fn)
struct line_cats * Vect_new_cats_struct ()
 Creates and initializes line_cats structure.
int Vect_destroy_cats_struct (struct line_cats *p)
 Frees all memory associated with line_cats structure, including the struct itself.
int Vect_cat_set (struct line_cats *Cats, int field, int cat)
 Add new field/cat to category structure if doesn't exist yet.
int Vect_cat_get (struct line_cats *Cats, int field, int *cat)
 Get first found category of given field.
int Vect_field_cat_get (struct line_cats *Cats, int field, struct ilist *cats)
 Get list of categories of given field.
int Vect_cat_del (struct line_cats *Cats, int field)
 Delete all categories of given layer.
int Vect_field_cat_del (struct line_cats *Cats, int field, int cat)
 Delete field/cat from line_cats structure.
int Vect_reset_cats (struct line_cats *Cats)
 Reset category structure to make sure cats structure is clean to be re-used.
struct cat_list * Vect_new_cat_list ()
 Allocate memory for cat_list structure.
int Vect_destroy_cat_list (struct cat_list *p)
 Frees allocated cat_list memory.
int Vect_str_to_cat_list (const char *str, struct cat_list *list)
 Convert string of categories and cat ranges separated by commas to cat_list.
int Vect_array_to_cat_list (int *vals, int nvals, struct cat_list *list)
 Convert ordered array of integers to cat_list structure.
int Vect_cat_in_cat_list (int cat, struct cat_list *list)
 Check if category number is in list.
int Vect_cat_in_array (int cat, int *array, int ncats)
 Check if category is in ordered array of integers.

Function Documentation

struct line_cats * Vect__new_cats_struct ( )
read

Creates and initializes line_cats structure (lower level fn)

This structure is used for reading and writing vector cats. The library routines handle all memory allocation.

Returns
struct line_cats *

Definition at line 58 of file vector/Vlib/cats.c.

Referenced by Vect_new_cats_struct().

int Vect_array_to_cat_list ( int *  vals,
int  nvals,
struct cat_list *  list 
)

Convert ordered array of integers to cat_list structure.

Parameters
[in]valsarray of integers
[in]nvalsnumber of values
[out]listresult cat_list structure
Returns
number of ranges

Definition at line 432 of file vector/Vlib/cats.c.

References G_debug().

int Vect_cat_del ( struct line_cats *  Cats,
int  field 
)

Delete all categories of given layer.

Parameters
[in]Catsline_cats structure
[in]fieldlayer number
Returns
1 deleted
0 layer does not exist

Definition at line 221 of file vector/Vlib/cats.c.

Referenced by gui_modules.wxvdigit.IVDigit::DeleteSelectedLines().

int Vect_cat_get ( struct line_cats *  Cats,
int  field,
int *  cat 
)

Get first found category of given field.

'cat' is set to first category found or -1 if field was not found

Parameters
[in]Catsline_cats structure
[in]fieldlayer number
[in]catpointer to variable where cat will be written
Returns
1 found
0 layer does not exist

Definition at line 157 of file vector/Vlib/cats.c.

Referenced by G_site_get(), IL_vector_input_data_2d(), NetA_get_node_costs(), Vect_get_line_cat(), Vect_net_build_graph(), and Vect_set_varray_from_cat_list().

int Vect_cat_in_array ( int  cat,
int *  array,
int  ncats 
)

Check if category is in ordered array of integers.

Parameters
[in]catcategory number
[in]arrayordered array of integers
[in]ncatsnumber of categories in array
Returns
TRUE if cat is in list
FALSE if it is not

Definition at line 493 of file vector/Vlib/cats.c.

References FALSE, NULL, and TRUE.

int Vect_cat_in_cat_list ( int  cat,
struct cat_list *  list 
)

Check if category number is in list.

Parameters
[in]catcategory number
[in]listcat_list structure
Returns
TRUE if cat is in list
FALSE if it is not

Definition at line 472 of file vector/Vlib/cats.c.

References FALSE, max, and TRUE.

Referenced by Vect_set_varray_from_cat_list().

int Vect_cat_set ( struct line_cats *  Cats,
int  field,
int  cat 
)

Add new field/cat to category structure if doesn't exist yet.

Parameters
[in]Catsline_cats structure
[in]fieldlayer number
[in]catcategory number
Returns
number of categories
0 if no space for new category in structure, n_cats would be > GV_NCATS_MAX
-1 on out of memory
-2 if field out of range: 1 - GV_FIELD_MAX or cat out of range: 1 - GV_CAT_MAX

Definition at line 106 of file vector/Vlib/cats.c.

References dig_alloc_cats(), and G_fatal_error().

Referenced by gui_modules.wxvdigit.IVDigit::CopyCats(), gui_modules.wxvdigit.IVDigit::DeleteSelectedLines(), G_site_put(), IL_check_at_points_2d(), gui_modules.wxvdigit.IVDigit::InitCats(), gui_modules.wxvdigit.IVDigit::SetLineCats(), V1_read_next_line_ogr(), V2_read_line_ogr(), Vect_clean_small_angles_at_nodes(), Vect_merge_lines(), Vect_overlay_and(), Vect_remove_duplicates(), and Vedit_modify_cats().

int Vect_destroy_cat_list ( struct cat_list *  p)

Frees allocated cat_list memory.

Parameters
[in]pline_cats structure
Returns
0

Definition at line 331 of file vector/Vlib/cats.c.

References G_free().

Referenced by Vect_set_varray_from_cat_string().

int Vect_field_cat_del ( struct line_cats *  Cats,
int  field,
int  cat 
)

Delete field/cat from line_cats structure.

Parameters
[in]Catsline_cats structure
[in]fieldlayer number
[in]catcategory to be deleted or -1 to delete all cats of given field
Returns
1 deleted
0 field/category number does not exist

Definition at line 257 of file vector/Vlib/cats.c.

Referenced by gui_modules.wxvdigit.IVDigit::SetLineCats(), and Vedit_modify_cats().

int Vect_field_cat_get ( struct line_cats *  Cats,
int  field,
struct ilist *  cats 
)

Get list of categories of given field.

Parameters
Catsline_cats structure
fieldlayer number
[out]catspointer to list where cats will be written
Returns
number of found categories
-1 on invalid field

Definition at line 191 of file vector/Vlib/cats.c.

References Vect_list_append(), and Vect_reset_list().

struct cat_list* Vect_new_cat_list ( )
read

Allocate memory for cat_list structure.

Returns
poiter to allocated structure
NULL on out of memory

Definition at line 305 of file vector/Vlib/cats.c.

References NULL.

Referenced by Vect_set_varray_from_cat_string().

int Vect_reset_cats ( struct line_cats *  Cats)

Reset category structure to make sure cats structure is clean to be re-used.

I.e. it has no cats associated with it. Cats must have previously been created with Vect_new_cats_struct()

Parameters
[out]Catsline_cats structure
Returns
0

Definition at line 292 of file vector/Vlib/cats.c.

Referenced by G_site_put(), IL_check_at_points_2d(), gui_modules.wxvdigit.IVDigit::InitCats(), V1_read_next_line_ogr(), V2_read_line_ogr(), Vect_break_polygons(), Vect_clean_small_angles_at_nodes(), Vect_get_area_cat(), Vect_get_area_cats(), Vect_merge_lines(), and Vect_overlay_and().

int Vect_str_to_cat_list ( const char *  str,
struct cat_list *  list 
)

Convert string of categories and cat ranges separated by commas to cat_list.

Examples of string: 2,3,5-9,20. str - input string

Parameters
[in]strcat list string
[out]listresult cat_list structure
Returns
number of errors in ranges

Definition at line 355 of file vector/Vlib/cats.c.

References err(), G_debug(), G_warning(), max, min, NULL, and gui_modules.psmap_dialogs::s.

Referenced by Vect_set_varray_from_cat_string().