GRASS GIS 8 Programmer's Manual  8.5.0dev(2024)-38f5cf43d1
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, nbgmaps list of background vector maps used for snapping
22  \param List list of primitives to be moved
23  \param move_x,move_y,move_z direction (move_z used only if map is 3D)
24  \param snap enable snapping (see globals.h)
25 
26  \return number of modified primitives
27  \return -1 on error
28  */
29 int Vedit_move_lines(struct Map_info *Map, struct Map_info **BgMap, int nbgmaps,
30  struct ilist *List, double move_x, double move_y,
31  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++) {
73  if (Vedit_snap_point(BgMap[bgi], -1, &x[j], &y[j],
74  &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 }
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:709
int n_values
Number of values in the list.
Definition: gis.h:717
int * value
Array of values.
Definition: gis.h:713
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