GRASS Programmer's Manual
6.4.1(2011)
|
00001 00018 #include <grass/vedit.h> 00019 00032 int Vedit_move_lines(struct Map_info *Map, struct Map_info **BgMap, 00033 int nbgmaps, struct ilist *List, double move_x, 00034 double move_y, double move_z, int snap, double thresh) 00035 { 00036 struct line_pnts *Points; 00037 struct line_cats *Cats; 00038 int i, j; 00039 int type, newline, line; 00040 int nlines_moved; 00041 double *x, *y, *z; 00042 00043 nlines_moved = 0; 00044 00045 Points = Vect_new_line_struct(); 00046 Cats = Vect_new_cats_struct(); 00047 00048 for (i = 0; i < List->n_values; i++) { 00049 line = List->value[i]; 00050 00051 if (!Vect_line_alive(Map, line)) 00052 continue; 00053 00054 type = Vect_read_line(Map, Points, Cats, line); 00055 00056 G_debug(3, "Vedit_move_lines(): type=%d, line=%d", type, line); 00057 00058 x = Points->x; 00059 y = Points->y; 00060 z = Points->z; 00061 00062 /* move */ 00063 for (j = 0; j < Points->n_points; j++) { 00064 x[j] += move_x; 00065 y[j] += move_y; 00066 if (Vect_is_3d(Map)) 00067 z[j] += move_z; 00068 00069 if (snap != NO_SNAP) { 00070 if (Vedit_snap_point(Map, line, &x[j], &y[j], &z[j], thresh, 00071 (snap == SNAPVERTEX) ? 1 : 0) == 0) { 00072 /* check also background maps */ 00073 int bgi; 00074 00075 for (bgi = 0; bgi < nbgmaps; bgi++) { 00076 if (Vedit_snap_point 00077 (BgMap[bgi], line, &x[j], &y[j], &z[j], thresh, 00078 (snap == SNAPVERTEX) ? 1 : 0)) 00079 break; /* snapped, don't continue */ 00080 } 00081 } 00082 } 00083 } /* for each point at line */ 00084 00085 newline = Vect_rewrite_line(Map, line, type, Points, Cats); 00086 00087 if (newline < 0) { 00088 return -1; 00089 } 00090 00091 nlines_moved++; 00092 } 00093 00094 Vect_destroy_line_struct(Points); 00095 Vect_destroy_cats_struct(Cats); 00096 00097 return nlines_moved; 00098 }