GRASS Programmer's Manual  6.4.2(2012)
zbulk.c
Go to the documentation of this file.
00001 
00015 #include <grass/dbmi.h>
00016 #include <grass/vedit.h>
00017 
00032 int Vedit_bulk_labeling(struct Map_info *Map, struct ilist *List,
00033                         double x1, double y1, double x2, double y2,
00034                         double start, double step)
00035 {
00036     int i, cv_i, p_i;
00037     int line, type, temp_line;
00038     int nlines_modified;
00039     double value, dist;
00040 
00041     struct line_cats *Cats;
00042     struct line_pnts *Points, *Points_se;       /* start - end */
00043 
00044     /* for intersection */
00045     struct line_pnts **Points_a, **Points_b;
00046     int nlines_a, nlines_b;
00047 
00048     dbCatValArray cv;           /* line_id / dist */
00049 
00050     nlines_modified = 0;
00051 
00052     value = start;
00053 
00054     Points = Vect_new_line_struct();
00055     Points_se = Vect_new_line_struct();
00056     Cats = Vect_new_cats_struct();
00057 
00058     //cv = (dbCatValArray *) G_malloc (sizeof (dbCatValArray));
00059     db_CatValArray_alloc(&cv, List->n_values);
00060     cv.ctype = DB_C_TYPE_DOUBLE;
00061     cv.n_values = 0;
00062 
00063     Vect_append_point(Points_se, x1, y1, -PORT_DOUBLE_MAX);
00064     Vect_append_point(Points_se, x2, y2, PORT_DOUBLE_MAX);
00065 
00066     /* write temporaly line */
00067     temp_line = Vect_write_line(Map, GV_LINE, Points_se, Cats);
00068     if (temp_line < 0) {
00069         return -1;
00070     }
00071 
00072     /* determine order of lines */
00073     cv_i = 0;
00074     for (i = 0; i < List->n_values; i++) {
00075         line = List->value[i];
00076 
00077         if (!Vect_line_alive(Map, line))
00078             continue;
00079 
00080         type = Vect_read_line(Map, Points, NULL, line);
00081 
00082         if (!(type & GV_LINE))
00083             continue;
00084 
00085         if (Vect_line_check_intersection(Points_se, Points, WITH_Z)) {
00086             Vect_line_intersection(Points_se, Points,
00087                                    &Points_a, &Points_b, &nlines_a, &nlines_b,
00088                                    WITHOUT_Z);
00089 
00090             if (nlines_a < 2 || nlines_b < 1)   /* should not happen */
00091                 continue;
00092 
00093             /* calculate distance start point -> point of intersection */
00094             for (p_i = 0; p_i < Points_a[0]->n_points; p_i++) {
00095                 Points_a[0]->z[p_i] = 0;
00096             }
00097             dist = Vect_line_length(Points_a[0]);       /* always first line in array? */
00098 
00099             cv.value[cv_i].cat = line;
00100             cv.value[cv_i++].val.d = dist;
00101             cv.n_values++;
00102         }
00103     }
00104 
00105     /* sort array by distance */
00106     db_CatValArray_sort_by_value(&cv);
00107 
00108     /* z bulk-labeling */
00109     for (cv_i = 0; cv_i < cv.n_values; cv_i++) {
00110         line = cv.value[cv_i].cat;
00111         Vect_read_line(Map, Points, Cats, line);
00112 
00113         for (p_i = 0; p_i < Points->n_points; p_i++) {
00114             Points->z[p_i] = value;
00115         }
00116 
00117         if (Vect_rewrite_line(Map, line, type, Points, Cats) < 0) {
00118             return -1;
00119         }
00120         nlines_modified++;
00121 
00122         value += step;
00123     }
00124 
00125     if (Vect_delete_line(Map, temp_line) < 0) {
00126         return -1;
00127     }
00128 
00129     db_CatValArray_free(&cv);
00130     Vect_destroy_line_struct(Points);
00131     Vect_destroy_line_struct(Points_se);
00132     Vect_destroy_cats_struct(Cats);
00133 
00134     return nlines_modified;
00135 }
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines