|
GRASS 8 Programmer's Manual 8.6.0dev(2026)-1d1e47ad9d
|
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 (void) |
| Creates and initializes line_cats structure. | |
| void | 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 (const struct line_cats *Cats, int field, int *cat) |
| Get first found category of given field. | |
| int | Vect_field_cat_get (const 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 (void) |
| Allocate memory for cat_list structure. | |
| void | 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) |
| Converts string of categories and cat ranges separated by commas to cat_list. | |
| int | Vect_array_to_cat_list (const int *vals, int nvals, struct cat_list *list) |
| Convert ordered array of integers to cat_list structure. | |
| 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. | |
| int | Vect_cat_in_cat_list (int cat, const struct cat_list *list) |
| Check if category number is in 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. | |
| int | Vect_cats_in_constraint (struct line_cats *Cats, int layer, struct cat_list *list) |
| Check if categories match with category constraints. | |
| int | Vect_cat_in_array (int cat, const int *array, int ncats) |
| Check if category is in ordered array of integers. | |
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.
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 446 of file vector/Vlib/cats.c.
References G_debug(), and G_realloc.
Referenced by Vect_cats_set_constraint().
Delete all categories of given layer.
| [in,out] | Cats | line_cats structure |
| field | layer number |
Definition at line 222 of file vector/Vlib/cats.c.
References line_cats::field.
Referenced by Vect_field_cat_del().
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, and GV_FIELD_MAX.
Referenced by Gp_load_sites_thematic(), Gv_load_vect_thematic(), IL_vector_input_data_2d(), NetA_get_node_costs(), NetA_initialise_varray(), P_Read_Vector_Region_Map(), V1_read_next_line_nat(), V2_read_next_line_nat(), Vect_get_line_cat(), Vect_net_build_graph(), Vect_net_ttb_build_graph(), Vect_net_ttb_shortest_path(), Vect_set_varray_from_cat_list(), and Vect_write_ascii().
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 712 of file vector/Vlib/cats.c.
References NULL.
Check if category number is in list.
| cat | category number |
| list | cat_list structure |
Definition at line 546 of file vector/Vlib/cats.c.
References FALSE, max, and TRUE.
Referenced by Vect_cats_in_constraint(), and Vect_set_varray_from_cat_list().
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().
| list | pointer to cat_list struct | |
| [out] | vals | array of integers |
| [out] | nvals | number of values |
Definition at line 489 of file vector/Vlib/cats.c.
References G_debug(), G_free(), G_malloc, G_realloc, and NULL.
Referenced by Vect_copy_table_by_cat_list().
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 103 of file vector/Vlib/cats.c.
References _, line_cats::cat, dig_alloc_cats(), line_cats::field, G_fatal_error(), and GV_NCATS_MAX.
Referenced by IL_write_point_2d(), P_Aux_to_Vector(), V1_read_line_ogr(), V1_read_line_pg(), V2_read_line_pg(), V2_read_line_sfa(), V2_read_next_line_ogr(), V2_read_next_line_pg(), Vect__copy_areas(), Vect_clean_small_angles_at_nodes(), Vect_overlay_and(), Vect_read_ascii(), Vect_remove_duplicates(), and Vedit_modify_cats().
Check if categories match with category constraints.
Definition at line 673 of file vector/Vlib/cats.c.
References _, G_warning(), 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 568 of file vector/Vlib/cats.c.
References _, db_close_database_shutdown_driver(), db_select_int(), db_start_driver_open_database(), G_fatal_error(), G_free(), G_verbose_message(), G_warning(), n_, NULL, Vect_array_to_cat_list(), Vect_destroy_cat_list(), Vect_get_field(), Vect_new_cat_list(), and Vect_str_to_cat_list().
Frees allocated cat_list memory.
| p | pointer to line_cats structure |
Definition at line 327 of file vector/Vlib/cats.c.
References G_free(), cat_list::max, cat_list::min, and cat_list::n_ranges.
Referenced by Vect_cats_set_constraint(), and Vect_set_varray_from_cat_string().
Frees all memory associated with line_cats structure, including the struct itself.
| p | line_cats structure |
Definition at line 79 of file vector/Vlib/cats.c.
References line_cats::cat, line_cats::field, G_free(), and line_cats::n_cats.
Referenced by NetA_get_node_costs(), NetA_initialise_varray(), P_estimate_splinestep(), P_Read_Vector_Region_Map(), Vect__copy_areas(), Vect_break_polygons_file(), Vect_break_polygons_mem(), Vect_build_nat(), Vect_clean_small_angles_at_nodes(), Vect_merge_lines(), Vect_net_ttb_build_graph(), Vect_net_ttb_shortest_path(), Vect_overlay_and(), Vect_read_ascii(), Vect_read_line_to_wkb(), Vect_remove_duplicates(), Vect_remove_small_areas_ext(), Vect_remove_small_areas_nat(), Vect_set_varray_from_cat_list(), Vect_set_varray_from_db(), Vect_snap_line(), Vect_topo_check(), Vect_write_ascii(), Vedit_add_vertex(), Vedit_bulk_labeling(), Vedit_chtype_lines(), Vedit_copy_lines(), Vedit_flip_lines(), Vedit_merge_lines(), Vedit_modify_cats(), Vedit_move_lines(), Vedit_move_vertex(), Vedit_remove_vertex(), Vedit_select_by_query(), Vedit_snap_line(), Vedit_snap_lines(), and Vedit_split_lines().
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 257 of file vector/Vlib/cats.c.
References line_cats::cat, line_cats::field, and Vect_cat_del().
Referenced by Vedit_modify_cats().
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::field, GV_FIELD_MAX, ilist::n_values, Vect_list_append(), and Vect_reset_list().
Referenced by Vect_write_ascii().
Allocate memory for cat_list structure.
Definition at line 309 of file vector/Vlib/cats.c.
References G_malloc, and G_zero().
Referenced by Vect_cats_set_constraint(), and Vect_set_varray_from_cat_string().
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 39 of file vector/Vlib/cats.c.
References _, G_fatal_error(), and NULL.
Referenced by Gp_load_sites(), Gv_load_vect(), IL_vector_input_data_2d(), NetA_get_node_costs(), NetA_initialise_varray(), P_Aux_to_Vector(), P_estimate_splinestep(), P_Read_Vector_Region_Map(), V1_rewrite_line_nat(), V2_delete_line_nat(), V2_delete_line_sfa(), V2_restore_line_nat(), V2_rewrite_line_nat(), Vect__copy_areas(), Vect_break_polygons_file(), Vect_break_polygons_mem(), Vect_build_nat(), Vect_clean_small_angles_at_nodes(), Vect_get_area_cat(), Vect_get_line_cat(), Vect_merge_lines(), Vect_net_build_graph(), Vect_net_ttb_build_graph(), Vect_net_ttb_shortest_path(), Vect_overlay_and(), Vect_read_ascii(), Vect_read_line_to_wkb(), Vect_remove_duplicates(), Vect_remove_small_areas_ext(), Vect_remove_small_areas_nat(), Vect_set_varray_from_cat_list(), Vect_set_varray_from_db(), Vect_snap_line(), Vect_topo_check(), Vect_write_ascii(), Vedit_add_vertex(), Vedit_bulk_labeling(), Vedit_chtype_lines(), Vedit_copy_lines(), Vedit_flip_lines(), Vedit_merge_lines(), Vedit_modify_cats(), Vedit_move_lines(), Vedit_move_vertex(), Vedit_remove_vertex(), Vedit_select_by_query(), Vedit_snap_line(), Vedit_snap_lines(), and Vedit_split_lines().
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 296 of file vector/Vlib/cats.c.
Referenced by Gp_load_sites(), Gv_load_vect(), IL_write_point_2d(), P_Aux_to_Vector(), V1_read_line_ogr(), V1_read_line_pg(), V2_read_line_pg(), V2_read_line_sfa(), V2_read_next_line_ogr(), V2_read_next_line_pg(), Vect__copy_areas(), Vect_clean_small_angles_at_nodes(), Vect_get_area_cat(), Vect_get_area_cats(), Vect_overlay_and(), and Vect_read_ascii().
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 368 of file vector/Vlib/cats.c.
References _, err(), G_debug(), G_malloc, G_realloc, G_warning(), l, max, min, NULL, and strcpy.
Referenced by Vect_cats_set_constraint(), and Vect_set_varray_from_cat_string().