15 #include <grass/vedit.h>
17 static int connect_lines(
struct Map_info *,
int,
int,
int,
18 double,
struct ilist *);
32 struct line_pnts *coord,
double thresh,
33 struct ilist *List_updated)
36 int type, line, seg, newline;
38 double px, py, spdist, lpdist, dist;
41 struct line_pnts *Points, *Points2;
42 struct line_cats *Cats;
43 struct ilist *List_in_box;
52 for (i = 0; i < List->n_values; i++) {
53 line = List->value[i];
67 for (j = 0; j < coord->n_points; j++) {
70 coord->z[j], WITHOUT_Z, &px, &py,
NULL,
71 &dist, &spdist, &lpdist);
77 G_debug(3,
"Vedit_split_lines(): line=%d, x=%f, y=%f, px=%f, py=%f, seg=%d, "
78 "dist=%f, spdist=%f, lpdist=%f", line, coord->x[j],
79 coord->y[j], px, py, seg, dist, spdist, lpdist);
84 G_debug(3,
"Vedit_split_lines(): line=%d", line);
88 for (l = 0; l < seg; l++) {
111 for (l = seg; l < Points->n_points; l++) {
132 return nlines_modified;
158 int nlines_modified, connected;
159 int i, j, node[2], n_nodes;
163 struct ilist *List_exclude, *List_found;
173 for (i = 0; i < List->n_values; i++) {
174 line = List->value[i];
179 node[0] = node[1] = -1;
181 if (node[0] < 0 || node[1] < 0)
187 for (j = 0; j < n_nodes && !connected; j++) {
195 List_exclude, List_found);
199 G_debug(3,
"Vedit_connect_lines(): lines=%d,%d", line, found);
200 if (connect_lines(Map, !j, line, found, thresh, List)) {
201 G_debug(3,
"Vedit_connect_lines(): lines=%d,%d -> connected",
203 nlines_modified += 2;
209 }
while(List_found->n_values > 0 && !connected);
216 return nlines_modified;
219 int connect_lines(
struct Map_info *
Map,
int first,
int line_from,
int line_to,
220 double thresh,
struct ilist *List)
223 int type_from, type_to;
224 int n_points, seg, is;
225 double x,
y, px, py, x1, y1;
226 double dist, spdist, lpdist, length, dist_p;
227 double angle_t, angle_f, angle;
229 struct line_pnts *Points_from, *Points_to, *Points_final;
230 struct line_cats *Cats_from, *Cats_to;
238 type_from =
Vect_read_line(Map, Points_from, Cats_from, line_from);
242 if (!(type_from &
GV_LINES) || !(type_to & GV_LINES))
247 x = Points_from->x[0];
248 y = Points_from->y[0];
251 n_points = Points_from->n_points - 1;
252 x = Points_from->x[n_points];
253 y = Points_from->y[n_points];
256 &px, &py,
NULL, &dist, &spdist, &lpdist);
258 if (seg > 0 && dist > 0.0 && (thresh < 0. || dist <= thresh)) {
270 angle = angle_t - angle_f;
271 dist_p = fabs(dist / sin(angle));
280 x1 = x + dist_p * cos(angle_f);
281 y1 = y + dist_p * sin(angle_f);
289 Points_from->x[0] = x1;
290 Points_from->y[0] = y1;
293 Points_from->x[n_points] = x1;
294 Points_from->y[n_points] = y1;
298 Points_from, Cats_from);
303 for (is = 0; is < seg; is++) {
310 Points_final, Cats_to);
316 for (is = seg; is < Points_to->n_points; is++) {
324 Points_final, Cats_to);
338 return line_new > 0 ? 1 : 0;
int Vect_destroy_list(struct ilist *list)
Frees all memory associated with a struct ilist, including the struct itself.
int Vect_get_line_nodes(struct Map_info *Map, int line, int *n1, int *n2)
Get line nodes.
struct line_pnts * Vect_new_line_struct()
Creates and initializes a struct line_pnts.
struct ilist * Vect_new_list(void)
Creates and initializes a struct ilist.
int Vect_find_line_list(struct Map_info *map, double ux, double uy, double uz, int type, double maxdist, int with_z, struct ilist *exclude, struct ilist *found)
Find the nearest line(s).
int Vect_reset_line(struct line_pnts *Points)
Reset line.
int Vect_append_point(struct line_pnts *Points, double x, double y, double z)
Appends one point to the end of a line.
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_point_on_line(struct line_pnts *Points, double distance, double *x, double *y, double *z, double *angle, double *slope)
Find point on line in the specified distance.
int Vect_reset_list(struct ilist *list)
Reset ilist structure.
int Vect_destroy_cats_struct(struct line_cats *p)
Frees all memory associated with line_cats structure, including the struct itself.
int Vect_list_append(struct ilist *list, int val)
Append new item to the end of list if not yet present.
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.
double Vect_line_length(struct line_pnts *Points)
Calculate line length, 3D-length in case of 3D vector line.
int G_debug(int level, const char *msg,...)
Print debugging message.
int Vedit_connect_lines(struct Map_info *Map, struct ilist *List, double thresh)
Connect lines in given threshold.
long Vect_write_line(struct Map_info *Map, int type, struct line_pnts *points, struct line_cats *cats)
Writes new feature to the end of file (table)
int Vect_get_node_coor(struct Map_info *map, int num, double *x, double *y, double *z)
Get node coordinates.
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 Vedit_split_lines(struct Map_info *Map, struct ilist *List, struct line_pnts *coord, double thresh, struct ilist *List_updated)
Split selected lines on given position.
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.