18 #include <grass/bitmap.h>
19 #include <grass/linkm.h>
20 #include <grass/gis.h>
21 #include <grass/dbmi.h>
22 #include <grass/Vect.h>
23 #include <grass/glocale.h>
25 #include <grass/interpf.h>
35 double *
xmin,
double *
xmax,
double *
ymin,
double *
ymax,
double *zmin,
double *zmax,
int *n_points,
44 double c1, c2, c3, c4;
45 int i, line, k = 0, nnodes;
46 double ns_res, ew_res;
50 double xprev, yprev, zprev, x1, y1, z1, d1, xt, yt, z, sm;
51 struct line_pnts *Points;
52 struct line_cats *Cats;
53 int times, j1, k1, ltype,
cat, zctype = 0, sctype = 0;
54 struct field_info *Fi;
58 dbCatValArray zarray, sarray;
63 G_debug(2,
"IL_vector_input_data_2d(): field = %d, zcol = %s, scol = %s",
67 dmax2 = *dmax * *
dmax;
75 if (field > 0 && zcol !=
NULL) {
79 G_fatal_error(_(
"Database connection not defined for layer %d"),
81 G_debug(3,
" driver = %s database = %s table = %s", Fi->driver,
82 Fi->database, Fi->table);
88 G_fatal_error(_(
"Unable to open database <%s> by driver <%s>"),
89 Fi->database, Fi->driver);
92 G_debug(3,
" zcol C type = %d", zctype);
96 if (zctype != DB_C_TYPE_INT && zctype != DB_C_TYPE_DOUBLE)
97 G_fatal_error(_(
"Data type of column <%s> must be numeric"), zcol);
106 G_debug(3,
" scol C type = %d", sctype);
109 if (sctype != DB_C_TYPE_INT && sctype != DB_C_TYPE_DOUBLE)
110 G_fatal_error(_(
"Data type of column <%s> must be numeric"), scol);
121 G_message(_(
"Reading features from vector map ..."));
126 if (!(ltype & (GV_POINT | GV_LINE | GV_BOUNDARY)))
139 if (zctype == DB_C_TYPE_INT) {
153 G_warning(_(
"Database record for cat %d not found"),
159 if (sctype == DB_C_TYPE_INT) {
171 G_fatal_error(_(
"Negative value of smoothing detected: sm must be >= 0"));
173 G_debug(5,
" z = %f sm = %f", z, sm);
179 for (i = 0; i < Points->n_points; i++) {
183 params->
zmult, xmin, xmax, ymin, ymax, zmin,
184 zmax, &npoint, &OUTRANGE, &k);
190 for (i = 1; i < Points->n_points - 1; i++) {
194 params->
zmult, xmin, xmax, ymin, ymax, zmin,
195 zmax, &npoint, &OUTRANGE, &k);
201 xprev = Points->x[0];
202 yprev = Points->y[0];
203 zprev = Points->z[0];
204 for (i = 1; i < Points->n_points; i++) {
212 d1 = (xt * xt + yt * yt);
213 if ((d1 > dmax2) && (dmax2 != 0.)) {
214 times = (
int)(d1 / dmax2 + 0.5);
215 for (j1 = 0; j1 < times; j1++) {
216 xt = x1 - j1 * ((x1 - xprev) / times);
217 yt = y1 - j1 * ((y1 - yprev) / times);
219 z = z1 - j1 * ((z1 - zprev) / times);
222 xmin, xmax, ymin, ymax, zmin, zmax, &npoint,
233 G_message(_(
"Reading nodes from vector map ..."));
235 for (k1 = 1; k1 <= nnodes; k1++) {
256 if (zctype == DB_C_TYPE_INT) {
270 G_warning(_(
"Database record for cat %d not found"),
276 if (sctype == DB_C_TYPE_INT) {
288 G_fatal_error(_(
"Negative value of smoothing detected: sm must be >= 0"));
290 G_debug(5,
" z = %f sm = %f", z, sm);
295 ymax, zmin, zmax, &npoint, &OUTRANGE, &k);
298 if (field > 0 && zcol !=
NULL)
304 c1 = *xmin - data->
x_orig;
306 c3 = *ymin - data->
y_orig;
308 if ((c1 > 5 * ew_res) || (c2 > 5 * ew_res) || (c3 > 5 * ns_res) ||
314 G_warning(_(
"Strip exists with insufficient data"));
328 G_warning(_(
"There are points outside specified 2D/3D region - %d points ignored"),
332 npoint = k - npoint - OUTRANGE;
333 if (npoint < params->kmin) {
335 G_warning(_(
"%d points given for interpolation (after thinning) is less than given NPMIN=%d"),
336 npoint, params->
kmin);
337 params->
kmin = npoint;
340 G_warning(_(
"Zero points in the given region"));
344 if (npoint > params->
KMAX2 && params->
kmin <= params->
kmax) {
345 G_warning(_(
"Segmentation parameters set to invalid values: npmin= %d, segmax= %d "
346 "for smooth connection of segments, npmin > segmax (see manual)"),
350 if (npoint < params->KMAX2 && params->
kmax != params->
KMAX2)
351 G_warning(_(
"There are less than %d points for interpolation. No "
352 "segmentation is necessary, to run the program faster set "
353 "segmax=%d (see manual)"), params->
KMAX2, params->
KMAX2);
355 G_message(_(
"Number of points from vector map %d"), k);
358 G_message(_(
"Number of points being used %d"), npoint);
371 double *zmax,
int *npoint,
int *OUTRANGE,
int *total)
374 double c1, c2, c3, c4;
376 static int first_time = 1;
389 if (!((c1 >= 0) && (c2 >= 0) && (c3 >= 0) && (c4 >= 0))) {
391 G_warning(_(
"Some points outside of region (ignored)"));
397 G_warning(_(
"Unable to allocate memory"));
405 G_warning(_(
"Unable to insert %f,%f,%f a = %d"), x, y, z, a);
418 *xmin =
amin1(*xmin, x);
419 *ymin =
amin1(*ymin, y);
420 *zmin =
amin1(*zmin, z);
421 *xmax =
amax1(*xmax, x);
422 *ymax =
amax1(*ymax, y);
423 *zmax =
amax1(*zmax, z);
def info
Display an informational message using g.message -i
int db_select_CatValArray(dbDriver *driver, const char *tab, const char *key, const char *col, const char *where, dbCatValArray *cvarr)
Select pairs key/value to array, values are sorted by key (must be integer)
int db_column_Ctype(dbDriver *driver, const char *tab, const char *col)
Get column ctype.
int db_CatValArray_get_value_int(dbCatValArray *arr, int key, int *val)
Find value (integer) by key.
struct field_info * Vect_get_field(struct Map_info *Map, int field)
Get information about link to database.
int Vect_get_node_line(struct Map_info *Map, int node, int line)
Get line id for node line index.
int Vect_read_next_line(struct Map_info *Map, struct line_pnts *line_p, struct line_cats *line_c)
Read next vector feature (level 1 and 2)
int db_close_database_shutdown_driver(dbDriver *driver)
Close driver/database connection.
struct line_pnts * Vect_new_line_struct()
Creates and initializes a struct line_pnts.
void G_important_message(const char *msg,...)
Print a message to stderr even in brief mode (verbosity=1)
int Vect_level(struct Map_info *Map)
Returns level that Map is opened at.
void db_CatValArray_free(dbCatValArray *arr)
double amax1(double, double)
int process_point(double, double, double, double, struct tree_info *, double, double *, double *, double *, double *, double *, double *, int *, int *, int *)
struct triple * quad_point_new(double x, double y, double z, double sm)
int db_CatValArray_get_value_double(dbCatValArray *arr, int key, double *val)
Find value (double) by key.
int G_percent(long n, long d, int s)
Print percent complete messages.
void G_verbose_message(const char *msg,...)
Print a message to stderr but only if module is in verbose mode.
void G_message(const char *msg,...)
Print a message to stderr.
int db_set_handle(dbHandle *handle, const char *dbName, const char *dbSchema)
double amin1(double, double)
void db_CatValArray_init(dbCatValArray *arr)
struct line_cats * Vect_new_cats_struct()
Creates and initializes line_cats structure.
G_warning("category support for [%s] in mapset [%s] %s", name, mapset, type)
int G_debug(int level, const char *msg,...)
Print debugging message.
void db_init_handle(dbHandle *handle)
int MT_insert(struct triple *point, struct tree_info *info, struct multtree *tree, int n_leafs)
int Vect_get_node_coor(struct Map_info *map, int num, double *x, double *y, double *z)
Get node coordinates.
int db_open_database(dbDriver *driver, dbHandle *handle)
Open database connection.
int Vect_get_num_nodes(struct Map_info *map)
Get number of nodes in vector map.
int G_fatal_error(const char *msg,...)
Print a fatal error message to stderr.
int IL_vector_input_data_2d(struct interp_params *, struct Map_info *, int, char *, char *, struct tree_info *, double *, double *, double *, double *, double *, double *, int *, double *)
dbDriver * db_start_driver(const char *name)
Initialize a new dbDriver for db transaction.
void db_init_string(dbString *x)
int Vect_read_line(struct Map_info *Map, struct line_pnts *line_p, struct line_cats *line_c, int line)
Read vector feature.
int Vect_cat_get(struct line_cats *Cats, int field, int *cat)
Get first found category of given field.