GRASS 8 Programmer's Manual 8.6.0dev(2026)-1878fdfec5
Loading...
Searching...
No Matches
vector/vedit/cats.c
Go to the documentation of this file.
1/*!
2 \file lib/vector/vedit/cats.c
3
4 \brief Vedit library - category manipulation
5
6 SPDX-FileCopyrightText: 2006-2008 GRASS Development Team
7 SPDX-License-Identifier: GPL-2.0-or-later
8
9 \author Jachym Cepicky <jachym.cepicky gmail.com>
10 \author Martin Landa <landa.martin gmail.com>
11 */
12
13#include <grass/glocale.h>
14#include <grass/vedit.h>
15
16/*!
17 \brief Add / remove categories
18
19 \param Map pointer to Map_info
20 \param List list of selected primitives
21 \param layer layer number
22 \param del action (non-zero for delete otherwise add)
23 \param Clist list of category numbers
24
25 \return number of modified primitives
26 \return -1 on error
27 */
28int Vedit_modify_cats(struct Map_info *Map, struct ilist *List, int layer,
29 int del, struct cat_list *Clist)
30{
31 int i, j;
32 struct line_cats *Cats;
33 struct line_pnts *Points;
34 int line, type, cat;
36
37 /* features defined by cats */
38 if (Clist->n_ranges <= 0) {
39 return 0;
40 }
41
43
45 Points = Vect_new_line_struct();
46
47 /* for each line, set new category */
48 for (i = 0; i < List->n_values; i++) {
49 line = List->value[i];
50 type = Vect_read_line(Map, Points, Cats, line);
51
52 if (!Vect_line_alive(Map, line))
53 continue;
54
55 rewrite = 0;
56 for (j = 0; j < Clist->n_ranges; j++) {
57 for (cat = Clist->min[j]; cat <= Clist->max[j]; cat++) {
58 /* add new category */
59 if (!del) {
60 if (Vect_cat_set(Cats, layer, cat) < 1) {
62 _("Unable to set category %d for (feature id %d)"),
63 cat, line);
64 }
65 else {
66 rewrite = 1;
67 }
68 }
69 else { /* delete old category */
70 if (Vect_field_cat_del(Cats, layer, cat) > 0) {
71 rewrite = 1;
72 }
73 }
74 }
75 }
76
77 if (rewrite == 0)
78 continue;
79
80 if (Vect_rewrite_line(Map, line, type, Points, Cats) < 0) {
81 return -1;
82 }
83
85 }
86
87 /* destroy structures */
90
91 return nlines_modified;
92}
void G_warning(const char *,...) __attribute__((format(printf
void Vect_destroy_line_struct(struct line_pnts *)
Frees all memory associated with a line_pnts structure, including the structure itself.
Definition line.c:75
off_t Vect_rewrite_line(struct Map_info *, off_t, int, const struct line_pnts *, const struct line_cats *)
Rewrites existing feature (topological level required)
int Vect_cat_set(struct line_cats *, int, int)
Add new field/cat to category structure if doesn't exist yet.
void Vect_destroy_cats_struct(struct line_cats *)
Frees all memory associated with line_cats structure, including the struct itself.
int Vect_read_line(struct Map_info *, struct line_pnts *, struct line_cats *, int)
Read vector feature (topological level required)
int Vect_line_alive(struct Map_info *, int)
Check if feature is alive or dead (topological level required)
int Vect_field_cat_del(struct line_cats *, int, int)
Delete field/cat from line_cats structure.
struct line_cats * Vect_new_cats_struct(void)
Creates and initializes line_cats structure.
struct line_pnts * Vect_new_line_struct(void)
Creates and initializes a line_pnts structure.
Definition line.c:43
#define _(str)
Definition glocale.h:10
Vector map info.
Category list.
List of integers.
Definition gis.h:712
Feature category info.
Feature geometry info - coordinates.
int Vedit_modify_cats(struct Map_info *Map, struct ilist *List, int layer, int del, struct cat_list *Clist)
Add / remove categories.