build_nat.c 19 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705
  1. /*!
  2. \file lib/vector/Vlib/build_nat.c
  3. \brief Vector library - Building topology for native format
  4. (C) 2001-2009 by the GRASS Development Team
  5. This program is free software under the
  6. GNU General Public License (>=v2).
  7. Read the file COPYING that comes with GRASS
  8. for details.
  9. \author Original author CERL, probably Dave Gerdes or Mike Higgins.
  10. \author Update to GRASS 5.7 Radim Blazek and David D. Gray.
  11. */
  12. #include <string.h>
  13. #include <stdlib.h>
  14. #include <stdio.h>
  15. #include <sys/types.h>
  16. #include <grass/glocale.h>
  17. #include <grass/vector.h>
  18. /*!
  19. \brief Build area on given side of line (GV_LEFT or GV_RIGHT)
  20. \param Map_info vector map
  21. \param iline line id
  22. \param side side (GV_LEFT or GV_RIGHT)
  23. \return > 0 number of area
  24. \return < 0 number of isle
  25. \return 0 not created (may also already exist)
  26. */
  27. int Vect_build_line_area(struct Map_info *Map, int iline, int side)
  28. {
  29. int j, area, isle, n_lines, line, type, direction;
  30. static int first = 1;
  31. off_t offset;
  32. struct Plus_head *plus;
  33. struct P_line *BLine;
  34. static struct line_pnts *Points, *APoints;
  35. struct bound_box box;
  36. plus_t *lines;
  37. double area_size;
  38. plus = &(Map->plus);
  39. G_debug(3, "Vect_build_line_area() line = %d, side = %d", iline, side);
  40. if (first) {
  41. Points = Vect_new_line_struct();
  42. APoints = Vect_new_line_struct();
  43. first = 0;
  44. }
  45. area = dig_line_get_area(plus, iline, side);
  46. if (area != 0) {
  47. G_debug(3, " area/isle = %d -> skip", area);
  48. return 0;
  49. }
  50. n_lines = dig_build_area_with_line(plus, iline, side, &lines);
  51. G_debug(3, " n_lines = %d", n_lines);
  52. if (n_lines < 1) {
  53. return 0;
  54. } /* area was not built */
  55. /* Area or island ? */
  56. Vect_reset_line(APoints);
  57. for (j = 0; j < n_lines; j++) {
  58. line = abs(lines[j]);
  59. BLine = plus->Line[line];
  60. offset = BLine->offset;
  61. G_debug(3, " line[%d] = %d, offset = %lu", j, line,
  62. (unsigned long)offset);
  63. type = Vect_read_line(Map, Points, NULL, line);
  64. if (lines[j] > 0)
  65. direction = GV_FORWARD;
  66. else
  67. direction = GV_BACKWARD;
  68. Vect_append_points(APoints, Points, direction);
  69. APoints->n_points--; /* skip last point, avoids duplicates */
  70. }
  71. dig_line_box(APoints, &box);
  72. APoints->n_points++; /* close polygon */
  73. dig_find_area_poly(APoints, &area_size);
  74. /* area_size = dig_find_poly_orientation(APoints); */
  75. /* area_size is not real area size, we are only interested in the sign */
  76. G_debug(3, " area/isle size = %f", area_size);
  77. if (area_size > 0) { /* CW: area */
  78. /* add area structure to plus */
  79. area = dig_add_area(plus, n_lines, lines, &box);
  80. if (area == -1) { /* error */
  81. Vect_close(Map);
  82. G_fatal_error(_("Unable to add area (map closed, topo saved)"));
  83. }
  84. G_debug(3, " -> area %d", area);
  85. return area;
  86. }
  87. else if (area_size < 0) { /* CCW: island */
  88. isle = dig_add_isle(plus, n_lines, lines, &box);
  89. if (isle == -1) { /* error */
  90. Vect_close(Map);
  91. G_fatal_error(_("Unable to add isle (map closed, topo saved)"));
  92. }
  93. G_debug(3, " -> isle %d", isle);
  94. return -isle;
  95. }
  96. else {
  97. /* TODO: What to do with such areas? Should be areas/isles of size 0 stored,
  98. * so that may be found and cleaned by some utility
  99. * Note: it would be useful for vertical closed polygons, but such would be added twice
  100. * as area */
  101. G_warning(_("Area of size = 0.0 ignored"));
  102. }
  103. return 0;
  104. }
  105. /*!
  106. \brief Find area outside island
  107. \param Map_info vector map
  108. \param isle isle id
  109. \return area id
  110. \return 0 if not found
  111. */
  112. int Vect_isle_find_area(struct Map_info *Map, int isle)
  113. {
  114. int j, line, sel_area, first, area, poly;
  115. static int first_call = 1;
  116. const struct Plus_head *plus;
  117. struct P_line *Line;
  118. struct P_node *Node;
  119. struct P_isle *Isle;
  120. struct P_area *Area;
  121. struct P_topo_b *topo;
  122. double size, cur_size;
  123. struct bound_box box, abox;
  124. static struct boxlist *List;
  125. static struct line_pnts *APoints;
  126. /* Note: We should check all isle points (at least) because if topology is not clean
  127. * and two areas overlap, isle which is not completely within area may be attached,
  128. * but it would take long time */
  129. G_debug(3, "Vect_isle_find_area () island = %d", isle);
  130. plus = &(Map->plus);
  131. if (plus->Isle[isle] == NULL) {
  132. G_warning(_("Request to find area outside nonexistent isle"));
  133. return 0;
  134. }
  135. if (first_call) {
  136. List = Vect_new_boxlist(1);
  137. APoints = Vect_new_line_struct();
  138. first_call = 0;
  139. }
  140. Isle = plus->Isle[isle];
  141. line = abs(Isle->lines[0]);
  142. Line = plus->Line[line];
  143. topo = (struct P_topo_b *)Line->topo;
  144. Node = plus->Node[topo->N1];
  145. /* select areas by box */
  146. box.E = Node->x;
  147. box.W = Node->x;
  148. box.N = Node->y;
  149. box.S = Node->y;
  150. box.T = PORT_DOUBLE_MAX;
  151. box.B = -PORT_DOUBLE_MAX;
  152. Vect_select_areas_by_box(Map, &box, List);
  153. G_debug(3, "%d areas overlap island boundary point", List->n_values);
  154. sel_area = 0;
  155. cur_size = -1;
  156. first = 1;
  157. Vect_get_isle_box(Map, isle, &box);
  158. for (j = 0; j < List->n_values; j++) {
  159. area = List->id[j];
  160. G_debug(3, "area = %d", area);
  161. Area = plus->Area[area];
  162. /* Before other tests, simply exclude those areas inside isolated isles formed by one boundary */
  163. if (abs(Isle->lines[0]) == abs(Area->lines[0])) {
  164. G_debug(3, " area inside isolated isle");
  165. continue;
  166. }
  167. /* Check box */
  168. /* Note: If build is run on large files of areas imported from nontopo format (shapefile)
  169. * attaching of isles takes very long time because each area is also isle and select by
  170. * box all overlapping areas selects all areas with box overlapping first node.
  171. * Then reading coordinates for all those areas would take a long time -> check first
  172. * if isle's box is completely within area box */
  173. abox = List->box[j];
  174. if (box.E > abox.E || box.W < abox.W || box.N > abox.N ||
  175. box.S < abox.S) {
  176. G_debug(3, " isle not completely inside area box");
  177. continue;
  178. }
  179. poly = Vect_point_in_area_outer_ring(Node->x, Node->y, Map, area, abox);
  180. G_debug(3, " poly = %d", poly);
  181. if (poly == 1) { /* point in area, but node is not part of area inside isle (would be poly == 2) */
  182. /* In rare case island is inside more areas in that case we have to calculate area
  183. * of outer ring and take the smaller */
  184. if (sel_area == 0) { /* first */
  185. sel_area = area;
  186. }
  187. else { /* is not first */
  188. if (cur_size < 0) { /* second area */
  189. /* This is slow, but should not be called often */
  190. Vect_get_area_points(Map, sel_area, APoints);
  191. /* G_begin_polygon_area_calculations();
  192. cur_size =
  193. G_area_of_polygon(APoints->x, APoints->y,
  194. APoints->n_points); */
  195. /* this is faster, but there may be latlon problems: the poles */
  196. dig_find_area_poly(APoints, &cur_size);
  197. G_debug(3, " first area size = %f (n points = %d)",
  198. cur_size, APoints->n_points);
  199. }
  200. Vect_get_area_points(Map, area, APoints);
  201. /* size =
  202. G_area_of_polygon(APoints->x, APoints->y,
  203. APoints->n_points); */
  204. /* this is faster, but there may be latlon problems: the poles */
  205. dig_find_area_poly(APoints, &size);
  206. G_debug(3, " area size = %f (n points = %d)", size,
  207. APoints->n_points);
  208. if (size > 0 && size < cur_size) {
  209. sel_area = area;
  210. cur_size = size;
  211. }
  212. }
  213. G_debug(3, "sel_area = %d cur_size = %f", sel_area, cur_size);
  214. }
  215. }
  216. if (sel_area > 0) {
  217. G_debug(3, "Island %d in area %d", isle, sel_area);
  218. }
  219. else {
  220. G_debug(3, "Island %d is not in area", isle);
  221. }
  222. return sel_area;
  223. }
  224. /*!
  225. \brief (Re)Attach isle to area
  226. \param Map_info vector map
  227. \param isle isle id
  228. \return 0
  229. */
  230. int Vect_attach_isle(struct Map_info *Map, int isle)
  231. {
  232. int sel_area;
  233. struct P_isle *Isle;
  234. struct Plus_head *plus;
  235. /* Note!: If topology is not clean and areas overlap, one island may fall to more areas
  236. * (partially or fully). Before isle is attached to area it must be check if it is not attached yet */
  237. G_debug(3, "Vect_attach_isle (): isle = %d", isle);
  238. plus = &(Map->plus);
  239. sel_area = Vect_isle_find_area(Map, isle);
  240. G_debug(3, " isle = %d -> area outside = %d", isle, sel_area);
  241. if (sel_area > 0) {
  242. Isle = plus->Isle[isle];
  243. if (Isle->area > 0) {
  244. G_debug(3,
  245. "Attempt to attach isle %d to more areas (=>topology is not clean)",
  246. isle);
  247. }
  248. else {
  249. Isle->area = sel_area;
  250. dig_area_add_isle(plus, sel_area, isle);
  251. }
  252. }
  253. return 0;
  254. }
  255. /*!
  256. \brief (Re)Attach isles to areas in given bounding box
  257. \param Map_info vector map
  258. \param box bounding box
  259. \return 0
  260. */
  261. int Vect_attach_isles(struct Map_info *Map, const struct bound_box * box)
  262. {
  263. int i, isle;
  264. static int first = 1;
  265. static struct boxlist *List;
  266. struct Plus_head *plus;
  267. G_debug(3, "Vect_attach_isles ()");
  268. plus = &(Map->plus);
  269. if (first) {
  270. List = Vect_new_boxlist(0);
  271. first = 0;
  272. }
  273. Vect_select_isles_by_box(Map, box, List);
  274. G_debug(3, " number of isles to attach = %d", List->n_values);
  275. for (i = 0; i < List->n_values; i++) {
  276. isle = List->id[i];
  277. /* only attach isles that are not yet attached, see Vect_attach_isle() */
  278. if (plus->Isle[isle]->area == 0)
  279. Vect_attach_isle(Map, isle);
  280. }
  281. return 0;
  282. }
  283. /*!
  284. \brief (Re)Attach centroids to areas in given bounding box
  285. \param Map_info vector map
  286. \param box bounding box
  287. \return 0
  288. */
  289. int Vect_attach_centroids(struct Map_info *Map, const struct bound_box * box)
  290. {
  291. int i, sel_area, centr;
  292. static int first = 1;
  293. static struct boxlist *List;
  294. static struct line_pnts *Points;
  295. struct P_area *Area;
  296. struct P_line *Line;
  297. struct P_topo_c *topo;
  298. struct Plus_head *plus;
  299. G_debug(3, "Vect_attach_centroids ()");
  300. plus = &(Map->plus);
  301. if (first) {
  302. List = Vect_new_boxlist(0);
  303. Points = Vect_new_line_struct();
  304. first = 0;
  305. }
  306. /* Warning: If map is updated on level2, it may happen that previously correct island
  307. * becomes incorrect. In that case, centroid of area forming the island is reattached
  308. * to outer area, because island polygon is not excluded.
  309. *
  310. * +-----------+ +-----------+
  311. * | 1 | | 1 |
  312. * | +---+---+ | | +---+---+ |
  313. * | | 2 | 3 | | | | 2 | |
  314. * | | x | | | -> | | x | |
  315. * | | | | | | | | |
  316. * | +---+---+ | | +---+---+ |
  317. * | | | |
  318. * +-----------+ +-----------+
  319. * centroid is centroid is
  320. * attached to 2 reattached to 1
  321. *
  322. * Because of this, when the centroid is reattached to another area, it is always necessary
  323. * to check if original area exist, unregister centroid from previous area.
  324. * To simplify code, this is implemented so that centroid is always firs unregistered
  325. * and if new area is found, it is registered again.
  326. *
  327. * This problem can be avoided altogether if properly attached centroids
  328. * are skipped
  329. * MM 2009
  330. */
  331. Vect_select_lines_by_box(Map, box, GV_CENTROID, List);
  332. G_debug(3, " number of centroids to reattach = %d", List->n_values);
  333. for (i = 0; i < List->n_values; i++) {
  334. int orig_area;
  335. centr = List->id[i];
  336. Line = plus->Line[centr];
  337. topo = (struct P_topo_c *)Line->topo;
  338. /* only attach unregistered and duplicate centroids because
  339. * 1) all properly attached centroids are properly attached, really! Don't touch.
  340. * 2) Vect_find_area() below does not always return the correct area
  341. * 3) it's faster
  342. */
  343. if (topo->area > 0)
  344. continue;
  345. orig_area = topo->area;
  346. Vect_read_line(Map, Points, NULL, centr);
  347. sel_area = Vect_find_area(Map, Points->x[0], Points->y[0]);
  348. G_debug(3, " centroid %d is in area %d", centr, sel_area);
  349. if (sel_area > 0) {
  350. Area = plus->Area[sel_area];
  351. if (Area->centroid == 0) { /* first centroid */
  352. G_debug(3, " first centroid -> attach to area");
  353. Area->centroid = centr;
  354. topo->area = sel_area;
  355. if (sel_area != orig_area && plus->do_uplist)
  356. dig_line_add_updated(plus, centr);
  357. }
  358. else if (Area->centroid != centr) { /* duplicate centroid */
  359. /* Note: it cannot happen that Area->centroid == centr, because the centroid
  360. * was not registered or a duplicate */
  361. G_debug(3, " duplicate centroid -> do not attach to area");
  362. topo->area = -sel_area;
  363. if (-sel_area != orig_area && plus->do_uplist)
  364. dig_line_add_updated(plus, centr);
  365. }
  366. }
  367. }
  368. return 0;
  369. }
  370. /*!
  371. \brief Build topology
  372. \param Map_info vector map
  373. \param build build level
  374. \return 1 on success
  375. \return 0 on error
  376. */
  377. int Vect_build_nat(struct Map_info *Map, int build)
  378. {
  379. struct Plus_head *plus;
  380. int i, s, type, line;
  381. off_t offset;
  382. int side, area;
  383. struct line_pnts *Points, *APoints;
  384. struct line_cats *Cats;
  385. struct P_line *Line;
  386. struct P_area *Area;
  387. struct bound_box box;
  388. struct ilist *List;
  389. int print_counter = G_verbose() > G_verbose_min();
  390. G_debug(3, "Vect_build_nat() build = %d", build);
  391. plus = &(Map->plus);
  392. if (build == plus->built)
  393. return 1; /* Do nothing */
  394. /* Check if upgrade or downgrade */
  395. if (build < plus->built) { /* lower level request */
  396. /* release old sources (this also initializes structures and numbers of elements) */
  397. if (plus->built >= GV_BUILD_CENTROIDS && build < GV_BUILD_CENTROIDS) {
  398. /* reset info about areas stored for centroids */
  399. int nlines = Vect_get_num_lines(Map);
  400. for (line = 1; line <= nlines; line++) {
  401. Line = plus->Line[line];
  402. if (Line && Line->type == GV_CENTROID) {
  403. struct P_topo_c *topo = (struct P_topo_c *)Line->topo;
  404. topo->area = 0;
  405. }
  406. }
  407. dig_free_plus_areas(plus);
  408. dig_spidx_free_areas(plus);
  409. dig_free_plus_isles(plus);
  410. dig_spidx_free_isles(plus);
  411. }
  412. if (plus->built >= GV_BUILD_AREAS && build < GV_BUILD_AREAS) {
  413. /* reset info about areas stored for lines */
  414. int nlines = Vect_get_num_lines(Map);
  415. for (line = 1; line <= nlines; line++) {
  416. Line = plus->Line[line];
  417. if (Line && Line->type == GV_BOUNDARY) {
  418. struct P_topo_b *topo = (struct P_topo_b *)Line->topo;
  419. topo->left = 0;
  420. topo->right = 0;
  421. }
  422. }
  423. dig_free_plus_areas(plus);
  424. dig_spidx_free_areas(plus);
  425. dig_free_plus_isles(plus);
  426. dig_spidx_free_isles(plus);
  427. }
  428. if (plus->built >= GV_BUILD_BASE && build < GV_BUILD_BASE) {
  429. dig_free_plus_nodes(plus);
  430. dig_spidx_free_nodes(plus);
  431. dig_free_plus_lines(plus);
  432. dig_spidx_free_lines(plus);
  433. }
  434. plus->built = build;
  435. return 1;
  436. }
  437. Points = Vect_new_line_struct();
  438. APoints = Vect_new_line_struct();
  439. Cats = Vect_new_cats_struct();
  440. List = Vect_new_list();
  441. if (plus->built < GV_BUILD_BASE) {
  442. register int npoints, format, c;
  443. format = G_info_format();
  444. /*
  445. * We shall go through all primitives in coor file and
  446. * add new node for each end point to nodes structure
  447. * if the node with the same coordinates doesn't exist yet.
  448. */
  449. /* register lines, create nodes */
  450. Vect_rewind(Map);
  451. G_message(_("Registering primitives..."));
  452. i = 0;
  453. npoints = 0;
  454. while (1) {
  455. /* register line */
  456. type = Vect_read_next_line(Map, Points, Cats);
  457. /* Note: check for dead lines is not needed, because they are skipped by V1_read_next_line_nat() */
  458. if (type == -1) {
  459. G_warning(_("Unable to read vector map"));
  460. return 0;
  461. }
  462. else if (type == -2) {
  463. break;
  464. }
  465. npoints += Points->n_points;
  466. offset = Map->head.last_offset;
  467. G_debug(3, "Register line: offset = %lu", (unsigned long)offset);
  468. dig_line_box(Points, &box);
  469. line = dig_add_line(plus, type, Points, &box, offset);
  470. if (line == 1)
  471. Vect_box_copy(&(plus->box), &box);
  472. else
  473. Vect_box_extend(&(plus->box), &box);
  474. /* Add all categories to category index */
  475. if (build == GV_BUILD_ALL) {
  476. for (c = 0; c < Cats->n_cats; c++) {
  477. dig_cidx_add_cat(plus, Cats->field[c], Cats->cat[c],
  478. line, type);
  479. }
  480. if (Cats->n_cats == 0) /* add field 0, cat 0 */
  481. dig_cidx_add_cat(plus, 0, 0, line, type);
  482. }
  483. i++;
  484. if (i == 10000 && print_counter) {
  485. if (format == G_INFO_FORMAT_PLAIN)
  486. fprintf(stderr, "%d..", plus->n_lines);
  487. else
  488. fprintf(stderr, "%10d\b\b\b\b\b\b\b\b\b\b", plus->n_lines);
  489. i = 0;
  490. }
  491. }
  492. if ((print_counter) && format != G_INFO_FORMAT_PLAIN)
  493. fprintf(stderr, "\r");
  494. G_message(_("%d primitives registered"), plus->n_lines);
  495. G_message(_("%d vertices registered"), npoints);
  496. plus->built = GV_BUILD_BASE;
  497. }
  498. if (build < GV_BUILD_AREAS)
  499. return 1;
  500. if (plus->built < GV_BUILD_AREAS) {
  501. /* Build areas */
  502. /* Go through all bundaries and try to build area for both sides */
  503. G_important_message(_("Building areas..."));
  504. for (line = 1; line <= plus->n_lines; line++) {
  505. G_percent(line, plus->n_lines, 1);
  506. /* build */
  507. if (plus->Line[line] == NULL) {
  508. continue;
  509. } /* dead line */
  510. Line = plus->Line[line];
  511. if (Line->type != GV_BOUNDARY) {
  512. continue;
  513. }
  514. for (s = 0; s < 2; s++) {
  515. if (s == 0)
  516. side = GV_LEFT;
  517. else
  518. side = GV_RIGHT;
  519. G_debug(3, "Build area for line = %d, side = %d", line, side);
  520. Vect_build_line_area(Map, line, side);
  521. }
  522. }
  523. G_message(_("%d areas built"), plus->n_areas);
  524. G_message(_("%d isles built"), plus->n_isles);
  525. plus->built = GV_BUILD_AREAS;
  526. }
  527. if (build < GV_BUILD_ATTACH_ISLES)
  528. return 1;
  529. /* Attach isles to areas */
  530. if (plus->built < GV_BUILD_ATTACH_ISLES) {
  531. G_important_message(_("Attaching islands..."));
  532. for (i = 1; i <= plus->n_isles; i++) {
  533. G_percent(i, plus->n_isles, 1);
  534. Vect_attach_isle(Map, i);
  535. }
  536. plus->built = GV_BUILD_ATTACH_ISLES;
  537. }
  538. if (build < GV_BUILD_CENTROIDS)
  539. return 1;
  540. /* Attach centroids to areas */
  541. if (plus->built < GV_BUILD_CENTROIDS) {
  542. int nlines;
  543. struct P_topo_c *topo;
  544. G_important_message(_("Attaching centroids..."));
  545. nlines = Vect_get_num_lines(Map);
  546. for (line = 1; line <= nlines; line++) {
  547. G_percent(line, nlines, 1);
  548. Line = plus->Line[line];
  549. if (!Line)
  550. continue; /* Dead */
  551. if (Line->type != GV_CENTROID)
  552. continue;
  553. Vect_read_line(Map, Points, NULL, line);
  554. area = Vect_find_area(Map, Points->x[0], Points->y[0]);
  555. if (area > 0) {
  556. G_debug(3, "Centroid (line=%d) in area %d", line, area);
  557. Area = plus->Area[area];
  558. topo = (struct P_topo_c *)Line->topo;
  559. if (Area->centroid == 0) { /* first */
  560. Area->centroid = line;
  561. topo->area = area;
  562. }
  563. else { /* duplicate */
  564. topo->area = -area;
  565. }
  566. }
  567. }
  568. plus->built = GV_BUILD_CENTROIDS;
  569. }
  570. /* Add areas to category index */
  571. for (i = 1; i <= plus->n_areas; i++) {
  572. int c;
  573. if (plus->Area[i] == NULL)
  574. continue;
  575. if (plus->Area[i]->centroid > 0) {
  576. Vect_read_line(Map, NULL, Cats, plus->Area[i]->centroid);
  577. for (c = 0; c < Cats->n_cats; c++) {
  578. dig_cidx_add_cat(plus, Cats->field[c], Cats->cat[c], i,
  579. GV_AREA);
  580. }
  581. }
  582. if (plus->Area[i]->centroid == 0 || Cats->n_cats == 0) /* no centroid or no cats */
  583. dig_cidx_add_cat(plus, 0, 0, i, GV_AREA);
  584. }
  585. return 1;
  586. }