GRASS Programmer's Manual  6.5.svn(2014)-r66266
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator 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 }
int Vedit_modify_cats(struct Map_info *Map, struct ilist *List, int layer, int del, struct cat_list *Clist)
Add / remove categories.
int Vect_field_cat_del(struct line_cats *Cats, int field, int cat)
Delete field/cat from line_cats structure.
struct line_pnts * Vect_new_line_struct()
Creates and initializes a struct line_pnts.
Definition: line.c:57
#define max(x, y)
Definition: draw2.c:69
int Vect_cat_set(struct line_cats *Cats, int field, int cat)
Add new field/cat to category structure if doesn&#39;t exist yet.
int Vect_rewrite_line(struct Map_info *Map, int line, int type, struct line_pnts *points, struct line_cats *cats)
Rewrites feature info at the given offset.
int Vect_destroy_cats_struct(struct line_cats *p)
Frees all memory associated with line_cats structure, including the struct itself.
int Vect_line_alive(struct Map_info *Map, int line)
Check if feature is alive or dead.
struct line_cats * Vect_new_cats_struct()
Creates and initializes line_cats structure.
G_warning("category support for [%s] in mapset [%s] %s", name, mapset, type)
tuple Map
Definition: render.py:1310
CELL cat
Definition: g3dcats.c:90
int Vect_destroy_line_struct(struct line_pnts *p)
Frees all memory associated with a struct line_pnts, including the struct itself. ...
Definition: line.c:90
int Vect_read_line(struct Map_info *Map, struct line_pnts *line_p, struct line_cats *line_c, int line)
Read vector feature.