GRASS 8 Programmer's Manual  8.5.0dev(2025)-c070206eb1
vector/vedit/move.c
Go to the documentation of this file.
1 /*!
2  \file lib/vector/vedit/move.c
3 
4  \brief Vedit library - move primitives
5 
6  (C) 2007-2008 by the GRASS Development Team
7 
8  This program is free software under the GNU General Public License
9  (>=v2). Read the file COPYING that comes with GRASS for details.
10 
11  \author Martin Landa <landa.martin gmail.com>
12  \author Jachym Cepicky <jachym.cepicky gmail.com>
13  */
14 
15 #include <grass/vedit.h>
16 
17 /*!
18  \brief Move selected primitives
19 
20  \param Map pointer to Map_info
21  \param BgMap list of background vector maps used for snapping
22  \param nbgmaps Number of background vector maps in BgMap
23  \param List list of primitives to be moved
24  \param move_x,move_y,move_z direction (move_z used only if map is 3D)
25  \param snap enable snapping (see globals.h)
26  \param thresh snapping threshold (>0)
27 
28  \return number of modified primitives
29  \return -1 on error
30  */
31 int Vedit_move_lines(struct Map_info *Map, struct Map_info **BgMap, int nbgmaps,
32  struct ilist *List, double move_x, double move_y,
33  double move_z, int snap, double thresh)
34 {
35  struct line_pnts *Points;
36  struct line_cats *Cats;
37  int i, j;
38  int type, newline, line;
39  int nlines_moved;
40  double *x, *y, *z;
41 
42  nlines_moved = 0;
43 
44  Points = Vect_new_line_struct();
45  Cats = Vect_new_cats_struct();
46 
47  for (i = 0; i < List->n_values; i++) {
48  line = List->value[i];
49 
50  if (!Vect_line_alive(Map, line))
51  continue;
52 
53  type = Vect_read_line(Map, Points, Cats, line);
54 
55  G_debug(3, "Vedit_move_lines(): type=%d, line=%d", type, line);
56 
57  x = Points->x;
58  y = Points->y;
59  z = Points->z;
60 
61  /* move */
62  for (j = 0; j < Points->n_points; j++) {
63  x[j] += move_x;
64  y[j] += move_y;
65  if (Vect_is_3d(Map))
66  z[j] += move_z;
67 
68  if (snap != NO_SNAP) {
69  if (Vedit_snap_point(Map, line, &x[j], &y[j], &z[j], thresh,
70  (snap == SNAPVERTEX) ? 1 : 0) == 0) {
71  /* check also background maps */
72  int bgi;
73 
74  for (bgi = 0; bgi < nbgmaps; bgi++) {
75  if (Vedit_snap_point(BgMap[bgi], -1, &x[j], &y[j],
76  &z[j], thresh,
77  (snap == SNAPVERTEX) ? 1 : 0))
78  break; /* snapped, don't continue */
79  }
80  }
81  }
82  } /* for each point at line */
83 
84  newline = Vect_rewrite_line(Map, line, type, Points, Cats);
85 
86  if (newline < 0) {
87  return -1;
88  }
89 
90  nlines_moved++;
91  }
92 
95 
96  return nlines_moved;
97 }
int G_debug(int, const char *,...) __attribute__((format(printf
void Vect_destroy_line_struct(struct line_pnts *)
Frees all memory associated with a line_pnts structure, including the structure itself.
Definition: line.c:77
off_t Vect_rewrite_line(struct Map_info *, off_t, int, const struct line_pnts *, const struct line_cats *)
Rewrites existing feature (topological level required)
void Vect_destroy_cats_struct(struct line_cats *)
Frees all memory associated with line_cats structure, including the struct itself.
int Vect_read_line(struct Map_info *, struct line_pnts *, struct line_cats *, int)
Read vector feature (topological level required)
int Vect_line_alive(struct Map_info *, int)
Check if feature is alive or dead (topological level required)
struct line_pnts * Vect_new_line_struct(void)
Creates and initializes a line_pnts structure.
Definition: line.c:45
struct line_cats * Vect_new_cats_struct(void)
Creates and initializes line_cats structure.
int Vect_is_3d(struct Map_info *)
Check if vector map is 3D.
int Vedit_snap_point(struct Map_info *, int, double *, double *, double *, double, int)
Snap given point to the nearest primitive.
Definition: vedit/snap.c:28
Vector map info.
Definition: dig_structs.h:1243
List of integers.
Definition: gis.h:715
int n_values
Number of values in the list.
Definition: gis.h:723
int * value
Array of values.
Definition: gis.h:719
Feature category info.
Definition: dig_structs.h:1677
Feature geometry info - coordinates.
Definition: dig_structs.h:1651
double * y
Array of Y coordinates.
Definition: dig_structs.h:1659
double * x
Array of X coordinates.
Definition: dig_structs.h:1655
int n_points
Number of points.
Definition: dig_structs.h:1667
double * z
Array of Z coordinates.
Definition: dig_structs.h:1663
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.
#define NO_SNAP
Definition: vedit.h:7
#define SNAPVERTEX
Definition: vedit.h:9
#define x