GRASS 8 Programmer's Manual 8.6.0dev(2026)-745b61fbf6
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 SPDX-FileCopyrightText: 2008 GRASS Development Team
7 SPDX-License-Identifier: GPL-2.0-or-later
8
9 \author Martin Landa <landa.martin gmail.com>
10 */
11
12#include <grass/vedit.h>
13
14/*!
15 \brief Change primitive type
16
17 Supported conversions:
18 - point <-> centroid
19 - line <-> boundary
20
21 \param Map pointer to Map_info
22 \param List list of selected primitives
23
24 \return number of modified primitives
25 \return -1 on error
26 */
28{
29 int i;
30 int nret, line;
31 int type, newtype;
32 struct line_pnts *Points;
33 struct line_cats *Cats;
34
35 nret = 0;
36
37 Points = Vect_new_line_struct();
39
40 for (i = 0; i < List->n_values; i++) {
41 line = List->value[i];
42 if (!Vect_line_alive(Map, line))
43 continue;
44 type = Vect_read_line(Map, Points, Cats, line);
45 if (type < 0) {
46 return -1;
47 }
48 switch (type) {
49 case GV_POINT:
51 break;
52 case GV_CENTROID:
54 break;
55 case GV_LINE:
57 break;
58 case GV_BOUNDARY:
60 break;
61 default:
62 newtype = -1;
63 break;
64 }
65
66 G_debug(3, "Vedit_chtype_lines(): line=%d, from_type=%d, to_type=%d",
67 line, type, newtype);
68
69 if (newtype > 0) {
70 if (Vect_rewrite_line(Map, line, newtype, Points, Cats) < 0) {
71 return -1;
72 }
73 nret++;
74 }
75 }
76
79
80 return nret;
81}
int Vedit_chtype_lines(struct Map_info *Map, struct ilist *List)
Change primitive type.
Definition chtype.c:27
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:75
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:43
#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:712
Feature category info.
Feature geometry info - coordinates.