21 #include <grass/gis.h>
22 #include <grass/Vect.h>
23 #include <grass/glocale.h>
25 #define REMOVE_DANGLE 0
26 #define CHTYPE_DANGLE 1
27 #define SELECT_DANGLE 2
29 static void dangles(
struct Map_info *,
int,
int,
double,
30 struct Map_info *,
struct ilist *);
128 static void dangles(
struct Map_info *
Map,
int type,
int option,
129 double maxlength,
struct Map_info *Err,
130 struct ilist *List_dangle)
132 struct line_pnts *Points;
133 struct line_cats *Cats;
134 int i, line, ltype, next_line = 0, nnodelines;
135 int nnodes, node, node1, node2, next_node;
136 int lcount, tmp_next_line = 0;
143 next_line = tmp_next_line = 0;
151 lmsg =
"changed lines";
154 lmsg =
"removed lines";
157 lmsg =
"selected lines";
168 G_debug(2,
"nnodes = %d", nnodes);
170 for (node = 1; node <= nnodes; node++) {
179 for (i = 0; i < nnodelines; i++) {
181 G_debug(3,
" node line %d = %d", i, line);
193 G_debug(3,
" node %d is dangle -> follow the line %d", node,
196 while (next_line != 0) {
201 next_node = next_line > 0 ? node2 : node1;
203 G_debug(3,
" next_node = %d", next_node);
208 for (i = 0; i < nnodelines; i++) {
210 G_debug(3,
" node line %d = %d", i, line);
214 if (ltype & type && abs(line) != abs(next_line)) {
216 tmp_next_line = line;
220 next_line = tmp_next_line;
228 for (i = 0; i < List->n_values; i++) {
229 G_debug(3,
" chain line %d = %d", i, List->value[i]);
234 if (maxlength < 0 || length < maxlength) {
235 G_debug(3,
" delete the chain (length=%g)", length);
237 for (i = 0; i < List->n_values; i++) {
249 G_debug(3,
" rewrite line %d", List->value[i]);
int Vect_get_node_line(struct Map_info *Map, int node, int line)
Get line id for node line index.
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_node_alive(struct Map_info *Map, int node)
Check if node is alive or dead.
void Vect_remove_dangles(struct Map_info *Map, int type, double maxlength, struct Map_info *Err)
Remove dangles from vector map.
void Vect_select_dangles(struct Map_info *Map, int type, double maxlength, struct ilist *List)
Select dangles from vector map.
int G_percent(long n, long d, int s)
Print percent complete messages.
void Vect_chtype_dangles(struct Map_info *Map, double maxlength, struct Map_info *Err)
Change boundary dangles to lines.
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_list_append(struct ilist *list, int val)
Append new item to the end of list if not yet present.
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 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_get_num_nodes(struct Map_info *map)
Get number of nodes in vector map.
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.