16 #include <grass/glocale.h>
17 #include <grass/vedit.h>
19 static int select_by_query(
struct Map_info *,
int,
int,
double,
20 int,
struct line_pnts *,
struct line_cats *);
22 static int merge_lists(
struct ilist *alist,
struct ilist *blist);
44 int type,
int layer,
double thresh,
int query,
49 struct line_pnts *Points;
50 struct line_cats *Cats;
51 struct ilist *List_query;
56 if (List->n_values == 0) {
65 if (List->n_values == 0) {
68 for (line = 1; line <=
num; line++) {
69 if (select_by_query(Map, line, type, thresh,
75 for (i = 0; i < List->n_values; i++) {
76 line = List->value[i];
77 if (select_by_query(Map, line, type, thresh,
78 query, Points, Cats)) {
86 struct ilist *List_dangle;
89 thresh_tmp = fabs(thresh);
95 for (i = 0; i < List_dangle->n_values; i++) {
113 if (List != List_query) {
114 merge_lists(List, List_query);
118 G_debug(3,
"Vedit_select_by_query(): %d lines selected (by query %d)",
119 List->n_values, query);
124 return List->n_values;
134 int select_by_query(
struct Map_info *
Map,
int line,
int type,
double thresh,
135 int query,
struct line_pnts *Points,
136 struct line_cats *Cats)
141 int node1, node2, node;
144 struct ilist *exclude, *found;
145 struct line_cats *Cats_curr;
155 if (query == QUERY_LENGTH) {
158 if (length <= fabs(thresh))
166 else if (query == QUERY_DANGLE) {
185 if ((nnode1 == 4 && nnode2 == 1) || (nnode1 == 1 && nnode2 == 4)) {
198 if (length > fabs(thresh))
202 if (length <= thresh)
214 GV_LINES, 0.0, WITHOUT_Z, exclude, found);
218 for (i = 0; i < found->n_values; i++) {
232 G_fatal_error(
"Vedit_select_by_query(): %s", _(
"Unknown query tool"));
246 int merge_lists(
struct ilist *alist,
struct ilist *blist)
250 struct ilist *list_del;
254 for (i = 0; i < alist->n_values; i++) {
263 return alist->n_values;
int Vect_destroy_list(struct ilist *list)
Frees all memory associated with a struct ilist, including the struct itself.
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_find_line_list(struct Map_info *map, double ux, double uy, double uz, int type, double maxdist, int with_z, struct ilist *exclude, struct ilist *found)
Find the nearest line(s).
void Vect_select_dangles(struct Map_info *Map, int type, double maxlength, struct ilist *List)
Select dangles from vector map.
int Vedit_select_by_query(struct Map_info *Map, int type, int layer, double thresh, int query, struct ilist *List)
Select primitives by query (based on geometry properties)
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.
double Vect_line_length(struct line_pnts *Points)
Calculate line length, 3D-length in case of 3D vector line.
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_list_delete_list(struct ilist *alist, struct ilist *blist)
Delete list from existing list.
int Vect_val_in_list(struct ilist *list, int val)
Find a given item in the list.
int Vect_get_node_coor(struct Map_info *map, int num, double *x, double *y, double *z)
Get node coordinates.
int G_fatal_error(const char *msg,...)
Print a fatal error message to stderr.
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_cat_get(struct line_cats *Cats, int field, int *cat)
Get first found category of given field.
int Vect_get_node_n_lines(struct Map_info *Map, int node)
Get number of lines for node.