GRASS GIS 8 Programmer's Manual  8.2.2dev(2023)-3d2c704037
vector/vedit/copy.c
Go to the documentation of this file.
1 /*!
2  \file lib/vector/vedit/copy.c
3 
4  \brief Vedit library - copy primitives
5 
6  (C) 2007-2008 by the GRASS Development Team
7 
8  This program is free software under the GNU General Public License
9  (>=v2). Read the file COPYING that comes with GRASS for details.
10 
11  \author Jachym Cepicky <jachym.cepicky gmail.com>
12  \author Martin Landa <landa.martin gmail.com>
13 */
14 
15 #include <grass/vedit.h>
16 
17 /*!
18  \brief Copy selected primitives
19 
20  \param Map pointer to Map_info copy to
21  \param FromMap vector map copy from (if not given use Map)
22  \param List list of selected primitives (to be copied)
23 
24  \return number of copied primitives
25  \return -1 on error
26 */
27 int Vedit_copy_lines(struct Map_info *Map, struct Map_info *FromMap,
28  struct ilist *List)
29 {
30  struct line_cats *Cats;
31  struct line_pnts *Points;
32  int i;
33  int type, line;
34  int nlines_copied;
35 
36  nlines_copied = 0;
37  Cats = Vect_new_cats_struct();
38  Points = Vect_new_line_struct();
39 
40  if (!FromMap) {
41  FromMap = Map;
42  }
43 
44  /* for each line, make a copy */
45  for (i = 0; i < List->n_values; i++) {
46  line = List->value[i];
47 
48  if (!Vect_line_alive(FromMap, line))
49  continue;
50 
51  type = Vect_read_line(FromMap, Points, Cats, line);
52 
53  G_debug(3, "Vedit_copy_lines(): type=%d, line=%d", type, line);
54 
55  /* copy */
56  if (Vect_write_line(Map, type, Points, Cats) < 0) {
57  return -1;
58  }
59 
60  nlines_copied++;
61  }
62 
65 
66  return nlines_copied;
67 }
int n_values
Number of values in the list.
Definition: gis.h:709
Feature category info.
Definition: dig_structs.h:1702
Feature geometry info - coordinates.
Definition: dig_structs.h:1675
struct line_pnts * Vect_new_line_struct(void)
Creates and initializes a line_pnts structure.
Definition: line.c:45
void Vect_destroy_cats_struct(struct line_cats *)
Frees all memory associated with line_cats structure, including the struct itself.
off_t Vect_write_line(struct Map_info *, int, const struct line_pnts *, const struct line_cats *)
Writes a new feature.
int Vedit_copy_lines(struct Map_info *Map, struct Map_info *FromMap, struct ilist *List)
Copy selected primitives.
Vector map info.
Definition: dig_structs.h:1259
struct line_cats * Vect_new_cats_struct(void)
Creates and initializes line_cats structure.
int Vect_line_alive(const struct Map_info *, int)
Check if feature is alive or dead (topological level required)
List of integers.
Definition: gis.h:700
int * value
Array of values.
Definition: gis.h:705
void Vect_destroy_line_struct(struct line_pnts *)
Frees all memory associated with a line_pnts structure, including the structure itself.
Definition: line.c:77
int Vect_read_line(const struct Map_info *, struct line_pnts *, struct line_cats *, int)
Read vector feature (topological level required)
int G_debug(int, const char *,...) __attribute__((format(printf