18 #include <grass/config.h>
21 #include <grass/gis.h>
22 #include <grass/Vect.h>
23 #include <grass/glocale.h>
29 static int compare_cats(
struct line_cats *ACats,
struct line_cats *BCats)
33 if (ACats->n_cats == 0 || BCats->n_cats == 0) {
34 if (ACats->n_cats == 0 && BCats->n_cats == 0)
37 if (ACats->n_cats == 0 && BCats->n_cats > 0)
40 if (ACats->n_cats > 0 && BCats->n_cats == 0)
44 for (i = 0; i < ACats->n_cats; i++) {
47 for (j = 0; j < BCats->n_cats; j++) {
48 if (ACats->cat[i] == BCats->cat[j] &&
49 ACats->field[i] == BCats->field[j]) {
83 int line, nlines, i,
first, last, next_line, curr_line;
84 int merged = 0, newl = 0;
85 int next_node, direction, node_n_lines, ltype, lines_type;
86 struct Plus_head *Plus;
88 struct line_pnts *MPoints, *Points;
89 struct line_cats *MCats, *Cats;
94 (
"Merging is done with lines or boundaries only, not with other types");
107 for (line = 1; line <= nlines; line++) {
113 Line = Plus->Line[line];
129 next_node = Line->N1;
136 for (i = 0; i < node_n_lines; i++) {
138 if ((Plus->Line[abs(curr_line)]->type & GV_LINES))
140 if ((Plus->Line[abs(curr_line)]->type == ltype)) {
141 if (abs(curr_line) != abs(first)) {
145 if (compare_cats(MCats, Cats) == 0)
146 next_line = curr_line;
150 if (lines_type == 2 && abs(next_line) != abs(first) &&
151 abs(next_line) != line) {
155 next_node = Plus->Line[-
first]->N1;
157 next_node = Plus->Line[
first]->N2;
170 next_node = Plus->Line[-last]->N1;
172 next_node = Plus->Line[last]->N2;
180 for (i = 0; i < node_n_lines; i++) {
182 if ((Plus->Line[abs(curr_line)]->type & GV_LINES))
184 if ((Plus->Line[abs(curr_line)]->type == ltype)) {
185 if (abs(curr_line) != abs(last)) {
188 if (compare_cats(MCats, Cats) == 0)
189 next_line = curr_line;
194 if (lines_type == 2 && abs(next_line) != abs(last) &&
195 abs(next_line) != abs(first)) {
199 next_node = Plus->Line[-last]->N1;
201 next_node = Plus->Line[last]->N2;
208 if (List->n_values > 1) {
209 G_debug(3,
"merge %d lines", List->n_values);
212 for (i = 0; i < List->n_values; i++) {
215 direction = (List->value[i] < 0 ? GV_BACKWARD : GV_FORWARD);
226 merged += List->n_values;