35 break_lines(Map,
NULL,
NULL, type, Err, 0);
64 struct ilist *List_ref,
int type,
67 return break_lines(Map, List_break, List_ref, type, Err, 0);
84 return break_lines(Map,
NULL,
NULL, type, Err, 1);
106 struct ilist *List_ref,
int type,
109 return break_lines(Map, List_break, List_ref, type, Err, 1);
112 static int cmp(
const void *a,
const void *
b)
122 static void sort_ilist(
struct ilist *List)
124 int i, j, is_sorted = 1;
126 for (i = 1; i < List->
n_values; i++) {
138 for (i = 1; i < List->
n_values; i++) {
148 int break_lines(
struct Map_info *Map,
struct ilist *List_break,
152 struct line_pnts *APoints, *BPoints, *Points;
155 int i, j, k,
l, ret, atype, btype, aline, bline, found, iline;
156 int nlines, nlines_org;
157 int naxlines, nbxlines, nx;
162 int touch1_n = 0, touch1_s = 0, touch1_e = 0,
164 int touch2_n = 0, touch2_s = 0, touch2_e = 0,
167 int node, anode1, anode2, bnode1, bnode2;
169 int a_is_ref, b_is_ref, break_a, break_b;
186 sort_ilist(List_ref);
188 sort_ilist(List_break);
194 else if (List_break) {
202 G_debug(3,
"nlines = %d", nlines);
226 for (iline = 0; iline < nlines; iline++) {
231 aline = List_ref->
value[iline];
233 else if (List_break) {
234 aline = List_break->
value[iline];
240 G_debug(3,
"aline = %d", aline);
268 touch1_n = touch1_s = touch1_e = touch1_w = 0;
269 for (j = 1; j < APoints->
n_points; j++) {
270 if (APoints->
y[j] == ABox.N)
272 if (APoints->
y[j] == ABox.S)
274 if (APoints->
x[j] == ABox.E)
276 if (APoints->
x[j] == ABox.W)
279 G_debug(3,
"touch1: n = %d s = %d e = %d w = %d", touch1_n,
280 touch1_s, touch1_e, touch1_w);
281 touch2_n = touch2_s = touch2_e = touch2_w = 0;
282 for (j = 0; j < APoints->
n_points - 1; j++) {
283 if (APoints->
y[j] == ABox.N)
285 if (APoints->
y[j] == ABox.S)
287 if (APoints->
x[j] == ABox.E)
289 if (APoints->
x[j] == ABox.W)
292 G_debug(3,
"touch2: n = %d s = %d e = %d w = %d", touch2_n,
293 touch2_s, touch2_e, touch2_w);
299 for (j = -1; j < List->
n_values; j++) {
305 if (aline <= nlines_org)
318 if (List_ref && bsearch(&bline, List_ref->
value, List_ref->
n_values,
333 if (!break_a && !break_b)
338 if (break_a && break_b && aline > bline &&
339 (!List_ref || b_is_ref)) {
343 G_debug(3,
" j = %d bline = %d", j, bline);
351 BBox = &List->
box[j];
359 if (anode1 == bnode1 || anode1 == bnode2)
361 else if (anode2 == bnode1 || anode2 == bnode2)
366 if ((node == anode1 && nodey == ABox.N && !touch1_n &&
368 (node == anode2 && nodey == ABox.N && !touch2_n &&
370 (node == anode1 && nodey == ABox.S && !touch1_s &&
372 (node == anode2 && nodey == ABox.S && !touch2_s &&
374 (node == anode1 && nodex == ABox.E && !touch1_e &&
376 (node == anode2 && nodex == ABox.E && !touch2_e &&
378 (node == anode1 && nodex == ABox.W && !touch1_w &&
380 (node == anode2 && nodex == ABox.W && !touch2_w &&
384 "lines %d and %d touching by end nodes only -> "
395 if (aline != bline) {
397 &BXLines, &naxlines, &nbxlines, 0);
401 &BXLines, &naxlines, &nbxlines, 0);
404 G_debug(3,
" naxlines = %d nbxlines = %d", naxlines, nbxlines);
410 if (aline == bline && naxlines == 0 && nbxlines == 0 &&
411 APoints->
n_points >= 3 && break_a) {
414 G_debug(3,
" Check collapsed loop");
417 if (APoints->
x[centre - 1] == APoints->
x[centre + 1] &&
418 APoints->
y[centre - 1] == APoints->
y[centre + 1] &&
419 APoints->
z[centre - 1] ==
420 APoints->
z[centre + 1]) {
426 for (i = 0; i <= centre; i++)
428 APoints->
y[i], APoints->
z[i]);
430 for (i = centre; i < APoints->
n_points; i++)
432 APoints->
y[i], APoints->
z[i]);
441 xx = (
double *)
G_malloc((naxlines + nbxlines) *
sizeof(double));
442 yx = (
double *)
G_malloc((naxlines + nbxlines) *
sizeof(double));
443 zx = (
double *)
G_malloc((naxlines + nbxlines) *
sizeof(double));
448 G_debug(3,
" aline = %d, bline = %d, naxlines = %d", aline,
451 if (!check && break_a)
453 for (k = 0; k < naxlines; k++) {
458 if (!check && break_a) {
461 G_debug(3,
"Line %d written, npoints = %d", ret,
463 if (List_ref && a_is_ref) {
466 if (List_break && break_a) {
472 G_debug(3,
"axline %d has zero length", k);
477 xx[nx] = AXLines[k]->
x[0];
478 yx[nx] = AXLines[k]->
y[0];
479 zx[nx] = AXLines[k]->
z[0];
485 nbreaks += naxlines - 1;
491 if (aline != bline) {
494 G_debug(3,
" aline = %d, bline = %d, nbxlines = %d",
495 aline, bline, nbxlines);
497 if (!check && break_b)
499 for (k = 0; k < nbxlines; k++) {
504 if (!check && break_b) {
507 G_debug(5,
"Line %d written", ret);
508 if (List_ref && b_is_ref) {
517 G_debug(3,
"bxline %d has zero length", k);
523 for (
l = 0;
l < nx;
l++) {
524 if (xx[
l] == BXLines[k]->
x[0] &&
525 yx[
l] == BXLines[k]->
y[0] &&
526 zx[
l] == BXLines[k]->
z[0]) {
532 xx[nx] = BXLines[k]->
x[0];
533 yx[nx] = BXLines[k]->
y[0];
534 zx[nx] = BXLines[k]->
z[0];
540 nbreaks += nbxlines - 1;
542 for (k = 0; k < nbxlines; k++)
548 for (
l = 0;
l < nx;
l++) {
558 if (naxlines > 0 && !check && break_a) {
559 G_debug(3,
"aline was broken, use next one");
568 else if (List_break) {
574 G_debug(3,
"nlines = %d", nlines);
void Vect_break_lines(struct Map_info *Map, int type, struct Map_info *Err)
Break lines in vector map at each intersection.
int Vect_break_lines_list(struct Map_info *Map, struct ilist *List_break, struct ilist *List_ref, int type, struct Map_info *Err)
Break selected lines in vector map at each intersection.
int Vect_check_line_breaks(struct Map_info *Map, int type, struct Map_info *Err)
Check for and count intersecting lines, do not break.
int Vect_check_line_breaks_list(struct Map_info *Map, struct ilist *List_break, struct ilist *List_ref, int type, struct Map_info *Err)
Check for and count intersecting lines, do not break.
void G_percent(long, long, int)
Print percent complete messages.
void G_free(void *)
Free allocated memory.
void void G_verbose_message(const char *,...) __attribute__((format(printf
void G_ilist_add(struct ilist *, int)
Add item to ilist.
int G_debug(int, const char *,...) __attribute__((format(printf
void Vect_destroy_line_struct(struct line_pnts *)
Frees all memory associated with a line_pnts structure, including the structure itself.
int Vect_get_line_nodes(struct Map_info *, int, int *, int *)
Get line nodes.
int Vect_get_node_coor(struct Map_info *, int, double *, double *, double *)
Get node coordinates.
plus_t Vect_get_num_lines(struct Map_info *)
Fetch number of features (points, lines, boundaries, centroids) in vector map.
void Vect_line_box(const struct line_pnts *, struct bound_box *)
Get bounding box of line.
struct boxlist * Vect_new_boxlist(int)
Creates and initializes a struct boxlist.
int Vect_line_intersection2(struct line_pnts *, struct line_pnts *, struct bound_box *, struct bound_box *, struct line_pnts ***, struct line_pnts ***, int *, int *, int)
Intersect 2 lines.
void Vect_destroy_boxlist(struct boxlist *)
Frees all memory associated with a struct boxlist, including the struct itself.
void Vect_destroy_cats_struct(struct line_cats *)
Frees all memory associated with line_cats structure, including the struct itself.
int Vect_read_line(struct Map_info *, struct line_pnts *, struct line_cats *, int)
Read vector feature (topological level required)
int Vect_line_alive(struct Map_info *, int)
Check if feature is alive or dead (topological level required)
int Vect_delete_line(struct Map_info *, off_t)
Delete existing feature (topological level required)
off_t Vect_write_line(struct Map_info *, int, const struct line_pnts *, const struct line_cats *)
Writes a new feature.
struct line_pnts * Vect_new_line_struct(void)
Creates and initializes a line_pnts structure.
int Vect_select_lines_by_box(struct Map_info *, const struct bound_box *, int, struct boxlist *)
Select lines with bounding boxes by box.
void Vect_reset_line(struct line_pnts *)
Reset line.
int Vect_line_prune(struct line_pnts *)
Remove duplicate points, i.e. zero length segments.
struct line_cats * Vect_new_cats_struct(void)
Creates and initializes line_cats structure.
int Vect_is_3d(struct Map_info *)
Check if vector map is 3D.
int Vect_append_point(struct line_pnts *, double, double, double)
Appends one point to the end of a line.
#define GV_POINT
Feature types used in memory on run time (may change)
List of bounding boxes with id.
struct bound_box * box
Array of bounding boxes.
int n_values
Number of items in the list.
int n_values
Number of values in the list.
int * value
Array of values.
Feature geometry info - coordinates.
double * y
Array of Y coordinates.
double * x
Array of X coordinates.
int n_points
Number of points.
double * z
Array of Z coordinates.