write.c 1.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980
  1. #include <grass/vector.h>
  2. #include <grass/glocale.h>
  3. void write_lines(struct Map_info *In, struct field_info *IFi, int *ALines,
  4. int *AAreas,
  5. struct Map_info *Out, int table_flag, int reverse_flag,
  6. int nfields, int *fields, int *ncats, int **cats)
  7. {
  8. int i, f, j, aline, nalines;
  9. int atype;
  10. struct line_pnts *APoints;
  11. struct line_cats *ACats;
  12. APoints = Vect_new_line_struct();
  13. ACats = Vect_new_cats_struct();
  14. for (i = 0; i < nfields; i++) {
  15. ncats[i] = 0;
  16. cats[i] =
  17. (int *)G_malloc(Vect_cidx_get_num_cats_by_index(&(In[0]), i) *
  18. sizeof(int));
  19. fields[i] = Vect_cidx_get_field_number(&(In[0]), i);
  20. }
  21. nalines = Vect_get_num_lines(In);
  22. G_message(_("Writing selected features..."));
  23. for (aline = 1; aline <= nalines; aline++) {
  24. G_debug(3, "aline = %d ALines[aline] = %d", aline, ALines[aline]);
  25. G_percent(aline, nalines, 2);
  26. if ((!reverse_flag && !(ALines[aline])))
  27. continue;
  28. atype = Vect_read_line(&(In[0]), APoints, ACats, aline);
  29. if ((reverse_flag && ALines[aline])) {
  30. if (atype == GV_BOUNDARY && AAreas) {
  31. int left, right, skipme;
  32. skipme = 1;
  33. Vect_get_line_areas(&(In[0]), aline, &left, &right);
  34. if (left < 0)
  35. left = Vect_get_isle_area(&(In[0]), abs(left));
  36. if (left > 0 && !AAreas[left])
  37. skipme = 0;
  38. if (right < 0)
  39. right = Vect_get_isle_area(&(In[0]), abs(right));
  40. if (right > 0 && !AAreas[right])
  41. skipme = 0;
  42. if (skipme)
  43. continue;
  44. }
  45. else
  46. continue;
  47. }
  48. Vect_write_line(Out, atype, APoints, ACats);
  49. if (!table_flag && (IFi != NULL)) {
  50. for (i = 0; i < ACats->n_cats; i++) {
  51. f = -1;
  52. for (j = 0; j < nfields; j++) { /* find field */
  53. if (fields[j] == ACats->field[i]) {
  54. f = j;
  55. break;
  56. }
  57. }
  58. if (f >= 0) {
  59. cats[f][ncats[f]] = ACats->cat[i];
  60. ncats[f]++;
  61. }
  62. }
  63. }
  64. }
  65. Vect_destroy_line_struct(APoints);
  66. Vect_destroy_cats_struct(ACats);
  67. }