copy.c 1.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768
  1. /*!
  2. \file lib/vector/vedit/copy.c
  3. \brief Vedit library - copy primitives
  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 Jachym Cepicky <jachym.cepicky gmail.com>
  8. \author Martin Landa <landa.martin gmail.com>
  9. */
  10. #include <grass/vedit.h>
  11. /*!
  12. \brief Copy selected primitives
  13. \param Map pointer to Map_info copy to
  14. \param FromMap vector map copy from (if not given use Map)
  15. \param List list of selected primitives (to be copied)
  16. \return number of copied primitives
  17. \return -1 on error
  18. */
  19. int Vedit_copy_lines(struct Map_info *Map, struct Map_info *FromMap,
  20. struct ilist *List)
  21. {
  22. struct line_cats *Cats;
  23. struct line_pnts *Points;
  24. int i;
  25. int type, line;
  26. int nlines_copied;
  27. nlines_copied = 0;
  28. Cats = Vect_new_cats_struct();
  29. Points = Vect_new_line_struct();
  30. if (!FromMap) {
  31. FromMap = Map;
  32. }
  33. /* for each line, make a copy */
  34. for (i = 0; i < List->n_values; i++) {
  35. line = List->value[i];
  36. if (!Vect_line_alive(FromMap, line))
  37. continue;
  38. type = Vect_read_line(FromMap, Points, Cats, line);
  39. G_debug(3, "Vedit_copy_lines(): type=%d, line=%d", type, line);
  40. /* copy */
  41. if (Vect_write_line(Map, type, Points, Cats) < 0) {
  42. return -1;
  43. }
  44. nlines_copied++;
  45. }
  46. Vect_destroy_line_struct(Points);
  47. Vect_destroy_cats_struct(Cats);
  48. return nlines_copied;
  49. }