15 #include <grass/vedit.h>
32 static int merge_lines(
struct line_pnts *Points1,
struct line_cats *Cats1,
33 struct line_pnts *Points2,
struct line_cats *
Cats2,
34 double thresh,
struct line_pnts **Points);
49 struct ilist *List_in_box;
51 struct line_pnts *Points1, *Points2, *Points;
52 struct line_cats *Cats1, *
Cats2;
55 int line, line1, type1, line2, type2;
59 int nlines, nlines_selected, nlines_merged;
63 if (List->n_values < 2) {
76 nlines_selected = List->n_values;
79 for (line_i = 0; line_i < List->n_values; line_i++) {
80 line1 = List->value[line_i];
92 for (i = 0; i < Points1->n_points; i += Points1->n_points - 1) {
108 Points1->y[i], Points1->z[i]);
115 GV_LINES, List_in_box)) {
118 for (j = 0; do_merge && j < List->n_values; j++) {
119 if (List->value[j] == line1 ||
131 line2 = List->value[j];
136 if (!do_merge || line2 < 0)
141 merge_lines(Points1, Cats1, Points2, Cats2, -1.0, &Points);
143 G_debug(3,
"Vedit_merge_lines(): lines=%d,%d", line1, line2);
145 if (Points->n_points > 0) {
156 if (Points->n_points > 0) {
178 return nlines_merged;
181 static int merge_lines(
struct line_pnts *Points1,
struct line_cats *Cats1,
182 struct line_pnts *Points2,
struct line_cats *
Cats2,
183 double thresh,
struct line_pnts **Points)
185 struct line_pnts *ps = *Points;
186 struct line_cats *cs = Cats1;
195 G_debug(3,
" merge line ? index: %d, mindist: %g, thresh: %g",
196 mindistidx, mindist, thresh);
198 if (thresh > 0 && mindist > thresh) {
203 switch (mindistidx) {
207 if (ps->n_points == Points2->n_points)
212 if (ps->n_points == Points2->n_points)
216 if (ps->n_points == 0)
221 if (ps->n_points == 0)
233 for (i = 0; i < Cats2->n_cats; i++) {
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_append_points(struct line_pnts *Points, struct line_pnts *APoints, int direction)
Appends points to the end of a line.
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_cat_set(struct line_cats *Cats, int field, int cat)
Add new field/cat to category structure if doesn't exist yet.
int Vedit_merge_lines(struct Map_info *Map, struct ilist *List)
Merge lines/boundaries.
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_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_select_lines_by_polygon(struct Map_info *Map, struct line_pnts *Polygon, int nisles, struct line_pnts **Isles, int type, struct ilist *List)
Select lines by Polygon with optional isles.
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 Vect_get_num_lines(struct Map_info *map)
Fetch number of features (points, lines, boundaries, centroids) in vector map.
double Vedit_get_min_distance(struct line_pnts *Points1, struct line_pnts *Points2, int with_z, int *mindistidx)
Calculate distances between two lines.
int G_debug(int level, const char *msg,...)
Print debugging message.
int Vect_delete_line(struct Map_info *Map, int line)
Delete feature.
int Vect_val_in_list(struct ilist *list, int val)
Find a given item in the list.
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.