57 double *xmin,
double *xmax,
double *ymin,
double *ymax,
double *zmin,
58 double *zmax,
int *n_points,
63 double c1, c2, c3, c4;
65 double ns_res, ew_res;
69 double xprev, yprev, zprev, x1, y1, z1, d1, xt, yt, z, sm;
70 struct line_pnts *Points;
71 struct line_cats *Cats;
72 int times, j1, ltype, cat, zctype = 0, sctype = 0;
73 struct field_info *Fi;
77 dbCatValArray zarray, sarray;
82 G_debug(2,
"IL_vector_input_data_2d(): field = %d, zcol = %s, scol = %s",
84 ns_res = (data->ymax - data->y_orig) / data->n_rows;
85 ew_res = (data->xmax - data->x_orig) / data->n_cols;
86 dmax2 = *dmax * *dmax;
88 Points = Vect_new_line_struct();
89 Cats = Vect_new_cats_struct();
91 if (field == 0 && !Vect_is_3d(Map))
92 G_fatal_error(_(
"Vector map <%s> is not 3D"), Vect_get_full_name(Map));
94 if (field > 0 && zcol !=
NULL) {
96 Fi = Vect_get_field(Map, field);
98 G_fatal_error(_(
"Database connection not defined for layer %d"),
100 G_debug(3,
" driver = %s database = %s table = %s", Fi->driver,
101 Fi->database, Fi->table);
102 db_init_handle(&handle);
103 db_init_string(&stmt);
104 driver = db_start_driver(Fi->driver);
105 db_set_handle(&handle, Fi->database,
NULL);
106 if (db_open_database(
driver, &handle) != DB_OK)
107 G_fatal_error(_(
"Unable to open database <%s> by driver <%s>"),
108 Fi->database, Fi->driver);
110 zctype = db_column_Ctype(
driver, Fi->table, zcol);
111 G_debug(3,
" zcol C type = %d", zctype);
114 if (zctype != DB_C_TYPE_INT && zctype != DB_C_TYPE_DOUBLE)
115 G_fatal_error(_(
"Data type of column <%s> must be numeric"), zcol);
117 db_CatValArray_init(&zarray);
119 db_select_CatValArray(
driver, Fi->table, Fi->key, zcol,
123 sctype = db_column_Ctype(
driver, Fi->table, scol);
124 G_debug(3,
" scol C type = %d", sctype);
127 if (sctype != DB_C_TYPE_INT && sctype != DB_C_TYPE_DOUBLE)
131 db_CatValArray_init(&sarray);
132 db_select_CatValArray(
driver, Fi->table, Fi->key, scol,
136 db_close_database_shutdown_driver(
driver);
140 G_message(_(
"Reading features from vector map ..."));
142 while ((ltype = Vect_read_next_line(Map, Points, Cats)) != -2) {
144 if (!(ltype & (GV_POINT | GV_LINE | GV_BOUNDARY)))
148 Vect_cat_get(Cats, field, &cat);
156 if (zctype == DB_C_TYPE_INT) {
157 ret = db_CatValArray_get_value_int(&zarray, cat, &intval);
161 ret = db_CatValArray_get_value_double(&zarray, cat, &z);
172 G_warning(_(
"Database record for cat %d not found"),
178 if (sctype == DB_C_TYPE_INT) {
180 db_CatValArray_get_value_int(&sarray, cat, &intval);
185 db_CatValArray_get_value_double(&sarray, cat, &sm);
191 G_debug(5,
" z = %f sm = %f", z, sm);
196 for (i = 0; i < Points->n_points; i++) {
200 params->
zmult, xmin, xmax, ymin, ymax, zmin, zmax,
201 &npoint, &OUTRANGE, &k);
205 xprev = Points->x[0];
206 yprev = Points->y[0];
207 zprev = Points->z[0];
208 for (i = 1; i < Points->n_points; i++) {
216 d1 = (xt * xt + yt * yt);
217 if ((d1 > dmax2) && (dmax2 != 0.)) {
218 times = (int)(d1 / dmax2 + 0.5);
219 for (j1 = 0; j1 < times; j1++) {
220 xt = x1 - j1 * ((x1 - xprev) / times);
221 yt = y1 - j1 * ((y1 - yprev) / times);
223 z = z1 - j1 * ((z1 - zprev) / times);
226 xmax, ymin, ymax, zmin, zmax, &npoint,
236 if (field > 0 && zcol !=
NULL)
237 db_CatValArray_free(&zarray);
239 db_CatValArray_free(&sarray);
242 c1 = *xmin - data->x_orig;
243 c2 = data->xmax - *xmax;
244 c3 = *ymin - data->y_orig;
245 c4 = data->ymax - *ymax;
246 if ((c1 > 5 * ew_res) || (c2 > 5 * ew_res) || (c3 > 5 * ns_res) ||
252 G_warning(_(
"Strip exists with insufficient data"));
265 G_warning(_(
"There are points outside specified 2D/3D region - %d "
270 npoint = k - npoint - OUTRANGE;
271 if (npoint < params->kmin) {
273 G_warning(_(
"%d points given for interpolation (after thinning) is "
274 "less than given NPMIN=%d"),
275 npoint, params->
kmin);
276 params->
kmin = npoint;
279 G_warning(_(
"Zero points in the given region"));
283 if (npoint > params->
KMAX2 && params->
kmin <= params->
kmax) {
285 _(
"Segmentation parameters set to invalid values: npmin= %d, "
287 "for smooth connection of segments, npmin > segmax (see manual)"),
291 if (npoint < params->KMAX2 && params->
kmax != params->
KMAX2)
292 G_warning(_(
"There are less than %d points for interpolation. No "
293 "segmentation is necessary, to run the program faster set "
294 "segmax=%d (see manual)"),