1 #include <grass/config.h>
5 #include <grass/lidar.h>
6 #include <grass/vector.h>
10 struct bound_box General,
struct bound_box Overlap,
11 double **obs,
double *param,
int *line_num,
double pe,
12 double pn,
double overlap,
int nsplx,
int nsply,
13 int num_points,
int bilin,
struct line_cats *categories,
14 dbDriver *
driver,
double mean,
char *tab_name)
20 double interpolation, csi, eta, weight;
21 struct line_pnts *point;
23 point = Vect_new_line_struct();
25 db_begin_transaction(
driver);
27 for (i = 0; i < num_points; i++) {
29 if (Vect_point_in_box(obs[i][0], obs[i][1], mean,
35 obs[i][0], obs[i][1], pe, pn, nsplx, nsply,
36 Elaboration->west, Elaboration->south, param);
39 obs[i][0], obs[i][1], pe, pn, nsplx, nsply,
40 Elaboration->west, Elaboration->south, param);
42 interpolation += mean;
43 Vect_copy_xyz_to_pnts(point, &obs[i][0], &obs[i][1], &interpolation,
46 if (Vect_point_in_box(obs[i][0], obs[i][1], interpolation,
48 Vect_write_line(Out, GV_POINT, point, categories);
53 snprintf(buf,
sizeof(buf),
"INSERT INTO %s (ID, X, Y, Interp)",
55 db_append_string(&sql, buf);
57 snprintf(buf,
sizeof(buf),
" VALUES (");
58 db_append_string(&sql, buf);
59 snprintf(buf,
sizeof(buf),
"%d, %f, %f, ", line_num[i],
60 obs[i][0], obs[i][1]);
61 db_append_string(&sql, buf);
63 if ((*point->x > Overlap.E) && (*point->x < General.E)) {
64 if ((*point->y > Overlap.N) &&
65 (*point->y < General.N)) {
66 csi = (General.E - *point->x) / overlap;
67 eta = (General.N - *point->y) / overlap;
69 *point->z = weight * interpolation;
71 snprintf(buf,
sizeof(buf),
"%lf", *point->z);
72 db_append_string(&sql, buf);
73 snprintf(buf,
sizeof(buf),
")");
74 db_append_string(&sql, buf);
76 if (db_execute_immediate(
driver, &sql) != DB_OK)
80 else if ((*point->y < Overlap.S) &&
81 (*point->y > General.S)) {
82 csi = (General.E - *point->x) / overlap;
83 eta = (*point->y - General.S) / overlap;
85 *point->z = weight * interpolation;
87 snprintf(buf,
sizeof(buf),
"%lf", *point->z);
88 db_append_string(&sql, buf);
89 snprintf(buf,
sizeof(buf),
")");
90 db_append_string(&sql, buf);
92 if (db_execute_immediate(
driver, &sql) != DB_OK)
96 else if ((*point->y <= Overlap.N) &&
97 (*point->y >= Overlap.S)) {
98 weight = (General.E - *point->x) / overlap;
99 *point->z = weight * interpolation;
101 snprintf(buf,
sizeof(buf),
"%lf", *point->z);
102 db_append_string(&sql, buf);
103 snprintf(buf,
sizeof(buf),
")");
104 db_append_string(&sql, buf);
106 if (db_execute_immediate(
driver, &sql) != DB_OK)
111 else if ((*point->x < Overlap.W) && (*point->x > General.W)) {
112 if ((*point->y > Overlap.N) &&
113 (*point->y < General.N)) {
114 csi = (*point->x - General.W) / overlap;
115 eta = (General.N - *point->y) / overlap;
117 *point->z = weight * interpolation;
119 snprintf(buf,
sizeof(buf),
"%lf", *point->z);
120 db_append_string(&sql, buf);
121 snprintf(buf,
sizeof(buf),
")");
122 db_append_string(&sql, buf);
124 if (db_execute_immediate(
driver, &sql) != DB_OK)
128 else if ((*point->y < Overlap.S) &&
129 (*point->y > General.S)) {
130 csi = (*point->x - General.W) / overlap;
131 eta = (*point->y - General.S) / overlap;
133 *point->z = weight * interpolation;
135 snprintf(buf,
sizeof(buf),
"%lf", *point->z);
136 db_append_string(&sql, buf);
137 snprintf(buf,
sizeof(buf),
")");
138 db_append_string(&sql, buf);
140 if (db_execute_immediate(
driver, &sql) != DB_OK)
144 else if ((*point->y >= Overlap.S) &&
145 (*point->y <= Overlap.N)) {
146 weight = (*point->x - General.W) / overlap;
147 *point->z = weight * interpolation;
149 snprintf(buf,
sizeof(buf),
"%lf", *point->z);
150 db_append_string(&sql, buf);
151 snprintf(buf,
sizeof(buf),
")");
152 db_append_string(&sql, buf);
154 if (db_execute_immediate(
driver, &sql) != DB_OK)
159 else if ((*point->x >= Overlap.W) && (*point->x <= Overlap.E)) {
160 if ((*point->y > Overlap.N) &&
161 (*point->y < General.N)) {
162 weight = (General.N - *point->y) / overlap;
163 *point->z = weight * interpolation;
165 snprintf(buf,
sizeof(buf),
"%lf", *point->z);
166 db_append_string(&sql, buf);
167 snprintf(buf,
sizeof(buf),
")");
168 db_append_string(&sql, buf);
170 if (db_execute_immediate(
driver, &sql) != DB_OK)
174 else if ((*point->y < Overlap.S) &&
175 (*point->y > General.S)) {
176 weight = (*point->y - General.S) / overlap;
177 *point->z = (1 - weight) * interpolation;
179 snprintf(buf,
sizeof(buf),
"%lf", *point->z);
180 db_append_string(&sql, buf);
181 snprintf(buf,
sizeof(buf),
")");
182 db_append_string(&sql, buf);
184 if (db_execute_immediate(
driver, &sql) != DB_OK)
192 db_commit_transaction(
driver);
193 Vect_destroy_line_struct(point);
200 struct bound_box General,
struct bound_box Overlap,
201 SEGMENT *out_seg,
double *param,
double passoN,
202 double passoE,
double overlap,
double mean,
int nsplx,
203 int nsply,
int nrows,
int ncols,
int bilin)
206 int col, row, startcol, endcol, startrow, endrow;
207 double X,
Y, interpolation, weight, csi, eta, dval;
210 if (Original->north > General.N)
211 startrow = (Original->north - General.N) / Original->ns_res - 1;
214 if (Original->north > General.S) {
215 endrow = (Original->north - General.S) / Original->ns_res + 1;
221 if (General.W > Original->west)
222 startcol = (General.W - Original->west) / Original->ew_res - 1;
225 if (General.E > Original->west) {
226 endcol = (General.E - Original->west) / Original->ew_res + 1;
233 for (row = startrow; row < endrow; row++) {
234 for (col = startcol; col < endcol; col++) {
236 X = Rast_col_to_easting((
double)(col) + 0.5, Original);
237 Y = Rast_row_to_northing((
double)(row) + 0.5, Original);
239 if (Vect_point_in_box(
X,
Y, mean,
245 X,
Y, passoE, passoN, nsplx, nsply, Elaboration->west,
246 Elaboration->south, param);
249 X,
Y, passoE, passoN, nsplx, nsply, Elaboration->west,
250 Elaboration->south, param);
252 interpolation += mean;
254 if (Vect_point_in_box(
X,
Y, interpolation,
256 dval = interpolation;
260 if ((
X > Overlap.E) && (
X < General.E)) {
261 if ((
Y > Overlap.N) && (
Y < General.N)) {
262 csi = (General.E -
X) / overlap;
263 eta = (General.N -
Y) / overlap;
265 interpolation *= weight;
266 dval += interpolation;
268 else if ((
Y < Overlap.S) && (
Y > General.S)) {
269 csi = (General.E -
X) / overlap;
270 eta = (
Y - General.S) / overlap;
272 interpolation *= weight;
273 dval = interpolation;
275 else if ((
Y >= Overlap.S) &&
277 weight = (General.E -
X) / overlap;
278 interpolation *= weight;
279 dval = interpolation;
282 else if ((
X < Overlap.W) && (
X > General.W)) {
283 if ((
Y > Overlap.N) && (
Y < General.N)) {
284 csi = (
X - General.W) / overlap;
285 eta = (General.N -
Y) / overlap;
287 interpolation *= weight;
288 dval += interpolation;
290 else if ((
Y < Overlap.S) && (
Y > General.S)) {
291 csi = (
X - General.W) / overlap;
292 eta = (
Y - General.S) / overlap;
294 interpolation *= weight;
295 dval += interpolation;
297 else if ((
Y >= Overlap.S) &&
299 weight = (
X - General.W) / overlap;
300 interpolation *= weight;
301 dval += interpolation;
304 else if ((
X >= Overlap.W) && (
X <= Overlap.E)) {
305 if ((
Y > Overlap.N) && (
Y < General.N)) {
306 weight = (General.N -
Y) / overlap;
307 interpolation *= weight;
308 dval += interpolation;
310 else if ((
Y < Overlap.S) && (
Y > General.S)) {
311 weight = (
Y - General.S) / overlap;
312 interpolation *= weight;
313 dval = interpolation;
double dataInterpolateBicubic(double x, double y, double deltaX, double deltaY, int xNum, int yNum, double xMin, double yMin, double *parVect)
double dataInterpolateBilin(double x, double y, double deltaX, double deltaY, int xNum, int yNum, double xMin, double yMin, double *parVect)
void G_fatal_error(const char *msg,...)
Print a fatal error message to stderr.
void P_Sparse_Points(struct Map_info *Out, struct Cell_head *Elaboration, struct bound_box General, struct bound_box Overlap, double **obs, double *param, int *line_num, double pe, double pn, double overlap, int nsplx, int nsply, int num_points, int bilin, struct line_cats *categories, dbDriver *driver, double mean, char *tab_name)
int P_Regular_Points(struct Cell_head *Elaboration, struct Cell_head *Original, struct bound_box General, struct bound_box Overlap, SEGMENT *out_seg, double *param, double passoN, double passoE, double overlap, double mean, int nsplx, int nsply, int nrows, int ncols, int bilin)
int Segment_get(SEGMENT *SEG, void *buf, off_t row, off_t col)
Get value from segment file.
int Segment_put(SEGMENT *SEG, const void *buf, off_t row, off_t col)