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