GRASS GIS 7 Programmer's Manual  7.5.svn(2018)-r72114
 All Data Structures Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
flip.c
Go to the documentation of this file.
1 /*!
2  \file lib/vector/vedit/flip.c
3 
4  \brief Vedit library - flip lines
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 Martin Landa <landa.martin gmail.com>
12 */
13 
14 #include <grass/vedit.h>
15 
16 /*!
17  \brief Flip direction of selected lines
18 
19  \param Map pointer to Map_info
20  \param List list of selected lines
21 
22  \return number of modified lines
23  \return -1 on error
24 */
25 int Vedit_flip_lines(struct Map_info *Map, struct ilist *List)
26 {
27  struct line_cats *Cats;
28  struct line_pnts *Points;
29  int i, line, type;
30  int nlines_flipped;
31 
32  nlines_flipped = 0;
33 
34  Points = Vect_new_line_struct();
35  Cats = Vect_new_cats_struct();
36 
37  for (i = 0; i < List->n_values; i++) {
38  line = List->value[i];
39 
40  if (!Vect_line_alive(Map, line))
41  continue;
42 
43  type = Vect_read_line(Map, Points, Cats, line);
44 
45  if (!(type & GV_LINES))
46  continue;
47 
48  Vect_line_reverse(Points);
49 
50  if (Vect_rewrite_line(Map, line, type, Points, Cats) < 0) {
51  return -1;
52  }
53 
54  G_debug(3, "Vedit_flip_lines(): line=%d", line);
55 
56  nlines_flipped++;
57  }
58 
59  /* destroy structures */
62 
63  return nlines_flipped;
64 }
int Vedit_flip_lines(struct Map_info *Map, struct ilist *List)
Flip direction of selected lines.
Definition: flip.c:25
off_t Vect_rewrite_line(struct Map_info *Map, off_t line, int type, const struct line_pnts *points, const struct line_cats *cats)
Rewrites existing feature (topological level required)
struct line_pnts * Vect_new_line_struct()
Creates and initializes a line_pnts structure.
Definition: line.c:45
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:659
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
void Vect_line_reverse(struct line_pnts *Points)
Reverse the order of vertices.
Definition: line.c:932
int G_debug(int level, const char *msg,...)
Print debugging message.
Definition: debug.c:65
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:650
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:655
#define GV_LINES
Definition: dig_defines.h:192