GRASS GIS 8 Programmer's Manual
8.2.2dev(2023)-3d2c704037
|
Vector library - Category management. More...
#include <stdlib.h>
#include <string.h>
#include <grass/vector.h>
#include <grass/dbmi.h>
#include <grass/glocale.h>
Go to the source code of this file.
Functions | |
struct line_cats * | Vect_new_cats_struct () |
Creates and initializes line_cats structure. More... | |
void | Vect_destroy_cats_struct (struct line_cats *p) |
Frees all memory associated with line_cats structure, including the struct itself. More... | |
int | Vect_cat_set (struct line_cats *Cats, int field, int cat) |
Add new field/cat to category structure if doesn't exist yet. More... | |
int | Vect_cat_get (const struct line_cats *Cats, int field, int *cat) |
Get first found category of given field. More... | |
int | Vect_field_cat_get (const struct line_cats *Cats, int field, struct ilist *cats) |
Get list of categories of given field. More... | |
int | Vect_cat_del (struct line_cats *Cats, int field) |
Delete all categories of given layer. More... | |
int | Vect_field_cat_del (struct line_cats *Cats, int field, int cat) |
Delete field/cat from line_cats structure. More... | |
int | Vect_reset_cats (struct line_cats *Cats) |
Reset category structure to make sure cats structure is clean to be re-used. More... | |
struct cat_list * | Vect_new_cat_list () |
Allocate memory for cat_list structure. More... | |
void | Vect_destroy_cat_list (struct cat_list *p) |
Frees allocated cat_list memory. More... | |
int | Vect_str_to_cat_list (const char *str, struct cat_list *list) |
Converts string of categories and cat ranges separated by commas to cat_list. More... | |
int | Vect_array_to_cat_list (const int *vals, int nvals, struct cat_list *list) |
Convert ordered array of integers to cat_list structure. More... | |
int | Vect_cat_list_to_array (const struct cat_list *list, int **vals, int *nvals) |
Convert cat_list struct to ordered array of unique integers. More... | |
int | Vect_cat_in_cat_list (int cat, const struct cat_list *list) |
Check if category number is in list. More... | |
struct cat_list * | Vect_cats_set_constraint (struct Map_info *Map, int layer, char *where, char *catstr) |
Set category constraints using 'where' or 'cats' option and layer number. More... | |
int | Vect_cats_in_constraint (struct line_cats *Cats, int layer, struct cat_list *list) |
Check if categories match with category constraints. More... | |
int | Vect_cat_in_array (int cat, const int *array, int ncats) |
Check if category is in ordered array of integers. More... | |
Vector library - Category management.
Higher level functions for reading/writing/manipulating vectors.
(C) 2001-2012 by the 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.
Definition in file vector/Vlib/cats.c.
int Vect_array_to_cat_list | ( | const int * | vals, |
int | nvals, | ||
struct cat_list * | list | ||
) |
Convert ordered array of integers to cat_list structure.
vals | array of integers | |
nvals | number of values | |
[in,out] | list | pointer to cat_list structure |
Definition at line 444 of file vector/Vlib/cats.c.
References cat_list::alloc_ranges, G_debug(), G_realloc, cat_list::max, cat_list::min, and cat_list::n_ranges.
int Vect_cat_del | ( | struct line_cats * | Cats, |
int | field | ||
) |
Delete all categories of given layer.
[in,out] | Cats | line_cats structure |
field | layer number |
Definition at line 221 of file vector/Vlib/cats.c.
References line_cats::cat, line_cats::field, and line_cats::n_cats.
Referenced by Vect_field_cat_del().
int Vect_cat_get | ( | const 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
Cats | pointer line_cats structure | |
field | layer number | |
[out] | cat | pointer to variable where cat will be written (can be NULL) |
Definition at line 156 of file vector/Vlib/cats.c.
References line_cats::cat, line_cats::field, GV_FIELD_MAX, and line_cats::n_cats.
Referenced by NetA_initialise_varray().
int Vect_cat_in_array | ( | int | cat, |
const int * | array, | ||
int | ncats | ||
) |
Check if category is in ordered array of integers.
cat | category number |
array | ordered array of integers |
ncats | number of categories in array |
Definition at line 707 of file vector/Vlib/cats.c.
int Vect_cat_in_cat_list | ( | int | cat, |
const struct cat_list * | list | ||
) |
Check if category number is in list.
cat | category number |
list | cat_list structure |
Definition at line 544 of file vector/Vlib/cats.c.
References FALSE, max, cat_list::min, cat_list::n_ranges, and TRUE.
Referenced by Vect_cats_in_constraint().
int Vect_cat_list_to_array | ( | const struct cat_list * | list, |
int ** | vals, | ||
int * | nvals | ||
) |
Convert cat_list struct to ordered array of unique integers.
Output array do not contain duplicate items.
Allocated array should be freed by G_free().
Definition at line 489 of file vector/Vlib/cats.c.
References G_debug(), G_realloc, cat_list::max, cat_list::min, cat_list::n_ranges, and NULL.
int Vect_cat_set | ( | struct line_cats * | Cats, |
int | field, | ||
int | cat | ||
) |
Add new field/cat to category structure if doesn't exist yet.
[in,out] | Cats | line_cats structure |
[in] | field | layer number |
[in] | cat | category number |
Definition at line 104 of file vector/Vlib/cats.c.
References _, line_cats::alloc_cats, line_cats::cat, dig_alloc_cats(), line_cats::field, G_fatal_error(), GV_NCATS_MAX, and line_cats::n_cats.
Check if categories match with category constraints.
Definition at line 667 of file vector/Vlib/cats.c.
References _, line_cats::cat, line_cats::field, G_warning(), line_cats::n_cats, and Vect_cat_in_cat_list().
struct cat_list* Vect_cats_set_constraint | ( | struct Map_info * | Map, |
int | layer, | ||
char * | where, | ||
char * | catstr | ||
) |
Set category constraints using 'where' or 'cats' option and layer number.
Map | pointer to Map_info structure |
layer | layer number |
where | where statement |
catstr | category list as string |
Definition at line 565 of file vector/Vlib/cats.c.
References _, field_info::database, db_close_database_shutdown_driver(), db_select_int(), db_start_driver_open_database(), field_info::driver, G_fatal_error(), G_verbose_message(), G_warning(), field_info::key, list, n_, NULL, field_info::table, and Vect_get_field().
void Vect_destroy_cat_list | ( | struct cat_list * | p | ) |
Frees allocated cat_list memory.
p | pointer to line_cats structure |
Definition at line 326 of file vector/Vlib/cats.c.
References G_free(), cat_list::max, cat_list::min, and cat_list::n_ranges.
void Vect_destroy_cats_struct | ( | struct line_cats * | p | ) |
Frees all memory associated with line_cats structure, including the struct itself.
p | line_cats structure |
Definition at line 80 of file vector/Vlib/cats.c.
References line_cats::cat, line_cats::field, G_free(), and line_cats::n_cats.
Referenced by NetA_initialise_varray().
int Vect_field_cat_del | ( | struct line_cats * | Cats, |
int | field, | ||
int | cat | ||
) |
Delete field/cat from line_cats structure.
[in,out] | Cats | line_cats structure |
field | layer number | |
cat | category to be deleted or -1 to delete all cats of given field |
Definition at line 256 of file vector/Vlib/cats.c.
References line_cats::cat, line_cats::field, line_cats::n_cats, and Vect_cat_del().
Get list of categories of given field.
Cats | line_cats structure | |
field | layer number | |
[out] | cats | pointer to list where cats will be written |
Definition at line 192 of file vector/Vlib/cats.c.
References line_cats::cat, line_cats::field, GV_FIELD_MAX, line_cats::n_cats, ilist::n_values, Vect_list_append(), and Vect_reset_list().
struct cat_list* Vect_new_cat_list | ( | void | ) |
Allocate memory for cat_list structure.
Definition at line 307 of file vector/Vlib/cats.c.
struct line_cats* Vect_new_cats_struct | ( | void | ) |
Creates and initializes line_cats structure.
This structure is used for reading and writing vector cats. The library routines handle all memory allocation.
To free allocated memory call Vect_destroy_cats_struct().
Definition at line 40 of file vector/Vlib/cats.c.
References NULL.
Referenced by NetA_initialise_varray(), and Vect_get_area_cat().
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()
[out] | Cats | line_cats structure |
Definition at line 294 of file vector/Vlib/cats.c.
References line_cats::n_cats.
Referenced by Vect_get_area_cat(), and Vect_get_area_cats().
int Vect_str_to_cat_list | ( | const char * | str, |
struct cat_list * | list | ||
) |
Converts string of categories and cat ranges separated by commas to cat_list.
5,6,7 3-9 2,3,5-9,20
cat_list->field = 0 cat_list->n_ranges = 4 cat_list->min = {2, 3, 5, 20} cat_list->max = {2, 3, 9, 20}
str | category list as a string | |
[in,out] | list | pointer to cat_list structure |
Definition at line 367 of file vector/Vlib/cats.c.