GRASS 8 Programmer's Manual 8.6.0dev(2026)-1d1e47ad9d
Loading...
Searching...
No Matches
chtype.c
Go to the documentation of this file.
1/*!
2 \file vector/vedit/chtype.c
3
4 \brief Vedit library - change primitives type
5
6 (C) 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 Change primitive type
18
19 Supported conversions:
20 - point <-> centroid
21 - line <-> boundary
22
23 \param Map pointer to Map_info
24 \param List list of selected primitives
25
26 \return number of modified primitives
27 \return -1 on error
28 */
30{
31 int i;
32 int nret, line;
33 int type, newtype;
34 struct line_pnts *Points;
35 struct line_cats *Cats;
36
37 nret = 0;
38
39 Points = Vect_new_line_struct();
41
42 for (i = 0; i < List->n_values; i++) {
43 line = List->value[i];
44 if (!Vect_line_alive(Map, line))
45 continue;
46 type = Vect_read_line(Map, Points, Cats, line);
47 if (type < 0) {
48 return -1;
49 }
50 switch (type) {
51 case GV_POINT:
53 break;
54 case GV_CENTROID:
56 break;
57 case GV_LINE:
59 break;
60 case GV_BOUNDARY:
62 break;
63 default:
64 newtype = -1;
65 break;
66 }
67
68 G_debug(3, "Vedit_chtype_lines(): line=%d, from_type=%d, to_type=%d",
69 line, type, newtype);
70
71 if (newtype > 0) {
72 if (Vect_rewrite_line(Map, line, newtype, Points, Cats) < 0) {
73 return -1;
74 }
75 nret++;
76 }
77 }
78
81
82 return nret;
83}
int Vedit_chtype_lines(struct Map_info *Map, struct ilist *List)
Change primitive type.
Definition chtype.c:29
int G_debug(int, const char *,...) __attribute__((format(printf
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
off_t Vect_rewrite_line(struct Map_info *, off_t, int, const struct line_pnts *, const struct line_cats *)
Rewrites existing feature (topological level required)
void Vect_destroy_cats_struct(struct line_cats *)
Frees all memory associated with line_cats structure, including the struct itself.
int Vect_read_line(struct Map_info *, struct line_pnts *, struct line_cats *, int)
Read vector feature (topological level required)
int Vect_line_alive(struct Map_info *, int)
Check if feature is alive or dead (topological level required)
struct line_cats * Vect_new_cats_struct(void)
Creates and initializes line_cats structure.
struct line_pnts * Vect_new_line_struct(void)
Creates and initializes a line_pnts structure.
Definition line.c:45
#define GV_CENTROID
#define GV_LINE
#define GV_POINT
Feature types used in memory on run time (may change)
#define GV_BOUNDARY
Vector map info.
List of integers.
Definition gis.h:715
Feature category info.
Feature geometry info - coordinates.