GRASS 8 Programmer's Manual 8.6.0dev(2026)-c83afef6d3
Loading...
Searching...
No Matches
point2d.c
Go to the documentation of this file.
1/*!
2 * \file point2d.c
3 *
4 * \author
5 * Lubos Mitas (original program and various modifications)
6 *
7 * \author
8 * H. Mitasova,
9 * I. Kosinovsky,
10 * D. Gerdes,
11 * D. McCauley
12 * (GRASS4.1 version of the program and GRASS4.2 modifications)
13 *
14 * \author modified by McCauley in August 1995
15 * \author modified by Mitasova in August 1995, Nov. 1996
16 *
17 * SPDX-FileCopyrightText: 1993-2006 Helena Mitasova
18 * SPDX-FileCopyrightText: GRASS Development Team
19 * SPDX-License-Identifier: GPL-2.0-or-later
20 */
21
22#include <stdio.h>
23#include <math.h>
24#include <unistd.h>
25#include <grass/gis.h>
26#include <grass/vector.h>
27#include <grass/dbmi.h>
28
29#define POINT2D_C
30#include <grass/interpf.h>
31
32/* needed for AIX */
33#ifdef hz
34#undef hz
35#endif
36
37/*!
38 * Checks if interpolating function interp() evaluates correct z-values at
39 * given points. If smoothing is used calculate the maximum error caused
40 * by smoothing.
41 *
42 * *ertot* is a RMS deviation of the interpolated surface.
43 *
44 * \todo
45 * Alternative description:
46 * ...calculate the maximum and RMS deviation caused by smoothing.
47 */
49 struct quaddata *data, /*!< current region */
50 double *b, /*!< solution of linear equations */
51 double *ertot, /*!< total error */
52 double zmin, /*!< min z-value */
53 double dnorm, struct triple *skip_point)
54{
55 int n_points = data->n_points; /* number of points */
56 struct triple *points = data->points; /* points for interpolation */
58 double east = data->xmax;
59 double west = data->x_orig;
60 double north = data->ymax;
61 double south = data->y_orig;
62 double /* rfsta2, errmax, */ h, xx, yy, r2, hz, zz, err, xmm, ymm, r;
63 double skip_err;
64 int /* n1, */ mm, m;
65
66 /* double fstar2; */
67 int inside;
68
69 /* if ((site = G_site_new_struct (-1, 2, 0, 1)) == NULL)
70 G_fatal_error ("Memory error for site struct"); */
71
72 /* fstar2 = params->fi * params->fi / 4.; */
73 /* errmax = .0; */
74 /* n1 = n_points + 1; */
75 for (mm = 1; mm <= n_points; mm++) {
76 h = b[0];
77 for (m = 1; m <= n_points; m++) {
78 xx = points[mm - 1].x - points[m - 1].x;
79 yy = points[mm - 1].y - points[m - 1].y;
80 r2 = yy * yy + xx * xx;
81 if (r2 != 0.) {
82 /* rfsta2 = fstar2 * r2; */
83 r = r2;
84 h = h + b[m] * params->interp(r, params->fi);
85 }
86 }
87 /* modified by helena january 1997 - normalization of z was
88 removed from segm2d.c and interp2d.c
89 hz = (h * dnorm) + zmin;
90 zz = (points[mm - 1].z * dnorm) + zmin;
91 */
92 hz = h + zmin;
93 zz = points[mm - 1].z + zmin;
94 err = hz - zz;
95 xmm = points[mm - 1].x * dnorm + params->x_orig + west;
96 ymm = points[mm - 1].y * dnorm + params->y_orig + south;
97 if ((xmm >= west + params->x_orig) && (xmm <= east + params->x_orig) &&
98 (ymm >= south + params->y_orig) && (ymm <= north + params->y_orig))
99 inside = 1;
100 else
101 inside = 0;
102
103 if (params->create_devi) {
104
105 if (inside) { /* if the point is inside the region */
108 point_writeout.z = zz;
110 }
111 }
112 (*ertot) += err * err;
113 }
114
115 /* cv stuff */
116 if (params->cv) {
117 h = b[0];
118 for (m = 1; m <= n_points - 1; m++) {
119 xx = points[m - 1].x - skip_point->x;
120 yy = points[m - 1].y - skip_point->y;
121 r2 = yy * yy + xx * xx;
122 if (r2 != 0.) {
123 /* rfsta2 = fstar2 * r2; */
124 r = r2;
125 h = h + b[m] * params->interp(r, params->fi);
126 }
127 }
128 hz = h + zmin;
129 zz = skip_point->z + zmin;
130 skip_err = hz - zz;
131 xmm = skip_point->x * dnorm + params->x_orig + west;
132 ymm = skip_point->y * dnorm + params->y_orig + south;
133
134 if ((xmm >= west + params->x_orig) && (xmm <= east + params->x_orig) &&
135 (ymm >= south + params->y_orig) && (ymm <= north + params->y_orig))
136 inside = 1;
137 else
138 inside = 0;
139
140 if (inside) { /* if the point is inside the region */
143 point_writeout.z = zz;
145 }
146 } /* cv */
147
148 return 1;
149}
150
151/*!
152 * \brief A function to write out point and deviation at point to database.
153 *
154 * \param point point to write out
155 * \param error deviation at point
156 *
157 * \return 1
158 */
159int IL_write_point_2d(struct triple point, double err)
160{
161
162 char buf[1024];
163
166
167 Vect_append_point(Pnts, point.x, point.y, point.z);
170
172 snprintf(buf, sizeof(buf), "insert into %s values ( %d ", ff->table, count);
173 db_append_string(&sql2, buf);
174
175 snprintf(buf, sizeof(buf), ", %f", err);
176 db_append_string(&sql2, buf);
177 db_append_string(&sql2, ")");
178 G_debug(3, "IL_check_at_points_2d: %s", db_get_string(&sql2));
179
183 G_fatal_error("Cannot insert new row: %s", db_get_string(&sql2));
184 }
185 count++;
186
187 return 1;
188}
Main header of GRASS DataBase Management Interface.
#define DB_OK
Definition dbmi.h:69
int db_shutdown_driver(dbDriver *)
Closedown the driver, and free the driver structure.
Definition shutdown.c:33
void db_zero_string(dbString *)
Zero string.
Definition string.c:77
char * db_get_string(const dbString *)
Get string.
Definition string.c:138
int db_execute_immediate(dbDriver *, dbString *)
Execute SQL statements.
Definition c_execute.c:24
int db_close_database(dbDriver *)
Close database connection.
Definition c_closedb.c:23
int db_append_string(dbString *, const char *)
Append string to dbString.
Definition string.c:203
void void void void G_fatal_error(const char *,...) __attribute__((format(printf
int G_debug(int, const char *,...) __attribute__((format(printf
int Vect_reset_cats(struct line_cats *)
Reset category structure to make sure cats structure is clean to be re-used.
int Vect_cat_set(struct line_cats *, int, int)
Add new field/cat to category structure if doesn't exist yet.
off_t Vect_write_line(struct Map_info *, int, const struct line_pnts *, const struct line_cats *)
Writes a new feature.
void Vect_reset_line(struct line_pnts *)
Reset line.
Definition line.c:127
int Vect_append_point(struct line_pnts *, double, double, double)
Appends one point to the end of a line.
Definition line.c:146
#define GV_POINT
Feature types used in memory on run time (may change)
struct Map_info Map2
struct field_info * ff
dbString sql2
dbDriver * driver2
struct line_cats * Cats2
int count
struct line_pnts * Pnts
int IL_check_at_points_2d(struct interp_params *params, struct quaddata *data, double *b, double *ertot, double zmin, double dnorm, struct triple *skip_point)
Definition point2d.c:48
int IL_write_point_2d(struct triple point, double err)
A function to write out point and deviation at point to database.
Definition point2d.c:159
double b
Definition r_raster.c:37
double r
Definition r_raster.c:37
interp_fn * interp
Definition interpf.h:136
double fi
Definition interpf.h:97
double x_orig
Definition interpf.h:112
double y_orig
Definition interpf.h:112
bool create_devi
Definition interpf.h:126
double ymax
Definition dataquad.h:45
double y_orig
Definition dataquad.h:43
double x_orig
Definition dataquad.h:42
struct triple * points
Definition dataquad.h:49
int n_points
Definition dataquad.h:48
double xmax
Definition dataquad.h:44
double z
Definition dataquad.h:37
double x
Definition dataquad.h:35
double y
Definition dataquad.h:36
SYMBOL * err(FILE *fp, SYMBOL *s, char *msg)