17 static int connect_lines(
struct Map_info *,
int,
int,
int,
18 double,
struct ilist *);
34 struct ilist *List_updated)
37 int type, line, seg, newline;
39 double px, py, spdist, lpdist, dist;
44 struct ilist *List_in_box;
53 for (i = 0; i < List->
n_values; i++) {
54 line = List->
value[i];
68 for (j = 0; j < coord->
n_points; j++) {
72 &dist, &spdist, &lpdist);
78 G_debug(3,
"Vedit_split_lines(): line=%d, x=%f, y=%f, px=%f, py=%f, seg=%d, " 79 "dist=%f, spdist=%f, lpdist=%f", line, coord->
x[j],
80 coord->
y[j], px, py, seg, dist, spdist, lpdist);
85 G_debug(3,
"Vedit_split_lines(): line=%d", line);
89 for (l = 0; l < seg; l++) {
112 for (l = seg; l < Points->
n_points; l++) {
133 return nlines_modified;
159 int nlines_modified, connected;
160 int i, j, node[2], n_nodes;
164 struct ilist *List_exclude, *List_found;
174 for (i = 0; i < List->
n_values; i++) {
175 line = List->
value[i];
183 node[0] = node[1] = -1;
185 if (node[0] < 0 || node[1] < 0)
191 for (j = 0; j < n_nodes && !connected; j++) {
199 List_exclude, List_found);
203 G_debug(3,
"Vedit_connect_lines(): lines=%d,%d", line, found);
204 if (connect_lines(Map, !j, line, found, thresh, List)) {
205 G_debug(3,
"Vedit_connect_lines(): lines=%d,%d -> connected",
207 nlines_modified += 2;
213 }
while(List_found->
n_values > 0 && !connected);
220 return nlines_modified;
223 int connect_lines(
struct Map_info *Map,
int first,
int line_from,
int line_to,
224 double thresh,
struct ilist *List)
227 int type_from, type_to;
228 int n_points, seg, is;
229 double x, y, px, py, x1, y1;
230 double dist, spdist, lpdist, length, dist_p;
231 double angle_t, angle_f, angle;
233 struct line_pnts *Points_from, *Points_to, *Points_final;
242 type_from =
Vect_read_line(Map, Points_from, Cats_from, line_from);
246 if (!(type_from &
GV_LINES) || !(type_to & GV_LINES))
250 n_points = Points_from->
n_points - 1;
253 x = Points_from->
x[0];
254 y = Points_from->
y[0];
257 x = Points_from->
x[n_points];
258 y = Points_from->
y[n_points];
261 &px, &py,
NULL, &dist, &spdist, &lpdist);
263 if (seg > 0 && dist > 0.0 && (thresh < 0. || dist <= thresh)) {
275 angle = angle_t - angle_f;
276 dist_p = fabs(dist / sin(angle));
285 x1 = x + dist_p * cos(angle_f);
286 y1 = y + dist_p * sin(angle_f);
294 Points_from->
x[0] = x1;
295 Points_from->
y[0] = y1;
298 Points_from->
x[n_points] = x1;
299 Points_from->
y[n_points] = y1;
303 Points_from, Cats_from);
308 for (is = 0; is < seg; is++) {
315 Points_final, Cats_to);
321 for (is = seg; is < Points_to->
n_points; is++) {
329 Points_final, Cats_to);
343 return line_new > 0 ? 1 : 0;
int Vect_reset_list(struct ilist *)
Reset ilist structure.
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)
int n_points
Number of points.
int n_values
Number of values in the list.
int Vect_line_distance(const struct line_pnts *, double, double, double, int, double *, double *, double *, double *, double *, double *)
Calculate distance of point to line.
double Vect_line_length(const struct line_pnts *)
Calculate line length, 3D-length in case of 3D vector line.
int Vect_get_node_coor(const struct Map_info *, int, double *, double *, double *)
Get node coordinates.
double * x
Array of X coordinates.
Feature geometry info - coordinates.
void Vect_destroy_list(struct ilist *)
Frees all memory associated with a struct ilist, including the struct itself.
struct line_pnts * Vect_new_line_struct(void)
Creates and initializes a line_pnts structure.
void Vect_destroy_cats_struct(struct line_cats *)
Frees all memory associated with line_cats structure, including the struct itself.
off_t Vect_write_line(struct Map_info *, int, const struct line_pnts *, const struct line_cats *)
Writes a new feature.
int Vect_append_point(struct line_pnts *, double, double, double)
Appends one point to the end of a line.
#define WITHOUT_Z
2D/3D vector data
int Vect_get_line_nodes(const struct Map_info *, int, int *, int *)
Get line nodes.
double * y
Array of Y coordinates.
struct ilist * Vect_new_list(void)
Creates and initializes a struct ilist.
struct line_cats * Vect_new_cats_struct(void)
Creates and initializes line_cats structure.
int Vect_list_append(struct ilist *, int)
Append new item to the end of list if not yet present.
int Vedit_connect_lines(struct Map_info *Map, struct ilist *List, double thresh)
Connect lines in given threshold.
int Vect_line_insert_point(struct line_pnts *, int, double, double, double)
Insert new point at index position and move all old points at that position and above up...
int Vect_line_alive(const struct Map_info *, int)
Check if feature is alive or dead (topological level required)
double * z
Array of Z coordinates.
int * value
Array of values.
int Vect_point_on_line(const struct line_pnts *, double, double *, double *, double *, double *, double *)
Find point on line in the specified distance.
int Vect_find_line_list(struct Map_info *, double, double, double, int, double, int, const struct ilist *, struct ilist *)
Find the nearest line(s).
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.
void Vect_destroy_line_struct(struct line_pnts *)
Frees all memory associated with a line_pnts structure, including the structure itself.
int Vect_read_line(const struct Map_info *, struct line_pnts *, struct line_cats *, int)
Read vector feature (topological level required)
int G_debug(int, const char *,...) __attribute__((format(printf
void Vect_reset_line(struct line_pnts *)
Reset line.
int Vect_get_line_type(const struct Map_info *, int)
Get line type.