GRASS Programmer's Manual  6.5.svn(2014)-r66266
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Pages
zbulk.c
Go to the documentation of this file.
1 
15 #include <grass/dbmi.h>
16 #include <grass/vedit.h>
17 
32 int Vedit_bulk_labeling(struct Map_info *Map, struct ilist *List,
33  double x1, double y1, double x2, double y2,
34  double start, double step)
35 {
36  int i, cv_i, p_i;
37  int line, type, temp_line;
38  int nlines_modified;
39  double value, dist;
40 
41  struct line_cats *Cats;
42  struct line_pnts *Points, *Points_se; /* start - end */
43 
44  /* for intersection */
45  struct line_pnts **Points_a, **Points_b;
46  int nlines_a, nlines_b;
47 
48  dbCatValArray cv; /* line_id / dist */
49 
50  nlines_modified = 0;
51 
52  value = start;
53 
54  Points = Vect_new_line_struct();
55  Points_se = Vect_new_line_struct();
56  Cats = Vect_new_cats_struct();
57 
58  db_CatValArray_alloc(&cv, List->n_values);
59  cv.ctype = DB_C_TYPE_DOUBLE;
60  cv.n_values = 0;
61 
62  Vect_append_point(Points_se, x1, y1, -PORT_DOUBLE_MAX);
63  Vect_append_point(Points_se, x2, y2, PORT_DOUBLE_MAX);
64 
65  /* write temporaly line */
66  temp_line = Vect_write_line(Map, GV_LINE, Points_se, Cats);
67  if (temp_line < 0) {
68  return -1;
69  }
70 
71  /* determine order of lines */
72  cv_i = 0;
73  for (i = 0; i < List->n_values; i++) {
74  line = List->value[i];
75 
76  if (!Vect_line_alive(Map, line))
77  continue;
78 
79  type = Vect_read_line(Map, Points, NULL, line);
80 
81  if (!(type & GV_LINE))
82  continue;
83 
84  if (Vect_line_check_intersection(Points_se, Points, WITH_Z)) {
85  Vect_line_intersection(Points_se, Points,
86  &Points_a, &Points_b, &nlines_a, &nlines_b,
87  WITHOUT_Z);
88 
89  if (nlines_a < 2 || nlines_b < 1) /* should not happen */
90  continue;
91 
92  /* calculate distance start point -> point of intersection */
93  for (p_i = 0; p_i < Points_a[0]->n_points; p_i++) {
94  Points_a[0]->z[p_i] = 0;
95  }
96  dist = Vect_line_length(Points_a[0]); /* always first line in array? */
97 
98  cv.value[cv_i].cat = line;
99  cv.value[cv_i++].val.d = dist;
100  cv.n_values++;
101  }
102  }
103 
104  /* sort array by distance */
106 
107  /* z bulk-labeling */
108  for (cv_i = 0; cv_i < cv.n_values; cv_i++) {
109  line = cv.value[cv_i].cat;
110  Vect_read_line(Map, Points, Cats, line);
111 
112  for (p_i = 0; p_i < Points->n_points; p_i++) {
113  Points->z[p_i] = value;
114  }
115 
116  if (Vect_rewrite_line(Map, line, type, Points, Cats) < 0) {
117  return -1;
118  }
119  nlines_modified++;
120 
121  value += step;
122  }
123 
124  if (Vect_delete_line(Map, temp_line) < 0) {
125  return -1;
126  }
127 
128  db_CatValArray_free(&cv);
129  Vect_destroy_line_struct(Points);
130  Vect_destroy_line_struct(Points_se);
132 
133  return nlines_modified;
134 }
struct line_pnts * Vect_new_line_struct()
Creates and initializes a struct line_pnts.
Definition: line.c:57
int Vect_line_check_intersection(struct line_pnts *APoints, struct line_pnts *BPoints, int with_z)
Check if 2 lines intersect.
void db_CatValArray_free(dbCatValArray *arr)
Definition: value.c:348
int db_CatValArray_alloc(dbCatValArray *arr, int n)
Definition: value.c:372
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:32
int Vect_append_point(struct line_pnts *Points, double x, double y, double z)
Appends one point to the end of a line.
Definition: line.c:168
int Vect_rewrite_line(struct Map_info *Map, int line, int type, struct line_pnts *points, struct line_cats *cats)
Rewrites feature info at the given offset.
int Vect_destroy_cats_struct(struct line_cats *p)
Frees all memory associated with line_cats structure, including the struct itself.
char * value
Definition: env.c:30
int Vect_line_alive(struct Map_info *Map, int line)
Check if feature is alive or dead.
struct line_cats * Vect_new_cats_struct()
Creates and initializes line_cats structure.
return NULL
Definition: dbfopen.c:1394
double Vect_line_length(struct line_pnts *Points)
Calculate line length, 3D-length in case of 3D vector line.
Definition: line.c:555
tuple Map
Definition: render.py:1310
int db_CatValArray_sort_by_value(dbCatValArray *arr)
Sort key/value array by value.
int Vect_line_intersection(struct line_pnts *APoints, struct line_pnts *BPoints, struct line_pnts ***ALines, struct line_pnts ***BLines, int *nalines, int *nblines, int with_z)
Intersect 2 lines.
int Vect_delete_line(struct Map_info *Map, int line)
Delete feature.
long Vect_write_line(struct Map_info *Map, int type, struct line_pnts *points, struct line_cats *cats)
Writes new feature to the end of file (table)
int Vect_destroy_line_struct(struct line_pnts *p)
Frees all memory associated with a struct line_pnts, including the struct itself. ...
Definition: line.c:90
int Vect_read_line(struct Map_info *Map, struct line_pnts *line_p, struct line_cats *line_c, int line)
Read vector feature.