GRASS Programmer's Manual  6.5.svn(2014)-r66266
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Pages
write_nat.c
Go to the documentation of this file.
1 
26 #include <stdio.h>
27 #include <stdlib.h>
28 #include <math.h>
29 
30 #include <grass/gis.h>
31 #include <grass/Vect.h>
32 #include <grass/glocale.h>
33 
40 static void delete_area_cats_from_cidx(struct Map_info *Map, int area)
41 {
42  int i;
43  P_AREA *Area;
44  static struct line_cats *Cats = NULL;
45 
46  G_debug(3, "delete_area_cats_from_cidx() area = %d", area);
47 
48  Area = Map->plus.Area[area];
49  if (!Area)
50  G_fatal_error(_("%s: Area %d does not exist"),
51  "delete_area_cats_from_cidx()", area);
52 
53  if (Area->centroid == 0) /* no centroid found */
54  return;
55 
56  if (!Cats)
57  Cats = Vect_new_cats_struct();
58 
59  V2_read_line_nat(Map, NULL, Cats, Area->centroid);
60 
61  for (i = 0; i < Cats->n_cats; i++) {
62  dig_cidx_del_cat(&(Map->plus), Cats->field[i], Cats->cat[i], area,
63  GV_AREA);
64  }
65 }
66 
73 static void add_area_cats_to_cidx(struct Map_info *Map, int area)
74 {
75  int i;
76  P_AREA *Area;
77  static struct line_cats *Cats = NULL;
78 
79  G_debug(3, "add_area_cats_to_cidx() area = %d", area);
80 
81  Area = Map->plus.Area[area];
82  if (!Area)
83  G_fatal_error(_("%s: Area %d does not exist"),
84  "add_area_cats_to_cidx():", area);
85 
86  if (Area->centroid == 0) /* no centroid found */
87  return;
88 
89  if (!Cats)
90  Cats = Vect_new_cats_struct();
91 
92  V2_read_line_nat(Map, NULL, Cats, Area->centroid);
93 
94  for (i = 0; i < Cats->n_cats; i++) {
95  dig_cidx_add_cat_sorted(&(Map->plus), Cats->field[i], Cats->cat[i],
96  area, GV_AREA);
97  }
98 }
99 
131 static void add_line_to_topo(struct Map_info *Map, int line,
132  struct line_pnts *points, struct line_cats *cats)
133 {
134  int first, s, n, i;
135  int type, node, next_line, area, side, sel_area, new_area[2];
136 
137  struct Plus_head *plus;
138  P_LINE *Line, *NLine;
139  P_NODE *Node;
140  P_AREA *Area;
141 
142  BOUND_BOX box, abox;
143 
144  plus = &(Map->plus);
145  Line = plus->Line[line];
146  type = Line->type;
147 
148  if (plus->built >= GV_BUILD_AREAS) {
149  if (type == GV_BOUNDARY) {
150  /* Delete neighbour areas/isles */
151  first = 1;
152  for (s = 1; s < 3; s++) { /* for each node */
153  if (s == 1)
154  node = Line->N1; /* Node 1 */
155  else
156  node = Line->N2;
157  G_debug(3,
158  " delete neighbour areas/iseles: side = %d node = %d",
159  s, node);
160  Node = plus->Node[node];
161  n = 0;
162  for (i = 0; i < Node->n_lines; i++) {
163  NLine = plus->Line[abs(Node->lines[i])];
164  if (NLine->type == GV_BOUNDARY)
165  n++;
166  }
167 
168  G_debug(3, " number of boundaries at node = %d", n);
169  if (n > 2) { /* more than 2 boundaries at node ( >= 2 old + 1 new ) */
170  /* Line above (to the right), it is enough to check to the right, because if area/isle
171  * exists it is the same to the left */
172  if (s == 1)
173  next_line =
174  dig_angle_next_line(plus, line, GV_RIGHT,
175  GV_BOUNDARY);
176  else
177  next_line =
178  dig_angle_next_line(plus, -line, GV_RIGHT,
179  GV_BOUNDARY);
180 
181  if (next_line != 0) { /* there is a boundary to the right */
182  NLine = plus->Line[abs(next_line)];
183  if (next_line > 0) /* the boundary is connected by 1. node */
184  area = NLine->right; /* we are interested just in this side (close to our line) */
185  else if (next_line < 0) /* the boundary is connected by 2. node */
186  area = NLine->left;
187 
188  G_debug(3, " next_line = %d area = %d", next_line,
189  area);
190  if (area > 0) { /* is area */
191  Vect_get_area_box(Map, area, &box);
192  if (first) {
193  Vect_box_copy(&abox, &box);
194  first = 0;
195  }
196  else
197  Vect_box_extend(&abox, &box);
198 
199  if (plus->update_cidx) {
200  delete_area_cats_from_cidx(Map, area);
201  }
202  dig_del_area(plus, area);
203  }
204  else if (area < 0) { /* is isle */
205  dig_del_isle(plus, -area);
206  }
207  }
208  }
209  }
210  /* Build new areas/isles. Thas true that we deleted also adjacent areas/isles, but if
211  * they form new one our boundary must participate, so we need to build areas/isles
212  * just for our boundary */
213  for (s = 1; s < 3; s++) {
214  if (s == 1)
215  side = GV_LEFT;
216  else
217  side = GV_RIGHT;
218  G_debug(3, " build area/isle on side = %d", side);
219 
220  G_debug(3, "Build area for line = %d, side = %d", line, side);
221  area = Vect_build_line_area(Map, line, side);
222  G_debug(3, "Build area for line = %d, side = %d", line, side);
223  if (area > 0) { /* area */
224  Vect_get_area_box(Map, area, &box);
225  if (first) {
226  Vect_box_copy(&abox, &box);
227  first = 0;
228  }
229  else
230  Vect_box_extend(&abox, &box);
231  }
232  else if (area < 0) {
233  /* isle -> must be attached -> add to abox */
234  Vect_get_isle_box(Map, -area, &box);
235  if (first) {
236  Vect_box_copy(&abox, &box);
237  first = 0;
238  }
239  else
240  Vect_box_extend(&abox, &box);
241  }
242  new_area[s - 1] = area;
243  }
244  /* Reattach all centroids/isles in deleted areas + new area.
245  * Because isles are selected by box it covers also possible new isle created above */
246  if (!first) { /* i.e. old area/isle was deleted or new one created */
247  /* Reattache isles */
248  if (plus->built >= GV_BUILD_ATTACH_ISLES)
249  Vect_attach_isles(Map, &abox);
250 
251  /* Reattach centroids */
252  if (plus->built >= GV_BUILD_CENTROIDS)
253  Vect_attach_centroids(Map, &abox);
254  }
255  /* Add to category index */
256  if (plus->update_cidx) {
257  for (s = 1; s < 3; s++) {
258  if (new_area[s - 1] > 0) {
259  add_area_cats_to_cidx(Map, new_area[s - 1]);
260  }
261  }
262  }
263  }
264  }
265 
266  /* Attach centroid */
267  if (plus->built >= GV_BUILD_CENTROIDS) {
268  if (type == GV_CENTROID) {
269  sel_area = Vect_find_area(Map, points->x[0], points->y[0]);
270  G_debug(3, " new centroid %d is in area %d", line, sel_area);
271  if (sel_area > 0) {
272  Area = plus->Area[sel_area];
273  Line = plus->Line[line];
274  if (Area->centroid == 0) { /* first centroid */
275  G_debug(3, " first centroid -> attach to area");
276  Area->centroid = line;
277  Line->left = sel_area;
278  if (plus->update_cidx) {
279  add_area_cats_to_cidx(Map, sel_area);
280  }
281  }
282  else { /* duplicate centroid */
283  G_debug(3,
284  " duplicate centroid -> do not attach to area");
285  Line->left = -sel_area;
286  }
287  }
288  }
289  }
290 
291  /* Add cetegory index */
292  for (i = 0; i < cats->n_cats; i++) {
293  dig_cidx_add_cat_sorted(plus, cats->field[i], cats->cat[i], line,
294  type);
295  }
296 
297  return;
298 }
299 
300 long V1__rewrite_line_nat(struct Map_info *Map, long offset, int type,
301  struct line_pnts *points, struct line_cats *cats);
302 
314 long V1_write_line_nat(struct Map_info *Map,
315  int type, struct line_pnts *points, struct line_cats *cats)
316 {
317  long offset;
318 
319  if (dig_fseek(&(Map->dig_fp), 0L, SEEK_END) == -1) /* set to end of file */
320  return -1;
321 
322  offset = dig_ftell(&(Map->dig_fp));
323  if (offset == -1)
324  return -1;
325 
326  return V1__rewrite_line_nat(Map, offset, type, points, cats);
327 }
328 
340 long V2_write_line_nat(struct Map_info *Map,
341  int type, struct line_pnts *points, struct line_cats *cats)
342 {
343  int line;
344  long offset;
345  struct Plus_head *plus;
346  BOUND_BOX box;
347 
348  line = 0;
349 
350  G_debug(3, "V2_write_line_nat()");
351  offset = V1_write_line_nat(Map, type, points, cats);
352  if (offset < 0)
353  return -1;
354 
355  /* Update topology */
356  plus = &(Map->plus);
357  /* Add line */
358  if (plus->built >= GV_BUILD_BASE) {
359  line = dig_add_line(plus, type, points, offset);
360  G_debug(3, " line added to topo with id = %d", line);
361  dig_line_box(points, &box);
362  dig_line_set_box(plus, line, &box);
363  if (line == 1)
364  Vect_box_copy(&(plus->box), &box);
365  else
366  Vect_box_extend(&(plus->box), &box);
367  }
368 
369  add_line_to_topo(Map,
370  line, points, cats);
371 
372  G_debug(3, "updated lines : %d , updated nodes : %d", plus->n_uplines,
373  plus->n_upnodes);
374 
375  return line;
376 }
377 
397 long V1_rewrite_line_nat(struct Map_info *Map,
398  long offset,
399  int type,
400  struct line_pnts *points, struct line_cats *cats)
401 {
402  int old_type;
403  static struct line_pnts *old_points = NULL;
404  static struct line_cats *old_cats = NULL;
405  long new_offset;
406 
407  /* TODO: enable points and cats == NULL */
408 
409  /* First compare numbers of points and cats with tha old one */
410  if (!old_points) {
411  old_points = Vect_new_line_struct();
412  old_cats = Vect_new_cats_struct();
413  }
414 
415  old_type = V1_read_line_nat(Map, old_points, old_cats, offset);
416  if (old_type == -1)
417  return (-1); /* error */
418 
419  if (old_type != -2 /* EOF -> write new line */
420  && points->n_points == old_points->n_points
421  && cats->n_cats == old_cats->n_cats
422  && (((type & GV_POINTS) && (old_type & GV_POINTS))
423  || ((type & GV_LINES) && (old_type & GV_LINES)))) {
424 
425  /* equal -> overwrite the old */
426  return V1__rewrite_line_nat(Map, offset, type, points, cats);
427  }
428  else {
429  /* differ -> delete the old and append new */
430  /* delete old */
431  V1_delete_line_nat(Map, offset);
432 
433  /* write new */
434  if (dig_fseek(&(Map->dig_fp), 0L, SEEK_END) == -1) /* end of file */
435  return -1;
436 
437  new_offset = dig_ftell(&(Map->dig_fp));
438  if (new_offset == -1)
439  return -1;
440 
441  return V1__rewrite_line_nat(Map, new_offset, type, points, cats);
442  }
443 }
444 
459 int V2_rewrite_line_nat(struct Map_info *Map,
460  int line,
461  int type,
462  struct line_pnts *points, struct line_cats *cats)
463 {
464  /* TODO: this is just quick shortcut because we have already V2_delete_nat()
465  * and V2_write_nat() this function first deletes old line
466  * and then writes new one. It is not very effective if number of points
467  * and cats was not changed or topology is not changed (nodes not moved,
468  * angles not changed etc.) */
469 
470  V2_delete_line_nat(Map, line);
471 
472  return (V2_write_line_nat(Map, type, points, cats));
473 }
474 
487 long V1__rewrite_line_nat(struct Map_info *Map,
488  long offset,
489  int type,
490  struct line_pnts *points, struct line_cats *cats)
491 {
492  int i, n_points;
493  char rhead, nc;
494  short field;
495  GVFILE *dig_fp;
496 
497  dig_set_cur_port(&(Map->head.port));
498  dig_fp = &(Map->dig_fp);
499 
500  if (dig_fseek(dig_fp, offset, 0) == -1)
501  return -1;
502 
503  /* first byte: 0 bit: 1 - alive, 0 - dead
504  * 1 bit: 1 - categories, 0 - no category
505  * 2-3 bit: store type
506  * 4-5 bit: reserved for store type expansion
507  * 6-7 bit: not used
508  */
509 
510  rhead = (char)dig_type_to_store(type);
511  rhead <<= 2;
512  if (cats->n_cats > 0) {
513  rhead |= 0x02;
514  }
515  rhead |= 0x01; /* written/rewritten is always alive */
516 
517  if (0 >= dig__fwrite_port_C(&rhead, 1, dig_fp)) {
518  return -1;
519  }
520 
521  if (cats->n_cats > 0) {
522  if (Map->head.Version_Minor == 1) { /* coor format 5.1 */
523  if (0 >= dig__fwrite_port_I(&(cats->n_cats), 1, dig_fp))
524  return -1;
525  }
526  else { /* coor format 5.0 */
527  nc = (char)cats->n_cats;
528  if (0 >= dig__fwrite_port_C(&nc, 1, dig_fp))
529  return -1;
530  }
531 
532  if (cats->n_cats > 0) {
533  if (Map->head.Version_Minor == 1) { /* coor format 5.1 */
534  if (0 >=
535  dig__fwrite_port_I(cats->field, cats->n_cats, dig_fp))
536  return -1;
537  }
538  else { /* coor format 5.0 */
539  for (i = 0; i < cats->n_cats; i++) {
540  field = (short)cats->field[i];
541  if (0 >= dig__fwrite_port_S(&field, 1, dig_fp))
542  return -1;
543  }
544  }
545  if (0 >= dig__fwrite_port_I(cats->cat, cats->n_cats, dig_fp))
546  return -1;
547  }
548  }
549 
550  if (type & GV_POINTS) {
551  n_points = 1;
552  }
553  else {
554  n_points = points->n_points;
555  if (0 >= dig__fwrite_port_I(&n_points, 1, dig_fp))
556  return -1;
557  }
558 
559  if (0 >= dig__fwrite_port_D(points->x, n_points, dig_fp))
560  return -1;
561  if (0 >= dig__fwrite_port_D(points->y, n_points, dig_fp))
562  return -1;
563 
564  if (Map->head.with_z) {
565  if (0 >= dig__fwrite_port_D(points->z, n_points, dig_fp))
566  return -1;
567  }
568 
569  if (0 != dig_fflush(dig_fp))
570  return -1;
571 
572  return offset;
573 }
574 
584 int V1_delete_line_nat(struct Map_info *Map, long offset)
585 {
586  char rhead;
587  GVFILE *dig_fp;
588 
589  G_debug(3, "V1_delete_line_nat(), offset = %ld", offset);
590 
591  dig_set_cur_port(&(Map->head.port));
592  dig_fp = &(Map->dig_fp);
593 
594  if (dig_fseek(dig_fp, offset, 0) == -1)
595  return -1;
596 
597  /* read old */
598  if (0 >= dig__fread_port_C(&rhead, 1, dig_fp))
599  return (-1);
600 
601  rhead &= 0xFE;
602 
603  if (dig_fseek(dig_fp, offset, 0) == -1)
604  return -1;
605 
606  if (0 >= dig__fwrite_port_C(&rhead, 1, dig_fp))
607  return -1;
608 
609  if (0 != dig_fflush(dig_fp))
610  return -1;
611 
612  return 0;
613 }
614 
624 int V2_delete_line_nat(struct Map_info *Map, int line)
625 {
626  int ret, i, side, type = 0, first = 0, next_line, area;
627  P_LINE *Line = NULL;
628  P_AREA *Area;
629  struct Plus_head *plus;
630  BOUND_BOX box, abox;
631  int adjacent[4], n_adjacent = 0;
632  static struct line_cats *Cats = NULL;
633 
634  G_debug(3, "V2_delete_line_nat(), line = %d", line);
635 
636  plus = &(Map->plus);
637 
638  if (plus->built >= GV_BUILD_BASE) {
639  Line = Map->plus.Line[line];
640 
641  if (Line == NULL)
642  G_fatal_error(_("Attempt to delete dead feature"));
643  type = Line->type;
644  }
645 
646  if (!Cats) {
647  Cats = Vect_new_cats_struct();
648  }
649 
650  /* Update category index */
651  if (plus->update_cidx) {
652  type = V2_read_line_nat(Map, NULL, Cats, line);
653 
654  for (i = 0; i < Cats->n_cats; i++) {
655  dig_cidx_del_cat(plus, Cats->field[i], Cats->cat[i], line, type);
656  }
657  }
658 
659  /* delete the line from coor */
660  ret = V1_delete_line_nat(Map, Line->offset);
661 
662  if (ret == -1) {
663  return ret;
664  }
665 
666  /* Update topology */
667  if (plus->built >= GV_BUILD_AREAS && type == GV_BOUNDARY) {
668  /* Store adjacent boundaries at nodes (will be used to rebuild area/isle) */
669  /* Adjacent are stored: > 0 - we want right side; < 0 - we want left side */
670  n_adjacent = 0;
671 
672  next_line = dig_angle_next_line(plus, line, GV_RIGHT, GV_BOUNDARY);
673  if (next_line != 0 && abs(next_line) != line) {
674  /* N1, to the right -> we want the right side for > 0 and left for < 0 */
675  adjacent[n_adjacent] = next_line;
676  n_adjacent++;
677  }
678  next_line = dig_angle_next_line(plus, line, GV_LEFT, GV_BOUNDARY);
679  if (next_line != 0 && abs(next_line) != line) {
680  /* N1, to the left -> we want the left side for > 0 and right for < 0 */
681  adjacent[n_adjacent] = -next_line;
682  n_adjacent++;
683  }
684  next_line = dig_angle_next_line(plus, -line, GV_RIGHT, GV_BOUNDARY);
685  if (next_line != 0 && abs(next_line) != line) {
686  /* N2, to the right -> we want the right side for > 0 and left for < 0 */
687  adjacent[n_adjacent] = next_line;
688  n_adjacent++;
689  }
690  next_line = dig_angle_next_line(plus, -line, GV_LEFT, GV_BOUNDARY);
691  if (next_line != 0 && abs(next_line) != line) {
692  /* N2, to the left -> we want the left side for > 0 and right for < 0 */
693  adjacent[n_adjacent] = -next_line;
694  n_adjacent++;
695  }
696 
697  /* Delete area(s) and islands this line forms */
698  first = 1;
699  if (Line->left > 0) { /* delete area */
700  Vect_get_area_box(Map, Line->left, &box);
701  if (first) {
702  Vect_box_copy(&abox, &box);
703  first = 0;
704  }
705  else
706  Vect_box_extend(&abox, &box);
707 
708  if (plus->update_cidx) {
709  delete_area_cats_from_cidx(Map, Line->left);
710  }
711  dig_del_area(plus, Line->left);
712  }
713  else if (Line->left < 0) { /* delete isle */
714  dig_del_isle(plus, -Line->left);
715  }
716  if (Line->right > 0) { /* delete area */
717  Vect_get_area_box(Map, Line->right, &box);
718  if (first) {
719  Vect_box_copy(&abox, &box);
720  first = 0;
721  }
722  else
723  Vect_box_extend(&abox, &box);
724 
725  if (plus->update_cidx) {
726  delete_area_cats_from_cidx(Map, Line->right);
727  }
728  dig_del_area(plus, Line->right);
729  }
730  else if (Line->right < 0) { /* delete isle */
731  dig_del_isle(plus, -Line->right);
732  }
733  }
734 
735  /* Delete reference from area */
736  if (plus->built >= GV_BUILD_CENTROIDS && type == GV_CENTROID) {
737  if (Line->left > 0) {
738  G_debug(3, "Remove centroid %d from area %d", line, Line->left);
739  if (plus->update_cidx) {
740  delete_area_cats_from_cidx(Map, Line->left);
741  }
742  Area = Map->plus.Area[Line->left];
743  Area->centroid = 0;
744  }
745  }
746 
747  /* delete the line from topo */
748  dig_del_line(plus, line);
749 
750  /* Rebuild areas/isles and attach centroids and isles */
751  if (plus->built >= GV_BUILD_AREAS && type == GV_BOUNDARY) {
752  int *new_areas, nnew_areas;
753 
754  nnew_areas = 0;
755  new_areas = (int *)G_malloc(2 * n_adjacent * sizeof(int));
756  /* Rebuild areas/isles */
757  for (i = 0; i < n_adjacent; i++) {
758  if (adjacent[i] > 0)
759  side = GV_RIGHT;
760  else
761  side = GV_LEFT;
762 
763  G_debug(3, "Build area for line = %d, side = %d", adjacent[i],
764  side);
765 
766  area = Vect_build_line_area(Map, abs(adjacent[i]), side);
767  if (area > 0) { /* area */
768  Vect_get_area_box(Map, area, &box);
769  if (first) {
770  Vect_box_copy(&abox, &box);
771  first = 0;
772  }
773  else
774  Vect_box_extend(&abox, &box);
775 
776  new_areas[nnew_areas] = area;
777  nnew_areas++;
778  }
779  else if (area < 0) {
780  /* isle -> must be attached -> add to abox */
781  Vect_get_isle_box(Map, -area, &box);
782  if (first) {
783  Vect_box_copy(&abox, &box);
784  first = 0;
785  }
786  else
787  Vect_box_extend(&abox, &box);
788  }
789  }
790  /* Reattach all centroids/isles in deleted areas + new area.
791  * Because isles are selected by box it covers also possible new isle created above */
792  if (!first) { /* i.e. old area/isle was deleted or new one created */
793  /* Reattache isles */
794  if (plus->built >= GV_BUILD_ATTACH_ISLES)
795  Vect_attach_isles(Map, &abox);
796 
797  /* Reattach centroids */
798  if (plus->built >= GV_BUILD_CENTROIDS)
799  Vect_attach_centroids(Map, &abox);
800  }
801 
802  if (plus->update_cidx) {
803  for (i = 0; i < nnew_areas; i++) {
804  add_area_cats_to_cidx(Map, new_areas[i]);
805  }
806  }
807  }
808 
809  G_debug(3, "updated lines : %d , updated nodes : %d", plus->n_uplines,
810  plus->n_upnodes);
811  return ret;
812 }
813 
823 int V1_restore_line_nat(struct Map_info *Map, long offset)
824 {
825  char rhead;
826  GVFILE *dig_fp;
827 
828  G_debug(3, "V1_restore_line_nat(), offset = %ld", offset);
829 
830  dig_set_cur_port(&(Map->head.port));
831  dig_fp = &(Map->dig_fp);
832 
833  if (dig_fseek(dig_fp, offset, 0) == -1)
834  return -1;
835 
836  /* read old */
837  if (0 >= dig__fread_port_C(&rhead, 1, dig_fp))
838  return (-1);
839 
840  /* mark as alive */
841  rhead |= 1;
842 
843  /* write new */
844  if (dig_fseek(dig_fp, offset, 0) == -1)
845  return -1;
846 
847  if (0 >= dig__fwrite_port_C(&rhead, 1, dig_fp))
848  return -1;
849 
850  if (0 != dig_fflush(dig_fp))
851  return -1;
852 
853  return 0;
854 }
855 
866 int V2_restore_line_nat(struct Map_info *Map, int line, long offset)
867 {
868  int i, ret, type;
869  P_LINE *Line;
870  struct Plus_head *plus;
871  BOUND_BOX box;
872 
873  static struct line_pnts *points = NULL;
874  static struct line_cats *cats = NULL;
875 
876  Line = NULL;
877  type = 0;
878 
879  G_debug(3, "V2_restore_line_nat(), line = %d", line);
880 
881  plus = &(Map->plus);
882 
883  if (plus->built >= GV_BUILD_BASE) {
884  Line = Map->plus.Line[line];
885 
886  if (Line != NULL)
887  G_fatal_error(_("Attempt to restore alive feature"));
888  }
889 
890  if (!points) {
891  points = Vect_new_line_struct();
892  }
893 
894  if (!cats) {
895  cats = Vect_new_cats_struct();
896  }
897 
898  /* restore the line in coor */
899  ret = V1_restore_line_nat(Map, offset);
900 
901  if (ret == -1) {
902  return ret;
903  }
904 
905  /* read feature geometry */
906  type = V1_read_line_nat(Map, points, cats, offset);
907  if (type < 0) {
908  return -1;
909  }
910 
911  /* update category index */
912  if (plus->update_cidx) {
913  for (i = 0; i < cats->n_cats; i++) {
914  dig_cidx_add_cat(plus, cats->field[i], cats->cat[i], line, type);
915  }
916  }
917 
918  /* restore the line from topo */
919  if (plus->built >= GV_BUILD_BASE) {
920  dig_restore_line(plus, line, type, points, offset);
921  G_debug(3, " line restored in topo with id = %d", line);
922  dig_line_box(points, &box);
923  dig_line_set_box(plus, line, &box);
924  Vect_box_extend(&(plus->box), &box);
925  }
926 
927  add_line_to_topo(Map,
928  line, points, cats);
929 
930  G_debug(3, "updated lines : %d , updated nodes : %d", plus->n_uplines,
931  plus->n_upnodes);
932 
933 
934  return ret;
935 }
int dig_set_cur_port(struct Port_info *port)
Definition: portable.c:640
int V2_restore_line_nat(struct Map_info *Map, int line, long offset)
Restores feature (topology level)
Definition: write_nat.c:866
int dig_del_isle(struct Plus_head *plus, int isle)
Delete island from Plus_head structure.
Definition: plus_area.c:746
int Vect_build_line_area(struct Map_info *Map, int iline, int side)
Build area on given side of line (GV_LEFT or GV_RIGHT)
Definition: build_nat.c:37
int dig_cidx_add_cat_sorted(struct Plus_head *Plus, int field, int cat, int line, int type)
int dig_line_box(struct line_pnts *Points, BOUND_BOX *Box)
Definition: diglib/box.c:24
struct line_pnts * Vect_new_line_struct()
Creates and initializes a struct line_pnts.
Definition: line.c:57
int dig_del_area(struct Plus_head *plus, int area)
Delete area from Plus_head structure.
Definition: plus_area.c:341
int dig_add_line(struct Plus_head *plus, int type, struct line_pnts *Points, long offset)
Add new line to Plus_head structure.
Definition: plus_line.c:102
long V1__rewrite_line_nat(struct Map_info *Map, long offset, int type, struct line_pnts *points, struct line_cats *cats)
Rewrites feature at the given offset.
Definition: write_nat.c:487
Definition: index.h:56
int V2_read_line_nat(struct Map_info *Map, struct line_pnts *line_p, struct line_cats *line_c, int line)
Reads any specified line, this is NOT affected by constraints.
Definition: read_nat.c:124
int dig__fwrite_port_D(double *buf, int cnt, GVFILE *fp)
Definition: portable.c:370
int dig_angle_next_line(struct Plus_head *plus, plus_t current_line, int side, int type)
Find number line of next angle to follow an line.
Definition: plus_area.c:474
int Vect_get_area_box(struct Map_info *Map, int area, BOUND_BOX *Box)
Get boundary box of area.
Definition: Vlib/box.c:247
tuple box
surface = wx.CheckBox(parent = panel, id = wx.ID_ANY, label = _(&quot;Follow source viewpoint&quot;)) pageSizer...
Definition: tools.py:1527
int dig__fwrite_port_I(int *buf, int cnt, GVFILE *fp)
Definition: portable.c:465
int dig_fseek(GVFILE *file, long offset, int whence)
Set GVFILE position.
Definition: file.c:60
int Vect_box_extend(BOUND_BOX *A, BOUND_BOX *B)
Extend box A by box B.
Definition: Vlib/box.c:93
int Vect_find_area(struct Map_info *Map, double x, double y)
Find the nearest area.
int dig_cidx_add_cat(struct Plus_head *Plus, int field, int cat, int line, int type)
Definition: diglib/cindex.c:68
long V2_write_line_nat(struct Map_info *Map, int type, struct line_pnts *points, struct line_cats *cats)
Writes feature to &#39;coor&#39; file (topology level)
Definition: write_nat.c:340
long V1_write_line_nat(struct Map_info *Map, int type, struct line_pnts *points, struct line_cats *cats)
Writes feature to &#39;coor&#39; file.
Definition: write_nat.c:314
int Vect_box_copy(BOUND_BOX *A, BOUND_BOX *B)
Copy box B to box A.
Definition: Vlib/box.c:72
int GV_LINES
Definition: vdigit/main.py:24
int Vect_attach_centroids(struct Map_info *Map, BOUND_BOX *box)
(Re)Attach centroids to areas in given box
Definition: build_nat.c:333
long V1_rewrite_line_nat(struct Map_info *Map, long offset, int type, struct line_pnts *points, struct line_cats *cats)
Rewrites feature at the given offset.
Definition: write_nat.c:397
int dig_del_line(struct Plus_head *plus, int line)
Delete line from Plus_head structure.
Definition: plus_line.c:183
int dig_restore_line(struct Plus_head *plus, int lineid, int type, struct line_pnts *Points, long offset)
Restore line in Plus_head structure.
Definition: plus_line.c:157
int V2_rewrite_line_nat(struct Map_info *Map, int line, int type, struct line_pnts *points, struct line_cats *cats)
Rewrites feature (topology level)
Definition: write_nat.c:459
int first
Definition: form/open.c:25
if(!YY_CURRENT_BUFFER)
Definition: lex.yy.c:799
int Vect_get_isle_box(struct Map_info *Map, int isle, BOUND_BOX *Box)
Get boundary box of isle.
Definition: Vlib/box.c:286
int dig__fread_port_C(char *buf, int cnt, GVFILE *fp)
Definition: portable.c:347
struct line_cats * Vect_new_cats_struct()
Creates and initializes line_cats structure.
return NULL
Definition: dbfopen.c:1394
int dig_fflush(GVFILE *file)
Flush GVFILE.
Definition: file.c:102
int V1_read_line_nat(struct Map_info *Map, struct line_pnts *Points, struct line_cats *Cats, long offset)
Read line from coor file on given offset.
Definition: read_nat.c:48
int dig_type_to_store(int type)
Convert type to store type.
tuple Map
Definition: render.py:1310
int Vect_attach_isles(struct Map_info *Map, BOUND_BOX *box)
(Re)Attach isles to areas in given box
Definition: build_nat.c:295
int G_debug(int level, const char *msg,...)
Print debugging message.
Definition: gis/debug.c:51
int V1_delete_line_nat(struct Map_info *Map, long offset)
Deletes feature at the given offset.
Definition: write_nat.c:584
int dig__fwrite_port_C(char *buf, int cnt, GVFILE *fp)
Definition: portable.c:558
int dig__fwrite_port_S(short *buf, int cnt, GVFILE *fp)
Definition: portable.c:508
int G_fatal_error(const char *msg,...)
Print a fatal error message to stderr.
int dig_cidx_del_cat(struct Plus_head *Plus, int field, int cat, int line, int type)
long dig_ftell(GVFILE *file)
Get GVFILE position.
Definition: file.c:36
int n
Definition: dataquad.c:291
int dig_line_set_box(struct Plus_head *plus, plus_t line, BOUND_BOX *Box)
Set line bounding box.
Definition: plus_line.c:318
int V2_delete_line_nat(struct Map_info *Map, int line)
Deletes feature (topology level).
Definition: write_nat.c:624
int V1_restore_line_nat(struct Map_info *Map, long offset)
Restores feature at the given offset.
Definition: write_nat.c:823