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 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 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] vals array of integers
[in] nvals number of values
[out] list result cat_list structure
Returns:
number of ranges

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

int Vect_cat_del ( struct line_cats *  Cats,
int  field 
)

Delete all categories of given layer.

Parameters:
[in] Cats line_cats structure
[in] field layer number
Returns:
1 deleted
0 layer does not exist

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

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] Cats line_cats structure
[in] field layer number
[in] cat pointer to variable where cat will be written
Returns:
1 found
0 layer does not exist

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

Referenced by 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] cat category number
[in] array ordered array of integers
[in] ncats number of categories in array
Returns:
TRUE if cat is in list
FALSE if it is not

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

References FALSE.

int Vect_cat_in_cat_list ( int  cat,
struct cat_list *  list 
)

Check if category number is in list.

Parameters:
[in] cat category number
[in] list cat_list structure
Returns:
TRUE if cat is in list
FALSE if it is not

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

References FALSE.

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] Cats line_cats structure
[in] field layer number
[in] cat category 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 Vlib/cats.c.

References dig_alloc_cats().

Referenced by V1_read_next_line_ogr(), V2_read_line_ogr(), Vect_clean_small_angles_at_nodes(), 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] p line_cats structure
Returns:
0

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

Referenced by Vect_set_varray_from_cat_string().

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

Delete field/cat from line_cats structure.

Parameters:
[in] Cats line_cats structure
[in] field layer number
[in] cat category 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 Vlib/cats.c.

Referenced by 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:
Cats line_cats structure
field layer number
[out] cats pointer to list where cats will be written
Returns:
number of found categories
-1 on invalid field

Definition at line 191 of file 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 Vlib/cats.c.

Referenced by Vect_set_varray_from_cat_string().

struct line_cats* Vect_new_cats_struct (  )  [read]
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] Cats line_cats structure
Returns:
0

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

Referenced by 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(), 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] str cat list string
[out] list result cat_list structure
Returns:
number of errors in ranges

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

Referenced by Vect_set_varray_from_cat_string().

Generated on Tue Apr 6 13:28:12 2010 for GRASS Programmer's Manual by  doxygen 1.6.3