GRASS Programmer's Manual  6.4.3(2013)-r
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Macros Pages
vector/vedit/cats.c
Go to the documentation of this file.
1 
15 #include <grass/glocale.h>
16 #include <grass/vedit.h>
17 
30 int Vedit_modify_cats(struct Map_info *Map, struct ilist *List,
31  int layer, int del, struct cat_list *Clist)
32 {
33  int i, j;
34  struct line_cats *Cats;
35  struct line_pnts *Points;
36  int line, type, cat;
37  int nlines_modified, rewrite;
38 
39  /* features defined by cats */
40  if (Clist->n_ranges <= 0) {
41  return 0;
42  }
43 
44  nlines_modified = 0;
45 
46  Cats = Vect_new_cats_struct();
47  Points = Vect_new_line_struct();
48 
49  /* for each line, set new category */
50  for (i = 0; i < List->n_values; i++) {
51  line = List->value[i];
52  type = Vect_read_line(Map, Points, Cats, line);
53 
54  if (!Vect_line_alive(Map, line))
55  continue;
56 
57  rewrite = 0;
58  for (j = 0; j < Clist->n_ranges; j++) {
59  for (cat = Clist->min[j]; cat <= Clist->max[j]; cat++) {
60  /* add new category */
61  if (!del) {
62  if (Vect_cat_set(Cats, layer, cat) < 1) {
63  G_warning(_("Unable to set category %d for (feature id %d)"),
64  cat, line);
65  }
66  else {
67  rewrite = 1;
68  }
69  }
70  else { /* delete old category */
71  if (Vect_field_cat_del(Cats, layer, cat) == 1) {
72  rewrite = 1;
73  }
74  }
75  }
76  }
77 
78  if (rewrite == 0)
79  continue;
80 
81  if (Vect_rewrite_line(Map, line, type, Points, Cats) < 0) {
82  return -1;
83  }
84 
85  nlines_modified++;
86 
87  }
88 
89  /* destroy structures */
92 
93  return nlines_modified;
94 }