17 #include <grass/vector.h> 18 #include <grass/glocale.h> 20 static int cmp_int(
const void *a,
const void *
b)
22 return (*(
int *)a - *(
int *)b);
25 static int boxlist_add_sorted(
struct boxlist *
list,
int id)
30 if (bsearch(&
id, list->
id, list->
n_values,
sizeof(
int), cmp_int))
35 size_t size = (list->
n_values + 100) *
sizeof(
int);
37 list->
id = (
int *)G_realloc((
void *)list->
id, size);
43 for (i = list->
n_values; i > 0; i--) {
44 if (list->
id[i - 1] <
id)
46 list->
id[i] = list->
id[i - 1];
73 int i, c, atype, btype, aline, bline;
74 int nlines, nacats_orig, npoints;
75 int na1, na2, nb1, nb2, nodelines, nline;
89 G_debug(1,
"nlines = %d", nlines);
99 for (aline = 1; aline <= nlines; aline++) {
112 G_debug(3,
"Line %d pruned, %d vertices removed", aline, npoints - APoints->
n_points);
125 for (i = 0; i < nodelines; i++) {
133 boxlist_add_sorted(List, nline);
138 ABox.
E = ABox.
W = APoints->
x[0];
139 ABox.
N = ABox.
S = APoints->
y[0];
140 ABox.
T = ABox.
B = APoints->
z[0];
147 for (i = 0; i < List->
n_values; i++) {
149 G_debug(3,
" j = %d bline = %d", i, bline);
157 if (atype & GV_LINES) {
159 if ((na1 == nb1 && na2 != nb2) ||
160 (na1 == nb2 && na2 != nb1))
181 nacats_orig = ACats->
n_cats;
183 for (c = 0; c < BCats->
n_cats; c++)
186 if (ACats->
n_cats > nacats_orig) {
187 G_debug(4,
"cats merged: n_cats %d -> %d", nacats_orig,
196 G_debug(3,
"nlines = %d\n", nlines);
215 const struct line_pnts *BPoints,
int with_z)
228 for (k = 0; k < APoints->
n_points; k++) {
229 if (APoints->
x[k] != BPoints->
x[k] ||
230 APoints->
y[k] != BPoints->
y[k] ||
231 (with_z && APoints->
z[k] != BPoints->
z[k])) {
239 for (k = 0; k < APoints->
n_points; k++) {
240 if (APoints->
x[k] != BPoints->
x[npoints - k - 1] ||
241 APoints->
y[k] != BPoints->
y[npoints - k - 1] ||
242 (with_z && APoints->
z[k] != BPoints->
z[npoints - k - 1])) {
struct boxlist * Vect_new_boxlist(int have_boxes)
Creates and initializes a struct boxlist.
int Vect_select_lines_by_box(struct Map_info *Map, const struct bound_box *Box, int type, struct boxlist *list)
Select lines with bounding boxes by box.
void G_verbose_message(const char *msg,...)
Print a message to stderr but only if module is in verbose mode.
off_t Vect_rewrite_line(struct Map_info *Map, off_t line, int type, const struct line_pnts *points, const struct line_cats *cats)
Rewrites existing feature (topological level required)
int Vect_get_node_n_lines(const struct Map_info *Map, int node)
Get number of lines for node.
struct line_pnts * Vect_new_line_struct()
Creates and initializes a line_pnts structure.
off_t Vect_write_line(struct Map_info *Map, int type, const struct line_pnts *points, const struct line_cats *cats)
Writes a new feature.
int n_points
Number of points.
int Vect_line_alive(const struct Map_info *Map, int line)
Check if feature is alive or dead (topological level required)
int Vect_delete_line(struct Map_info *Map, off_t line)
Delete existing feature (topological level required)
int n_values
Number of items in the list.
int Vect_cat_set(struct line_cats *Cats, int field, int cat)
Add new field/cat to category structure if doesn't exist yet.
double * x
Array of X coordinates.
Feature geometry info - coordinates.
int Vect_get_node_line(const struct Map_info *Map, int node, int line)
Get line id for node line index.
int n_cats
Number of categories attached to element.
int G_debug(int level, const char *msg,...)
Print debugging message.
int * cat
Array of categories.
void Vect_remove_duplicates(struct Map_info *Map, int type, struct Map_info *Err)
Remove duplicate features from vector map.
int Vect_get_line_type(const struct Map_info *Map, int line)
Get line type.
void G_percent(long n, long d, int s)
Print percent complete messages.
double * y
Array of Y coordinates.
int Vect_get_line_nodes(const struct Map_info *Map, int line, int *n1, int *n2)
Get line nodes.
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 alloc_values
Allocated space for items.
int Vect_line_check_duplicate(const struct line_pnts *APoints, const struct line_pnts *BPoints, int with_z)
Check for duplicate lines.
plus_t Vect_get_num_lines(const struct Map_info *Map)
Fetch number of features (points, lines, boundaries, centroids) in vector map.
List of bounding boxes with id.
double * z
Array of Z coordinates.
int Vect_read_line(const struct Map_info *Map, struct line_pnts *line_p, struct line_cats *line_c, int line)
Read vector feature (topological level required)
int * field
Array of layers (fields)
int Vect_reset_boxlist(struct boxlist *list)
Reset boxlist structure.