break_polygons.c 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681
  1. /*!
  2. \file lib/vector/Vlib/break_polygons.c
  3. \brief Vector library - clean geometry (break polygons)
  4. Higher level functions for reading/writing/manipulating vectors.
  5. (C) 2001-2009 by the GRASS Development Team
  6. This program is free software under the
  7. GNU General Public License (>=v2).
  8. Read the file COPYING that comes with GRASS
  9. for details.
  10. \author Radim Blazek
  11. \author Update for GRASS 7 Markus Metz
  12. */
  13. #include <stdlib.h>
  14. #include <sys/stat.h>
  15. #include <fcntl.h>
  16. #include <unistd.h>
  17. #include <math.h>
  18. #include <grass/vector.h>
  19. #include <grass/glocale.h>
  20. /* TODO: 3D support
  21. *
  22. * atan2() gives angle from x-axis
  23. * this is unambiguous only in 2D, not in 3D
  24. *
  25. * one possibility would be to store unit vectors of length 1
  26. * in struct XPNT
  27. * double a1[3], a2[3];
  28. *
  29. * length = sqrt(dx * dx + dy * dy + dz * dz);
  30. * dx /= length; dy /= length; dz /=length;
  31. * a1[0] = dx; a1[1] = dy; a1[2] = dz;
  32. *
  33. * get second dx, dy, dz
  34. * length = sqrt(dx * dx + dy * dy + dz * dz);
  35. * dx /= length; dy /= length; dz /=length;
  36. * a2[0] = dx; a2[1] = dy; a2[2] = dz;
  37. *
  38. * equal angles
  39. * if (a1[0] == a2[0] && a1[1] == a2[1] && a1[2] == a2[2])
  40. *
  41. * disadvantage: increased memory consumption
  42. *
  43. * new function Vect_break_faces() ?
  44. *
  45. */
  46. typedef struct
  47. {
  48. double x, y; /* coords */
  49. double a1, a2; /* angles */
  50. char cross; /* 0 - do not break, 1 - break */
  51. char used; /* 0 - was not used to break line, 1 - was used to break line
  52. * this is stored because points are automatically marked as cross, even if not used
  53. * later to break lines */
  54. } XPNT;
  55. typedef struct
  56. {
  57. double a1, a2; /* angles */
  58. char cross; /* 0 - do not break, 1 - break */
  59. char used; /* 0 - was not used to break line, 1 - was used to break line
  60. * this is stored because points are automatically marked as cross, even if not used
  61. * later to break lines */
  62. } XPNT2;
  63. static int fpoint;
  64. /* Function called from RTreeSearch for point found */
  65. void srch(int id, const struct RTree_Rect *rect, int *arg)
  66. {
  67. fpoint = id;
  68. }
  69. /* function used by binary tree to compare items */
  70. static int compare_xpnts(const void *Xpnta, const void *Xpntb)
  71. {
  72. XPNT *a, *b;
  73. a = (XPNT *)Xpnta;
  74. b = (XPNT *)Xpntb;
  75. if (a->x > b->x)
  76. return 1;
  77. else if (a->x < b->x)
  78. return -1;
  79. else {
  80. if (a->y > b->y)
  81. return 1;
  82. else if (a->y < b->y)
  83. return -1;
  84. else
  85. return 0;
  86. }
  87. G_warning(_("Break polygons: Bug in binary tree!"));
  88. return 1;
  89. }
  90. /* break polygons using a file-based search index */
  91. void Vect_break_polygons_file(struct Map_info *Map, int type, struct Map_info *Err)
  92. {
  93. struct line_pnts *BPoints, *Points;
  94. struct line_cats *Cats, *ErrCats;
  95. int i, j, k, ret, ltype, broken, last, nlines;
  96. int nbreaks;
  97. struct RTree *RTree;
  98. int npoints, nallpoints, nmarks;
  99. XPNT2 XPnt;
  100. double dx, dy, a1 = 0, a2 = 0;
  101. int closed, last_point;
  102. char cross;
  103. int fd, xpntfd;
  104. char *filename;
  105. static struct RTree_Rect rect;
  106. static int rect_init = 0;
  107. if (!rect_init) {
  108. rect.boundary = G_malloc(6 * sizeof(RectReal));
  109. rect_init = 6;
  110. }
  111. G_debug(1, "File-based version of Vect_break_polygons()");
  112. filename = G_tempfile();
  113. fd = open(filename, O_RDWR | O_CREAT | O_EXCL, 0600);
  114. RTree = RTreeNewIndex(fd, 0, 2);
  115. remove(filename);
  116. filename = G_tempfile();
  117. xpntfd = open(filename, O_RDWR | O_CREAT | O_EXCL, 0600);
  118. remove(filename);
  119. BPoints = Vect_new_line_struct();
  120. Points = Vect_new_line_struct();
  121. Cats = Vect_new_cats_struct();
  122. ErrCats = Vect_new_cats_struct();
  123. nlines = Vect_get_num_lines(Map);
  124. G_debug(3, "nlines = %d", nlines);
  125. /* Go through all lines in vector, and add each point to structure of points,
  126. * if such point already exists check angles of segments and if differ mark for break */
  127. nmarks = 0;
  128. npoints = 1; /* index starts from 1 ! */
  129. nallpoints = 0;
  130. XPnt.used = 0;
  131. G_verbose_message(_("Break polygons Pass 1: select break points"));
  132. for (i = 1; i <= nlines; i++) {
  133. G_percent(i, nlines, 1);
  134. G_debug(3, "i = %d", i);
  135. if (!Vect_line_alive(Map, i))
  136. continue;
  137. ltype = Vect_read_line(Map, Points, Cats, i);
  138. if (!(ltype & type))
  139. continue;
  140. /* This would be confused by duplicate coordinates (angle cannot be calculated) ->
  141. * prune line first */
  142. Vect_line_prune(Points);
  143. /* If first and last point are identical it is close polygon, we dont need to register last point
  144. * and we can calculate angle for first.
  145. * If first and last point are not identical we have to mark for break both */
  146. last_point = Points->n_points - 1;
  147. if (Points->x[0] == Points->x[last_point] &&
  148. Points->y[0] == Points->y[last_point])
  149. closed = 1;
  150. else
  151. closed = 0;
  152. for (j = 0; j < Points->n_points; j++) {
  153. G_debug(3, "j = %d", j);
  154. nallpoints++;
  155. if (j == last_point && closed)
  156. continue; /* do not register last of close polygon */
  157. /* Box */
  158. rect.boundary[0] = Points->x[j];
  159. rect.boundary[3] = Points->x[j];
  160. rect.boundary[1] = Points->y[j];
  161. rect.boundary[4] = Points->y[j];
  162. rect.boundary[2] = 0;
  163. rect.boundary[5] = 0;
  164. /* Already in DB? */
  165. fpoint = -1;
  166. RTreeSearch(RTree, &rect, (void *)srch, NULL);
  167. G_debug(3, "fpoint = %d", fpoint);
  168. if (Points->n_points <= 2 ||
  169. (!closed && (j == 0 || j == last_point))) {
  170. cross = 1; /* mark for cross in any case */
  171. }
  172. else { /* calculate angles */
  173. cross = 0;
  174. if (j == 0 && closed) { /* closed polygon */
  175. dx = Points->x[last_point] - Points->x[0];
  176. dy = Points->y[last_point] - Points->y[0];
  177. a1 = atan2(dy, dx);
  178. dx = Points->x[1] - Points->x[0];
  179. dy = Points->y[1] - Points->y[0];
  180. a2 = atan2(dy, dx);
  181. }
  182. else {
  183. dx = Points->x[j - 1] - Points->x[j];
  184. dy = Points->y[j - 1] - Points->y[j];
  185. a1 = atan2(dy, dx);
  186. dx = Points->x[j + 1] - Points->x[j];
  187. dy = Points->y[j + 1] - Points->y[j];
  188. a2 = atan2(dy, dx);
  189. }
  190. }
  191. if (fpoint > 0) { /* Found */
  192. /* read point */
  193. lseek(xpntfd, (off_t) (fpoint - 1) * sizeof(XPNT2), SEEK_SET);
  194. read(xpntfd, &XPnt, sizeof(XPNT2));
  195. if (XPnt.cross == 1)
  196. continue; /* already marked */
  197. /* Check angles */
  198. if (cross) {
  199. XPnt.cross = 1;
  200. nmarks++;
  201. /* write point */
  202. lseek(xpntfd, (off_t) (fpoint - 1) * sizeof(XPNT2), SEEK_SET);
  203. write(xpntfd, &XPnt, sizeof(XPNT2));
  204. }
  205. else {
  206. G_debug(3, "a1 = %f xa1 = %f a2 = %f xa2 = %f", a1,
  207. XPnt.a1, a2, XPnt.a2);
  208. if ((a1 == XPnt.a1 && a2 == XPnt.a2) ||
  209. (a1 == XPnt.a2 && a2 == XPnt.a1)) { /* identical */
  210. }
  211. else {
  212. XPnt.cross = 1;
  213. nmarks++;
  214. /* write point */
  215. lseek(xpntfd, (off_t) (fpoint - 1) * sizeof(XPNT2), SEEK_SET);
  216. write(xpntfd, &XPnt, sizeof(XPNT2));
  217. }
  218. }
  219. }
  220. else {
  221. /* Add to tree and to structure */
  222. RTreeInsertRect(&rect, npoints, RTree);
  223. if (j == 0 || j == (Points->n_points - 1) ||
  224. Points->n_points < 3) {
  225. XPnt.a1 = 0;
  226. XPnt.a2 = 0;
  227. XPnt.cross = 1;
  228. nmarks++;
  229. }
  230. else {
  231. XPnt.a1 = a1;
  232. XPnt.a2 = a2;
  233. XPnt.cross = 0;
  234. }
  235. /* write point */
  236. lseek(xpntfd, (off_t) (npoints - 1) * sizeof(XPNT2), SEEK_SET);
  237. write(xpntfd, &XPnt, sizeof(XPNT2));
  238. npoints++;
  239. }
  240. }
  241. }
  242. nbreaks = 0;
  243. /* Second loop through lines (existing when loop is started, no need to process lines written again)
  244. * and break at points marked for break */
  245. G_verbose_message(_("Break polygons Pass 2: break at selected points"));
  246. for (i = 1; i <= nlines; i++) {
  247. int n_orig_points;
  248. G_percent(i, nlines, 1);
  249. G_debug(3, "i = %d", i);
  250. if (!Vect_line_alive(Map, i))
  251. continue;
  252. ltype = Vect_read_line(Map, Points, Cats, i);
  253. if (!(ltype & type))
  254. continue;
  255. if (!(ltype & GV_LINES))
  256. continue; /* Nonsense to break points */
  257. /* Duplicates would result in zero length lines -> prune line first */
  258. n_orig_points = Points->n_points;
  259. Vect_line_prune(Points);
  260. broken = 0;
  261. last = 0;
  262. G_debug(3, "n_points = %d", Points->n_points);
  263. for (j = 1; j < Points->n_points; j++) {
  264. G_debug(3, "j = %d", j);
  265. nallpoints++;
  266. /* Box */
  267. rect.boundary[0] = Points->x[j];
  268. rect.boundary[3] = Points->x[j];
  269. rect.boundary[1] = Points->y[j];
  270. rect.boundary[4] = Points->y[j];
  271. rect.boundary[2] = 0;
  272. rect.boundary[5] = 0;
  273. if (Points->n_points <= 1 ||
  274. (j == (Points->n_points - 1) && !broken))
  275. break;
  276. /* One point only or
  277. * last point and line is not broken, do nothing */
  278. RTreeSearch(RTree, &rect, (void *)srch, 0);
  279. G_debug(3, "fpoint = %d", fpoint);
  280. /* read point */
  281. lseek(xpntfd, (off_t) (fpoint - 1) * sizeof(XPNT2), SEEK_SET);
  282. read(xpntfd, &XPnt, sizeof(XPNT2));
  283. /* break or write last segment of broken line */
  284. if ((j == (Points->n_points - 1) && broken) ||
  285. XPnt.cross) {
  286. Vect_reset_line(BPoints);
  287. for (k = last; k <= j; k++) {
  288. Vect_append_point(BPoints, Points->x[k], Points->y[k],
  289. Points->z[k]);
  290. }
  291. /* Result may collapse to one point */
  292. Vect_line_prune(BPoints);
  293. if (BPoints->n_points > 1) {
  294. ret = Vect_write_line(Map, ltype, BPoints, Cats);
  295. G_debug(3,
  296. "Line %d written j = %d n_points(orig,pruned) = %d n_points(new) = %d",
  297. ret, j, Points->n_points, BPoints->n_points);
  298. }
  299. if (!broken)
  300. Vect_delete_line(Map, i); /* not yet deleted */
  301. /* Write points on breaks */
  302. if (Err) {
  303. if (XPnt.cross && !XPnt.used) {
  304. Vect_reset_line(BPoints);
  305. Vect_append_point(BPoints, Points->x[j], Points->y[j], 0);
  306. Vect_write_line(Err, GV_POINT, BPoints, ErrCats);
  307. }
  308. if (!XPnt.used) {
  309. XPnt.used = 1;
  310. /* write point */
  311. lseek(xpntfd, (off_t) (fpoint - 1) * sizeof(XPNT2), SEEK_SET);
  312. write(xpntfd, &XPnt, sizeof(XPNT2));
  313. }
  314. }
  315. last = j;
  316. broken = 1;
  317. nbreaks++;
  318. }
  319. }
  320. if (!broken && n_orig_points > Points->n_points) { /* was pruned before -> rewrite */
  321. if (Points->n_points > 1) {
  322. Vect_rewrite_line(Map, i, ltype, Points, Cats);
  323. G_debug(3, "Line %d pruned, npoints = %d", i,
  324. Points->n_points);
  325. }
  326. else {
  327. Vect_delete_line(Map, i);
  328. G_debug(3, "Line %d was deleted", i);
  329. }
  330. }
  331. else {
  332. G_debug(3, "Line %d was not changed", i);
  333. }
  334. }
  335. close(RTree->fd);
  336. RTreeFreeIndex(RTree);
  337. close(xpntfd);
  338. Vect_destroy_line_struct(Points);
  339. Vect_destroy_line_struct(BPoints);
  340. Vect_destroy_cats_struct(Cats);
  341. Vect_destroy_cats_struct(ErrCats);
  342. G_verbose_message(_("Breaks: %d"), nbreaks);
  343. }
  344. /* break polygons using a memory-based search index */
  345. void Vect_break_polygons_mem(struct Map_info *Map, int type, struct Map_info *Err)
  346. {
  347. struct line_pnts *BPoints, *Points;
  348. struct line_cats *Cats, *ErrCats;
  349. int i, j, k, ret, ltype, broken, last, nlines;
  350. int nbreaks;
  351. struct RB_TREE *RBTree;
  352. int npoints, nallpoints, nmarks;
  353. XPNT *XPnt_found, XPnt_search;
  354. double dx, dy, a1 = 0, a2 = 0;
  355. int closed, last_point, cross;
  356. G_debug(1, "Memory-based version of Vect_break_polygons()");
  357. RBTree = rbtree_create(compare_xpnts, sizeof(XPNT));
  358. BPoints = Vect_new_line_struct();
  359. Points = Vect_new_line_struct();
  360. Cats = Vect_new_cats_struct();
  361. ErrCats = Vect_new_cats_struct();
  362. nlines = Vect_get_num_lines(Map);
  363. G_debug(3, "nlines = %d", nlines);
  364. /* Go through all lines in vector, and add each point to structure of points,
  365. * if such point already exists check angles of segments and if differ mark for break */
  366. nmarks = 0;
  367. npoints = 0;
  368. nallpoints = 0;
  369. XPnt_search.used = 0;
  370. G_message(_("Breaking polygons (pass 1: select break points)..."));
  371. for (i = 1; i <= nlines; i++) {
  372. G_percent(i, nlines, 1);
  373. G_debug(3, "i = %d", i);
  374. if (!Vect_line_alive(Map, i))
  375. continue;
  376. ltype = Vect_read_line(Map, Points, Cats, i);
  377. if (!(ltype & type))
  378. continue;
  379. /* This would be confused by duplicate coordinates (angle cannot be calculated) ->
  380. * prune line first */
  381. Vect_line_prune(Points);
  382. /* If first and last point are identical it is close polygon, we dont need to register last point
  383. * and we can calculate angle for first.
  384. * If first and last point are not identical we have to mark for break both */
  385. last_point = Points->n_points - 1;
  386. if (Points->x[0] == Points->x[last_point] &&
  387. Points->y[0] == Points->y[last_point])
  388. closed = 1;
  389. else
  390. closed = 0;
  391. for (j = 0; j < Points->n_points; j++) {
  392. G_debug(3, "j = %d", j);
  393. nallpoints++;
  394. if (j == last_point && closed)
  395. continue; /* do not register last of close polygon */
  396. XPnt_search.x = Points->x[j];
  397. XPnt_search.y = Points->y[j];
  398. /* Already in DB? */
  399. XPnt_found = rbtree_find(RBTree, &XPnt_search);
  400. if (Points->n_points <= 2 ||
  401. (!closed && (j == 0 || j == last_point))) {
  402. cross = 1; /* mark for cross in any case */
  403. }
  404. else { /* calculate angles */
  405. cross = 0;
  406. if (j == 0 && closed) { /* closed polygon */
  407. dx = Points->x[last_point] - Points->x[0];
  408. dy = Points->y[last_point] - Points->y[0];
  409. a1 = atan2(dy, dx);
  410. dx = Points->x[1] - Points->x[0];
  411. dy = Points->y[1] - Points->y[0];
  412. a2 = atan2(dy, dx);
  413. }
  414. else {
  415. dx = Points->x[j - 1] - Points->x[j];
  416. dy = Points->y[j - 1] - Points->y[j];
  417. a1 = atan2(dy, dx);
  418. dx = Points->x[j + 1] - Points->x[j];
  419. dy = Points->y[j + 1] - Points->y[j];
  420. a2 = atan2(dy, dx);
  421. }
  422. }
  423. if (XPnt_found) { /* found */
  424. if (XPnt_found->cross == 1)
  425. continue; /* already marked */
  426. /* check angles */
  427. if (cross) {
  428. XPnt_found->cross = 1;
  429. nmarks++;
  430. }
  431. else {
  432. G_debug(3, "a1 = %f xa1 = %f a2 = %f xa2 = %f", a1,
  433. XPnt_found->a1, a2, XPnt_found->a2);
  434. if ((a1 == XPnt_found->a1 && a2 == XPnt_found->a2) ||
  435. (a1 == XPnt_found->a2 && a2 == XPnt_found->a1)) { /* identical */
  436. }
  437. else {
  438. XPnt_found->cross = 1;
  439. nmarks++;
  440. }
  441. }
  442. }
  443. else {
  444. if (j == 0 || j == (Points->n_points - 1) ||
  445. Points->n_points < 3) {
  446. XPnt_search.a1 = 0;
  447. XPnt_search.a2 = 0;
  448. XPnt_search.cross = 1;
  449. nmarks++;
  450. }
  451. else {
  452. XPnt_search.a1 = a1;
  453. XPnt_search.a2 = a2;
  454. XPnt_search.cross = 0;
  455. }
  456. /* Add to tree */
  457. rbtree_insert(RBTree, &XPnt_search);
  458. npoints++;
  459. }
  460. }
  461. }
  462. nbreaks = 0;
  463. nallpoints = 0;
  464. G_debug(2, "Break polygons: unique vertices: %ld", (long int)RBTree->count);
  465. /* uncomment to check if search tree is healthy */
  466. /* if (rbtree_debug(RBTree, RBTree->root) == 0)
  467. G_warning("Break polygons: RBTree not ok"); */
  468. /* Second loop through lines (existing when loop is started, no need to process lines written again)
  469. * and break at points marked for break */
  470. G_message(_("Breaking polygons (pass 2: break at selected points)..."));
  471. for (i = 1; i <= nlines; i++) {
  472. int n_orig_points;
  473. G_percent(i, nlines, 1);
  474. G_debug(3, "i = %d", i);
  475. if (!Vect_line_alive(Map, i))
  476. continue;
  477. ltype = Vect_read_line(Map, Points, Cats, i);
  478. if (!(ltype & type))
  479. continue;
  480. if (!(ltype & GV_LINES))
  481. continue; /* Nonsense to break points */
  482. /* Duplicates would result in zero length lines -> prune line first */
  483. n_orig_points = Points->n_points;
  484. Vect_line_prune(Points);
  485. broken = 0;
  486. last = 0;
  487. G_debug(3, "n_points = %d", Points->n_points);
  488. for (j = 1; j < Points->n_points; j++) {
  489. G_debug(3, "j = %d", j);
  490. nallpoints++;
  491. if (Points->n_points <= 1 ||
  492. (j == (Points->n_points - 1) && !broken))
  493. break;
  494. /* One point only or
  495. * last point and line is not broken, do nothing */
  496. XPnt_search.x = Points->x[j];
  497. XPnt_search.y = Points->y[j];
  498. XPnt_found = rbtree_find(RBTree, &XPnt_search);
  499. /* all points must be in the search tree, without duplicates */
  500. if (XPnt_found == NULL)
  501. G_fatal_error(_("Point not in search tree!"));
  502. /* break or write last segment of broken line */
  503. if ((j == (Points->n_points - 1) && broken) ||
  504. XPnt_found->cross) {
  505. Vect_reset_line(BPoints);
  506. for (k = last; k <= j; k++) {
  507. Vect_append_point(BPoints, Points->x[k], Points->y[k],
  508. Points->z[k]);
  509. }
  510. /* Result may collapse to one point */
  511. Vect_line_prune(BPoints);
  512. if (BPoints->n_points > 1) {
  513. ret = Vect_write_line(Map, ltype, BPoints, Cats);
  514. G_debug(3,
  515. "Line %d written j = %d n_points(orig,pruned) = %d n_points(new) = %d",
  516. ret, j, Points->n_points, BPoints->n_points);
  517. }
  518. if (!broken)
  519. Vect_delete_line(Map, i); /* not yet deleted */
  520. /* Write points on breaks */
  521. if (Err) {
  522. if (XPnt_found->cross && !XPnt_found->used) {
  523. Vect_reset_line(BPoints);
  524. Vect_append_point(BPoints, Points->x[j], Points->y[j], 0);
  525. Vect_write_line(Err, GV_POINT, BPoints, ErrCats);
  526. }
  527. XPnt_found->used = 1;
  528. }
  529. last = j;
  530. broken = 1;
  531. nbreaks++;
  532. }
  533. }
  534. if (!broken && n_orig_points > Points->n_points) { /* was pruned before -> rewrite */
  535. if (Points->n_points > 1) {
  536. Vect_rewrite_line(Map, i, ltype, Points, Cats);
  537. G_debug(3, "Line %d pruned, npoints = %d", i,
  538. Points->n_points);
  539. }
  540. else {
  541. Vect_delete_line(Map, i);
  542. G_debug(3, "Line %d was deleted", i);
  543. }
  544. }
  545. else {
  546. G_debug(3, "Line %d was not changed", i);
  547. }
  548. }
  549. rbtree_destroy(RBTree);
  550. Vect_destroy_line_struct(Points);
  551. Vect_destroy_line_struct(BPoints);
  552. Vect_destroy_cats_struct(Cats);
  553. G_verbose_message(_("Breaks: %d"), nbreaks);
  554. }
  555. /*!
  556. \brief Break polygons in vector map.
  557. Breaks lines specified by type in vector map. Points at
  558. intersections may be optionally written to error map. Input map
  559. must be opened on level 2 for update at least on GV_BUILD_BASE.
  560. Function is optimized for closed polygons rigs (e.g. imported from
  561. OGR) but with clean geometry - adjacent polygons mostly have
  562. identical boundary. Function creates database of ALL points in the
  563. map, and then is looking for those where polygons should be broken.
  564. Lines may be broken only at points existing in input map!
  565. \param Map input map where polygons will be broken
  566. \param type type of line to be broken
  567. \param Err vector map where points at intersections will be written or NULL
  568. \return
  569. */
  570. void
  571. Vect_break_polygons(struct Map_info *Map, int type, struct Map_info *Err)
  572. {
  573. if (getenv("GRASS_VECTOR_LOWMEM"))
  574. return Vect_break_polygons_file(Map, type, Err);
  575. else
  576. return Vect_break_polygons_mem(Map, type, Err);
  577. }