GRASS Programmer's Manual  6.5.svn(2014)-r66266
 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 }
struct line_pnts * Vect_new_line_struct()
Creates and initializes a struct line_pnts.
Definition: line.c:57
int y
Definition: plot.c:34
int Vedit_move_lines(struct Map_info *Map, struct Map_info **BgMap, int nbgmaps, struct ilist *List, double move_x, double move_y, double move_z, int snap, double thresh)
Move selected primitives.
Definition: move.c:29
int Vect_is_3d(struct Map_info *Map)
Check if vector map is 3D (with z)
int Vedit_snap_point(struct Map_info *Map, int line, double *x, double *y, double *z, double thresh, int vertex)
Snap given point to the nearest primitive.
Definition: vedit/snap.c:28
int Vect_rewrite_line(struct Map_info *Map, int line, int type, struct line_pnts *points, struct line_cats *cats)
Rewrites feature info at the given offset.
int Vect_destroy_cats_struct(struct line_cats *p)
Frees all memory associated with line_cats structure, including the struct itself.
int Vect_line_alive(struct Map_info *Map, int line)
Check if feature is alive or dead.
struct line_cats * Vect_new_cats_struct()
Creates and initializes line_cats structure.
tuple Map
Definition: render.py:1310
int G_debug(int level, const char *msg,...)
Print debugging message.
Definition: gis/debug.c:51
int Vect_destroy_line_struct(struct line_pnts *p)
Frees all memory associated with a struct line_pnts, including the struct itself. ...
Definition: line.c:90
int Vect_read_line(struct Map_info *Map, struct line_pnts *line_p, struct line_cats *line_c, int line)
Read vector feature.