14 #include <grass/vedit.h>
29 int line,
double *x,
double *
y,
double *z,
double thresh,
32 struct line_pnts *Points;
35 int line2snap, mindist_idx;
44 line2snap =
Vect_find_line(Map, *x, *y, *z, -1, thresh, WITHOUT_Z, line);
54 for (i = 0; i < Points->n_points; i++) {
55 if (i > 0 && i < Points->n_points - 1)
59 Points->x[i], Points->y[i],
60 Points->z[i], WITHOUT_Z);
62 if (mindist >= dist) {
68 if (mindist_idx > -1) {
69 *x = Points->x[mindist_idx];
70 *y = Points->y[mindist_idx];
71 *z = Points->z[mindist_idx];
76 G_debug(3,
"Vedit_snap_point(): map=%s, line2snap=%d, snapped=%d",
77 Map->name, line2snap, snapped);
100 int nbgmaps,
int line,
struct line_pnts *Points,
101 double thresh,
int to_vertex)
103 int i, npoints, node, rewrite;
106 struct line_cats *Cats;
110 G_debug(3,
"Vedit_snap_line(): thresh=%g, to_vertex=%d", thresh,
116 npoints = Points->n_points;
122 for (node = 0; node < npoints; node++) {
123 if ((node > 0 && node < npoints - 1) && !to_vertex)
132 for (i = 0; i < nbgmaps; i++) {
134 (BgMap[i], -1, &x[node], &y[node], &z[node], thresh,
146 x[npoints - 1], y[npoints - 1], z[npoints - 1],
147 WITHOUT_Z) <= thresh) {
148 x[npoints - 1] = x[0];
149 y[npoints - 1] = y[0];
150 z[npoints - 1] = z[0];
155 G_debug(3,
"Vedit_snap_line(): line=%d, snapped=%d", line, rewrite);
176 int nbgmaps,
struct ilist *List,
double thresh,
180 int nlines_modified = 0;
182 struct line_pnts *Points;
183 struct line_cats *Cats;
188 for (i = 0; i < List->n_values; i++) {
189 line = List->value[i];
192 if (!(type & (GV_POINT |
GV_LINES))) {
197 line, Points, thresh, to_vertex) == 1) {
209 return nlines_modified;
int Vedit_snap_lines(struct Map_info *Map, struct Map_info **BgMap, int nbgmaps, struct ilist *List, double thresh, int to_vertex)
Snap lines/boundaries.
struct line_pnts * Vect_new_line_struct()
Creates and initializes a struct line_pnts.
int Vedit_snap_line(struct Map_info *Map, struct Map_info **BgMap, int nbgmaps, int line, struct line_pnts *Points, double thresh, int to_vertex)
Snap selected primitive to its nearest primitive.
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.
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.
int G_debug(int level, const char *msg,...)
Print debugging message.
double Vect_points_distance(double x1, double y1, double z1, double x2, double y2, double z2, int with_z)
Calculate distance of 2 points.
int Vect_find_line(struct Map_info *map, double ux, double uy, double uz, int type, double maxdist, int with_z, int exclude)
Find the nearest line.
int Vect_destroy_line_struct(struct line_pnts *p)
Frees all memory associated with a struct line_pnts, including the struct itself. ...
int Vect_read_line(struct Map_info *Map, struct line_pnts *line_p, struct line_cats *line_c, int line)
Read vector feature.