GRASS Programmer's Manual
6.4.2(2012)
|
00001 00015 #include <grass/glocale.h> 00016 #include <grass/vedit.h> 00017 00030 int Vedit_modify_cats(struct Map_info *Map, struct ilist *List, 00031 int layer, int del, struct cat_list *Clist) 00032 { 00033 int i, j; 00034 struct line_cats *Cats; 00035 struct line_pnts *Points; 00036 int line, type, cat; 00037 int nlines_modified, rewrite; 00038 00039 /* features defined by cats */ 00040 if (Clist->n_ranges <= 0) { 00041 return 0; 00042 } 00043 00044 nlines_modified = 0; 00045 00046 Cats = Vect_new_cats_struct(); 00047 Points = Vect_new_line_struct(); 00048 00049 /* for each line, set new category */ 00050 for (i = 0; i < List->n_values; i++) { 00051 line = List->value[i]; 00052 type = Vect_read_line(Map, Points, Cats, line); 00053 00054 if (!Vect_line_alive(Map, line)) 00055 continue; 00056 00057 rewrite = 0; 00058 for (j = 0; j < Clist->n_ranges; j++) { 00059 for (cat = Clist->min[j]; cat <= Clist->max[j]; cat++) { 00060 /* add new category */ 00061 if (!del) { 00062 if (Vect_cat_set(Cats, layer, cat) < 1) { 00063 G_warning(_("Unable to set category %d for (feature id %d)"), 00064 cat, line); 00065 } 00066 else { 00067 rewrite = 1; 00068 } 00069 } 00070 else { /* delete old category */ 00071 if (Vect_field_cat_del(Cats, layer, cat) == 1) { 00072 rewrite = 1; 00073 } 00074 } 00075 } 00076 } 00077 00078 if (rewrite == 0) 00079 continue; 00080 00081 if (Vect_rewrite_line(Map, line, type, Points, Cats) < 0) { 00082 return -1; 00083 } 00084 00085 nlines_modified++; 00086 00087 } 00088 00089 /* destroy structures */ 00090 Vect_destroy_line_struct(Points); 00091 Vect_destroy_cats_struct(Cats); 00092 00093 return nlines_modified; 00094 }