GRASS 8 Programmer's Manual 8.6.0dev(2026)-1878fdfec5
Loading...
Searching...
No Matches
zbulk.c
Go to the documentation of this file.
1/*!
2 \file lib/vector/vedit/zbulk.c
3
4 \brief Vedit library - Bulk labeling (automated labeling of vector
5 features)
6
7 SPDX-FileCopyrightText: 2007-2008 GRASS Development Team
8 SPDX-License-Identifier: GPL-2.0-or-later
9
10 \author Martin Landa <landa.martin gmail.com>
11 */
12
13#include <grass/dbmi.h>
14#include <grass/vedit.h>
15
16/*!
17 \brief Lines z-bulk labeling
18
19 Automated labeling (z coordinate assignment) of vector lines (iso-lines).
20
21 \param Map pointer to Map_info
22 \param List list of selected lines
23 \param x1,y1,x2,y2 staring and ending point
24 \param start starting value
25 \param step step value
26
27 \return number of modified features
28 \return -1 on error
29 */
30int Vedit_bulk_labeling(struct Map_info *Map, struct ilist *List, double x1,
31 double y1, double x2, double y2, double start,
32 double step)
33{
34 int i, cv_i, p_i;
35 int line, type, temp_line;
37 double value, dist;
38
39 struct line_cats *Cats;
40 struct line_pnts *Points, *Points_se; /* start - end */
41 struct bound_box box, box_se;
42
43 /* for intersection */
44 struct line_pnts **Points_a, **Points_b;
45 int nlines_a, nlines_b;
46
47 dbCatValArray cv; /* line_id / dist */
48
50
51 value = start;
52
53 Points = Vect_new_line_struct();
56
57 db_CatValArray_alloc(&cv, List->n_values);
59 cv.n_values = 0;
60
63
64 /* write temporary line */
66 if (temp_line < 0) {
67 nlines_modified = -1;
68 goto free_exit;
69 }
70
72
73 /* determine order of lines */
74 cv_i = 0;
75 for (i = 0; i < List->n_values; i++) {
76 line = List->value[i];
77
78 if (!Vect_line_alive(Map, line))
79 continue;
80
81 type = Vect_read_line(Map, Points, NULL, line);
82
83 if (!(type & GV_LINE))
84 continue;
85
86 Vect_line_box(Points, &box);
90
91 if (nlines_a < 2 || nlines_b < 1) /* should not happen */
92 continue;
93
94 /* calculate distance start point -> point of intersection */
95 for (p_i = 0; p_i < Points_a[0]->n_points; p_i++) {
96 Points_a[0]->z[p_i] = 0;
97 }
98 dist =
99 Vect_line_length(Points_a[0]); /* always first line in array? */
100
101 cv.value[cv_i].cat = line;
102 cv.value[cv_i++].val.d = dist;
103 cv.n_values++;
104 }
105 }
106
107 /* sort array by distance */
109
110 /* z bulk-labeling */
111 for (cv_i = 0; cv_i < cv.n_values; cv_i++) {
112 line = cv.value[cv_i].cat;
113 type = Vect_read_line(Map, Points, Cats, line);
114
115 for (p_i = 0; p_i < Points->n_points; p_i++) {
116 Points->z[p_i] = value;
117 }
118
119 if (Vect_rewrite_line(Map, line, type, Points, Cats) < 0) {
120 nlines_modified = -1;
121 goto free_exit;
122 }
124
125 value += step;
126 }
127
128 if (Vect_delete_line(Map, temp_line) < 0) {
129 nlines_modified = -1;
130 }
131
137
138 return nlines_modified;
139}
#define NULL
Definition ccmath.h:32
Main header of GRASS DataBase Management Interface.
#define DB_C_TYPE_DOUBLE
Definition dbmi.h:107
void db_CatValArray_free(dbCatValArray *)
Free allocated dbCatValArray.
Definition value.c:371
int db_CatValArray_sort_by_value(dbCatValArray *)
Sort key/value array by value.
int db_CatValArray_alloc(dbCatValArray *, int)
Allocate dbCatValArray.
Definition value.c:399
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)
double Vect_line_length(const struct line_pnts *)
Calculate line length, 3D-length in case of 3D vector line.
Definition line.c:573
void Vect_line_box(const struct line_pnts *, struct bound_box *)
Get bounding box of line.
Definition line.c:886
int Vect_line_intersection(struct line_pnts *, struct line_pnts *, struct bound_box *, struct bound_box *, struct line_pnts ***, struct line_pnts ***, int *, int *, int)
Intersect 2 lines.
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_check_intersection(struct line_pnts *, struct line_pnts *, int)
Check if 2 lines intersect.
int Vect_line_alive(struct Map_info *, int)
Check if feature is alive or dead (topological level required)
int Vect_delete_line(struct Map_info *, off_t)
Delete existing feature (topological level required)
struct line_cats * Vect_new_cats_struct(void)
Creates and initializes line_cats structure.
off_t Vect_write_line(struct Map_info *, int, const struct line_pnts *, const struct line_cats *)
Writes a new feature.
struct line_pnts * Vect_new_line_struct(void)
Creates and initializes a line_pnts structure.
Definition line.c:43
int Vect_append_point(struct line_pnts *, double, double, double)
Appends one point to the end of a line.
Definition line.c:146
#define GV_LINE
#define WITH_Z
#define PORT_DOUBLE_MAX
Limits for portable types.
Definition dig_defines.h:66
#define WITHOUT_Z
2D/3D vector data
Vector map info.
Bounding box.
Definition dig_structs.h:62
int ctype
Definition dbmi.h:270
int n_values
Definition dbmi.h:268
dbCatVal * value
Definition dbmi.h:271
union dbCatVal::@1 val
int cat
Definition dbmi.h:252
List of integers.
Definition gis.h:712
Feature category info.
Feature geometry info - coordinates.
int n_points
Number of points.
double * z
Array of Z coordinates.
int Vedit_bulk_labeling(struct Map_info *Map, struct ilist *List, double x1, double y1, double x2, double y2, double start, double step)
Lines z-bulk labeling.
Definition zbulk.c:30