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