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;
int Vect_destroy_list(struct ilist *list)
Frees all memory associated with a struct ilist, including the struct itself.
int Vect_get_node_line(struct Map_info *Map, int node, int line)
Get line id for node line index.
int Vect_merge_lines(struct Map_info *Map, int type, int *new_lines, struct Map_info *Err)
Merge lines or boundaries in vector map.
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 G_percent(long n, long d, int s)
Print percent complete messages.
void G_verbose_message(const char *msg,...)
Print a message to stderr but only if module is in verbose mode.
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.
G_warning("category support for [%s] in mapset [%s] %s", name, mapset, type)
int Vect_get_num_lines(struct Map_info *map)
Fetch number of features (points, lines, boundaries, centroids) in vector map.
int G_debug(int level, const char *msg,...)
Print debugging message.
int Vect_delete_line(struct Map_info *Map, int line)
Delete feature.
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_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.
int Vect_get_node_n_lines(struct Map_info *Map, int node)
Get number of lines for node.