copy.c 1.5 KB

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