GRASS Programmer's Manual  6.4.2(2012)
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Pages
move.c
Go to the documentation of this file.
1 
15 #include <grass/vedit.h>
16 
29 int Vedit_move_lines(struct Map_info *Map, struct Map_info **BgMap,
30  int nbgmaps, struct ilist *List, double move_x,
31  double move_y, double move_z, int snap, double thresh)
32 {
33  struct line_pnts *Points;
34  struct line_cats *Cats;
35  int i, j;
36  int type, newline, line;
37  int nlines_moved;
38  double *x, *y, *z;
39 
40  nlines_moved = 0;
41 
42  Points = Vect_new_line_struct();
43  Cats = Vect_new_cats_struct();
44 
45  for (i = 0; i < List->n_values; i++) {
46  line = List->value[i];
47 
48  if (!Vect_line_alive(Map, line))
49  continue;
50 
51  type = Vect_read_line(Map, Points, Cats, line);
52 
53  G_debug(3, "Vedit_move_lines(): type=%d, line=%d", type, line);
54 
55  x = Points->x;
56  y = Points->y;
57  z = Points->z;
58 
59  /* move */
60  for (j = 0; j < Points->n_points; j++) {
61  x[j] += move_x;
62  y[j] += move_y;
63  if (Vect_is_3d(Map))
64  z[j] += move_z;
65 
66  if (snap != NO_SNAP) {
67  if (Vedit_snap_point(Map, line, &x[j], &y[j], &z[j], thresh,
68  (snap == SNAPVERTEX) ? 1 : 0) == 0) {
69  /* check also background maps */
70  int bgi;
71 
72  for (bgi = 0; bgi < nbgmaps; bgi++) {
74  (BgMap[bgi], line, &x[j], &y[j], &z[j], thresh,
75  (snap == SNAPVERTEX) ? 1 : 0))
76  break; /* snapped, don't continue */
77  }
78  }
79  }
80  } /* for each point at line */
81 
82  newline = Vect_rewrite_line(Map, line, type, Points, Cats);
83 
84  if (newline < 0) {
85  return -1;
86  }
87 
88  nlines_moved++;
89  }
90 
93 
94  return nlines_moved;
95 }