15 #include <grass/vedit.h>
34 int nbgmaps,
struct ilist *List,
35 struct line_pnts *coord,
double thresh_coords,
36 double thresh_snap,
double move_x,
double move_y,
37 double move_z,
int move_first,
int snap)
39 int nvertices_moved, nlines_modified, nvertices_snapped;
42 int line,
type, rewrite;
44 double east, north, dist;
48 struct line_pnts *Points, *Points_snap;
49 struct line_cats *Cats;
52 nvertices_moved = nvertices_snapped = 0;
59 for (i = 0; i < List->n_values; i++) {
60 line = List->value[i];
70 npoints = Points->n_points;
81 (
char *)G_realloc((
void *)moved, Points->n_points *
sizeof(char));
82 G_zero((
void *)moved, Points->n_points *
sizeof(
char));
85 for (j = 0; j < coord->n_points; j++) {
90 for (k = 0; k < Points->n_points; k++) {
93 x[k], y[k], z[k], WITHOUT_Z);
94 if (dist <= thresh_coords) {
96 "Vedit_move_vertex(): line=%d; x=%f, y=%f -> x=%f, y=%f",
97 line, x[k], y[k], x[k] + move_x,
106 G_debug(3,
"Vedit_move_vertex(): line=%d, point=%d",
109 if (snap != NO_SNAP) {
111 (Map, line, &x[k], &y[k], &z[k], thresh_snap,
112 (snap == SNAPVERTEX) ? 1 : 0) == 0) {
116 for (bgi = 0; bgi < nbgmaps; bgi++) {
118 (BgMap[bgi], line, &x[k], &y[k],
120 (snap == SNAPVERTEX) ? 1 : 0))
140 if ((type & GV_LINES) &&
142 x[npoints - 1], y[npoints - 1],
144 WITHOUT_Z) <= thresh_snap) {
147 x[0] = x[npoints - 1];
148 y[0] = y[npoints - 1];
150 z[0] = z[npoints - 1];
152 else if (moved[npoints - 1] == 1) {
153 x[npoints - 1] = x[0];
154 y[npoints - 1] = y[0];
156 z[npoints - 1] = z[0];
176 return nvertices_moved;
195 struct line_pnts *coord,
double thresh)
199 int nlines_modified, nvertices_added, rewrite;
200 double east, north, dist;
204 struct line_pnts *Points;
205 struct line_cats *Cats;
212 for (i = 0; i < List->n_values; i++) {
213 line = List->value[i];
227 for (j = 0; j < coord->n_points; j++) {
232 WITHOUT_Z, &px, &py,
NULL,
236 if (dist <= thresh &&
240 z[seg - 1], WITHOUT_Z) > 0) {
244 "Vedit_add_vertex(): line=%d; x=%f, y=%f, index=%d",
266 return nvertices_added;
283 struct line_pnts *coord,
double thresh)
287 int nvertices_removed, rewrite, nlines_modified;
292 struct line_pnts *Points;
293 struct line_cats *Cats;
295 nvertices_removed = nlines_modified = 0;
300 for (i = 0; i < List->n_values; i++) {
301 line = List->value[i];
315 for (j = 0; j < coord->n_points; j++) {
319 for (k = 0; k < Points->n_points; k++) {
321 x[k], y[k], z[k], WITHOUT_Z);
322 if (dist <= thresh) {
326 "Vedit_remove_vertex(): line=%d; x=%f, y=%f, index=%d",
327 line, x[k], y[k], k);
349 return nvertices_removed;
struct line_pnts * Vect_new_line_struct()
Creates and initializes a struct line_pnts.
int Vedit_remove_vertex(struct Map_info *Map, struct ilist *List, struct line_pnts *coord, double thresh)
Remove vertex from line.
int G_zero(void *buf, int i)
Zero out a buffer, buf, of length i.
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_line_insert_point(struct line_pnts *Points, int index, double x, double y, double z)
Insert new point at index position and move all old points at that position and above up...
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 Vect_line_prune(struct line_pnts *Points)
Remove duplicate points, i.e. zero length segments.
int Vedit_add_vertex(struct Map_info *Map, struct ilist *List, struct line_pnts *coord, double thresh)
Add new vertex to line.
int G_debug(int level, const char *msg,...)
Print debugging message.
int Vedit_move_vertex(struct Map_info *Map, struct Map_info **BgMap, int nbgmaps, struct ilist *List, struct line_pnts *coord, double thresh_coords, double thresh_snap, double move_x, double move_y, double move_z, int move_first, int snap)
Move all vertices in bounding box(es)
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_line_delete_point(struct line_pnts *Points, int index)
Delete point at given index and move all points above down.
int Vect_line_distance(struct line_pnts *points, double ux, double uy, double uz, int with_z, double *px, double *py, double *pz, double *dist, double *spdist, double *lpdist)
calculate line distance.
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.