31#include <grass/bitmap.h>
32#include <grass/linkm.h>
34#include <grass/dbmi.h>
35#include <grass/vector.h>
36#include <grass/glocale.h>
38#include <grass/interpf.h>
57 double *xmin,
double *xmax,
58 double *ymin,
double *ymax,
59 double *zmin,
double *zmax,
65 double c1, c2, c3, c4;
67 double ns_res, ew_res;
71 double xprev, yprev, zprev, x1, y1, z1, d1, xt, yt, z, sm;
72 struct line_pnts *Points;
73 struct line_cats *Cats;
74 int times, j1, ltype, cat, zctype = 0, sctype = 0;
75 struct field_info *Fi;
79 dbCatValArray zarray, sarray;
84 G_debug(2,
"IL_vector_input_data_2d(): field = %d, zcol = %s, scol = %s",
88 dmax2 = *dmax * *dmax;
90 Points = Vect_new_line_struct();
91 Cats = Vect_new_cats_struct();
93 if (field == 0 && !Vect_is_3d(Map))
94 G_fatal_error(_(
"Vector map <%s> is not 3D"), Vect_get_full_name(Map));
96 if (field > 0 && zcol !=
NULL) {
98 Fi = Vect_get_field(Map, field);
100 G_fatal_error(_(
"Database connection not defined for layer %d"),
102 G_debug(3,
" driver = %s database = %s table = %s", Fi->driver,
103 Fi->database, Fi->table);
104 db_init_handle(&handle);
105 db_init_string(&stmt);
106 driver = db_start_driver(Fi->driver);
107 db_set_handle(&handle, Fi->database,
NULL);
108 if (db_open_database(
driver, &handle) != DB_OK)
109 G_fatal_error(_(
"Unable to open database <%s> by driver <%s>"),
110 Fi->database, Fi->driver);
112 zctype = db_column_Ctype(
driver, Fi->table, zcol);
113 G_debug(3,
" zcol C type = %d", zctype);
117 if (zctype != DB_C_TYPE_INT && zctype != DB_C_TYPE_DOUBLE)
118 G_fatal_error(_(
"Data type of column <%s> must be numeric"), zcol);
120 db_CatValArray_init(&zarray);
122 db_select_CatValArray(
driver, Fi->table, Fi->key, zcol,
126 sctype = db_column_Ctype(
driver, Fi->table, scol);
127 G_debug(3,
" scol C type = %d", sctype);
130 if (sctype != DB_C_TYPE_INT && sctype != DB_C_TYPE_DOUBLE)
131 G_fatal_error(_(
"Data type of column <%s> must be numeric"), scol);
133 db_CatValArray_init(&sarray);
134 db_select_CatValArray(
driver, Fi->table, Fi->key, scol,
138 db_close_database_shutdown_driver(
driver);
142 G_message(_(
"Reading features from vector map ..."));
145 while ((ltype = Vect_read_next_line(Map, Points, Cats)) != -2) {
147 if (!(ltype & (GV_POINT | GV_LINE | GV_BOUNDARY)))
151 Vect_cat_get(Cats, field, &cat);
160 if (zctype == DB_C_TYPE_INT) {
161 ret = db_CatValArray_get_value_int(&zarray, cat, &intval);
165 ret = db_CatValArray_get_value_double(&zarray, cat, &z);
174 G_warning(_(
"Database record for cat %d not found"),
180 if (sctype == DB_C_TYPE_INT) {
182 db_CatValArray_get_value_int(&sarray, cat,
188 db_CatValArray_get_value_double(&sarray, cat,
192 G_fatal_error(_(
"Negative value of smoothing detected: sm must be >= 0"));
194 G_debug(5,
" z = %f sm = %f", z, sm);
199 for (i = 0; i < Points->n_points; i++) {
204 zmax, &npoint, &OUTRANGE, &k);
209 xprev = Points->x[0];
210 yprev = Points->y[0];
211 zprev = Points->z[0];
212 for (i = 1; i < Points->n_points; i++) {
220 d1 = (xt * xt + yt * yt);
221 if ((d1 > dmax2) && (dmax2 != 0.)) {
222 times = (int)(d1 / dmax2 + 0.5);
223 for (j1 = 0; j1 < times; j1++) {
224 xt = x1 - j1 * ((x1 - xprev) / times);
225 yt = y1 - j1 * ((y1 - yprev) / times);
227 z = z1 - j1 * ((z1 - zprev) / times);
230 xmin,
xmax, ymin,
ymax, zmin, zmax, &npoint,
240 if (field > 0 && zcol !=
NULL)
241 db_CatValArray_free(&zarray);
243 db_CatValArray_free(&sarray);
246 c1 = *xmin - data->
x_orig;
248 c3 = *ymin - data->
y_orig;
250 if ((c1 > 5 * ew_res) || (c2 > 5 * ew_res) || (c3 > 5 * ns_res) ||
256 G_warning(_(
"Strip exists with insufficient data"));
270 G_warning(_(
"There are points outside specified 2D/3D region - %d points ignored"),
274 npoint = k - npoint - OUTRANGE;
275 if (npoint < params->kmin) {
277 G_warning(_(
"%d points given for interpolation (after thinning) is less than given NPMIN=%d"),
278 npoint, params->
kmin);
279 params->
kmin = npoint;
282 G_warning(_(
"Zero points in the given region"));
286 if (npoint > params->
KMAX2 && params->
kmin <= params->
kmax) {
287 G_warning(_(
"Segmentation parameters set to invalid values: npmin= %d, segmax= %d "
288 "for smooth connection of segments, npmin > segmax (see manual)"),
292 if (npoint < params->KMAX2 && params->
kmax != params->
KMAX2)
293 G_warning(_(
"There are less than %d points for interpolation. No "
294 "segmentation is necessary, to run the program faster set "
295 "segmax=%d (see manual)"), params->
KMAX2, params->
KMAX2);
313 double *zmax,
int *npoint,
int *OUTRANGE,
int *total)
316 double c1, c2, c3, c4;
318 static int first_time = 1;
331 if (!((c1 >= 0) && (c2 >= 0) && (c3 >= 0) && (c4 >= 0))) {
333 G_warning(_(
"Some points outside of region (ignored)"));
339 G_warning(_(
"Unable to allocate memory"));
347 G_warning(_(
"Unable to insert %f,%f,%f a = %d"),
x, y, z, a);
361 *ymin =
amin1(*ymin, y);
362 *zmin =
amin1(*zmin, z);
365 *zmax =
amax1(*zmax, z);
struct triple * quad_point_new(double x, double y, double z, double sm)
int G_debug(int level, const char *msg,...)
Print debugging message.
void G_verbose_message(const char *msg,...)
Print a message to stderr but only if module is in verbose mode.
void G_important_message(const char *msg,...)
Print a message to stderr even in brief mode (verbosity=1)
void G_fatal_error(const char *msg,...)
Print a fatal error message to stderr.
void G_message(const char *msg,...)
Print a message to stderr.
void G_warning(const char *msg,...)
Print a warning message to stderr.
double amin1(double, double)
double amax1(double, double)
int MT_insert(struct triple *point, struct tree_info *info, struct multtree *tree, int n_leafs)