flip.c 1.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768
  1. /**
  2. \file vector/vedit/flip.c
  3. \brief Vedit library - flip lines
  4. (C) 2007-2008 by the GRASS Development Team
  5. This program is free software under the GNU General Public License
  6. (>=v2). Read the file COPYING that comes with GRASS for details.
  7. \author Martin Landa <landa.martin gmail.com>
  8. \date 2007-2008
  9. */
  10. #include <grass/vedit.h>
  11. /**
  12. \brief Flip direction of selected lines
  13. \param Map vector map
  14. \param List list of selected lines
  15. \return number of modified lines
  16. \return -1 on error
  17. */
  18. int Vedit_flip_lines(struct Map_info *Map, struct ilist *List)
  19. {
  20. struct line_cats *Cats;
  21. struct line_pnts *Points;
  22. int i, line, type;
  23. int nlines_flipped;
  24. nlines_flipped = 0;
  25. Points = Vect_new_line_struct();
  26. Cats = Vect_new_cats_struct();
  27. for (i = 0; i < List->n_values; i++) {
  28. line = List->value[i];
  29. if (!Vect_line_alive(Map, line))
  30. continue;
  31. type = Vect_read_line(Map, Points, Cats, line);
  32. if (!(type & GV_LINES))
  33. continue;
  34. Vect_line_reverse(Points);
  35. if (Vect_rewrite_line(Map, line, type, Points, Cats) < 0) {
  36. return -1;
  37. }
  38. G_debug(3, "Vedit_flip_lines(): line=%d", line);
  39. nlines_flipped++;
  40. }
  41. /* destroy structures */
  42. Vect_destroy_line_struct(Points);
  43. Vect_destroy_cats_struct(Cats);
  44. return nlines_flipped;
  45. }