GRASS GIS 7 Programmer's Manual  7.5.svn(2018)-r72846
 All Data Structures Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
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 }
struct line_pnts * Vect_new_line_struct()
Creates and initializes a line_pnts structure.
Definition: line.c:45
off_t Vect_write_line(struct Map_info *Map, int type, const struct line_pnts *points, const struct line_cats *cats)
Writes a new feature.
int Vect_line_alive(const struct Map_info *Map, int line)
Check if feature is alive or dead (topological level required)
int n_values
Number of values in the list.
Definition: gis.h:676
void Vect_destroy_line_struct(struct line_pnts *p)
Frees all memory associated with a line_pnts structure, including the structure itself.
Definition: line.c:77
void Vect_destroy_cats_struct(struct line_cats *p)
Frees all memory associated with line_cats structure, including the struct itself.
Feature category info.
Definition: dig_structs.h:1702
Feature geometry info - coordinates.
Definition: dig_structs.h:1675
int G_debug(int level, const char *msg,...)
Print debugging message.
Definition: debug.c:65
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()
Creates and initializes line_cats structure.
List of integers.
Definition: gis.h:667
int Vect_read_line(const struct Map_info *Map, struct line_pnts *line_p, struct line_cats *line_c, int line)
Read vector feature (topological level required)
int * value
Array of values.
Definition: gis.h:672