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