6
#include <grass/Vect.h>
7
#include <grass/dbmi.h>
8
#include <grass/glocale.h>
9
#include <grass/config.h>
11
#include "PolimiFunct.h"
13
/*------------------------------------------------------------------------------------------------*/
15
P_Sparse_Points(struct Map_info *Out, struct Cell_head *Elaboration,
16
BOUND_BOX General, BOUND_BOX Overlap, double **obs,
17
double *param, int *line_num, double pe, double pn,
18
double overlap, int nsplx, int nsply, int num_points,
19
int bilin, struct line_cats *categories, dbDriver * driver,
20
double mean, char *tab_name)
26
double interpolation, csi, eta, weight;
27
struct line_pnts *point;
29
point = Vect_new_line_struct();
31
db_begin_transaction(driver);
33
for (i = 0; i < num_points; i++) {
35
if (Vect_point_in_box(obs[i][0], obs[i][1], mean, &General)) { /*Here mean is just for asking if obs point is in box */
39
dataInterpolateBilin(obs[i][0], obs[i][1], pe, pn, nsplx,
40
nsply, Elaboration->west,
41
Elaboration->south, param);
44
dataInterpolateBicubic(obs[i][0], obs[i][1], pe, pn,
45
nsplx, nsply, Elaboration->west,
46
Elaboration->south, param);
48
interpolation += mean;
49
Vect_copy_xyz_to_pnts(point, &obs[i][0], &obs[i][1],
52
if (Vect_point_in_box(obs[i][0], obs[i][1], interpolation, &Overlap)) { /*(5) */
53
Vect_write_line(Out, GV_POINT, point, categories);
58
sprintf(buf, "INSERT INTO %s (ID, X, Y, Interp)", tab_name);
59
db_append_string(&sql, buf);
61
sprintf(buf, " VALUES (");
62
db_append_string(&sql, buf);
63
sprintf(buf, "%d, %f, %f, ", line_num[i], obs[i][0],
65
db_append_string(&sql, buf);
67
if ((*point->x > Overlap.E) && (*point->x < General.E)) {
68
if ((*point->y > Overlap.N) && (*point->y < General.N)) { /*(3) */
69
csi = (General.E - *point->x) / overlap;
70
eta = (General.N - *point->y) / overlap;
72
*point->z = weight * interpolation;
74
sprintf(buf, "%lf", *point->z);
75
db_append_string(&sql, buf);
77
db_append_string(&sql, buf);
79
if (db_execute_immediate(driver, &sql) != DB_OK)
80
G_fatal_error(_("Unable to access table <%s>"),
83
else if ((*point->y < Overlap.S) && (*point->y > General.S)) { /*(1) */
84
csi = (General.E - *point->x) / overlap;
85
eta = (*point->y - General.S) / overlap;
87
*point->z = weight * interpolation;
89
sprintf(buf, "%lf", *point->z);
90
db_append_string(&sql, buf);
92
db_append_string(&sql, buf);
94
if (db_execute_immediate(driver, &sql) != DB_OK)
95
G_fatal_error(_("Unable to access table <%s>"),
98
else if ((*point->y <= Overlap.N) && (*point->y >= Overlap.S)) { /*(1) */
99
weight = (General.E - *point->x) / overlap;
100
*point->z = weight * interpolation;
102
sprintf(buf, "%lf", *point->z);
103
db_append_string(&sql, buf);
105
db_append_string(&sql, buf);
107
if (db_execute_immediate(driver, &sql) != DB_OK)
108
G_fatal_error(_("Unable to access table <%s>"),
112
else if ((*point->x < Overlap.W) && (*point->x > General.W)) {
113
if ((*point->y > Overlap.N) && (*point->y < General.N)) { /*(4) */
114
csi = (*point->x - General.W) / overlap;
115
eta = (General.N - *point->y) / overlap;
117
*point->z = weight * interpolation;
119
sprintf(buf, "%lf", *point->z);
120
db_append_string(&sql, buf);
122
db_append_string(&sql, buf);
124
if (db_execute_immediate(driver, &sql) != DB_OK)
125
G_fatal_error(_("Unable to access table <%s>"),
128
else if ((*point->y < Overlap.S) && (*point->y > General.S)) { /*(2) */
129
csi = (*point->x - General.W) / overlap;
130
eta = (*point->y - General.S) / overlap;
132
*point->z = weight * interpolation;
134
sprintf(buf, "%lf", *point->z);
135
db_append_string(&sql, buf);
137
db_append_string(&sql, buf);
139
if (db_execute_immediate(driver, &sql) != DB_OK)
140
G_fatal_error(_("Unable to access table <%s>"),
143
else if ((*point->y >= Overlap.S) && (*point->y <= Overlap.N)) { /*(2) */
144
weight = (*point->x - General.W) / overlap;
145
*point->z = weight * interpolation;
147
sprintf(buf, "%lf", *point->z);
148
db_append_string(&sql, buf);
150
db_append_string(&sql, buf);
152
if (db_execute_immediate(driver, &sql) != DB_OK)
153
G_fatal_error(_("Unable to access table <%s>"),
157
else if ((*point->x >= Overlap.W) && (*point->x <= Overlap.E)){
158
if ((*point->y > Overlap.N) && (*point->y < General.N)) { /*(3) */
159
weight = (General.N - *point->y) / overlap;
160
*point->z = weight * interpolation;
162
sprintf(buf, "%lf", *point->z);
163
db_append_string(&sql, buf);
165
db_append_string(&sql, buf);
167
if (db_execute_immediate(driver, &sql) != DB_OK)
168
G_fatal_error(_("Unable to access table <%s>"),
171
else if ((*point->y < Overlap.S) && (*point->y > General.S)) { /*(1) */
172
weight = (*point->y - General.S) / overlap;
173
*point->z = (1 - weight) * interpolation;
175
sprintf(buf, "%lf", *point->z);
176
db_append_string(&sql, buf);
178
db_append_string(&sql, buf);
180
if (db_execute_immediate(driver, &sql) != DB_OK)
181
G_fatal_error(_("Unable to access table <%s>"),
189
db_commit_transaction(driver);
195
/*------------------------------------------------------------------------------------------------*/
196
double **P_Regular_Points(struct Cell_head *Elaboration, BOUND_BOX General,
197
BOUND_BOX Overlap, double **matrix, double *param,
198
double passoN, double passoE, double overlap,
199
double mean, int nsplx, int nsply, int nrows,
200
int ncols, int bilin)
203
int col, row, startcol, endcol, startrow, endrow;
204
double X, Y, interpolation, weight, csi, eta;
205
struct Cell_head Original;
207
G_get_window(&Original);
208
if (Original.north > General.N)
209
startrow = (Original.north - General.N) / Original.ns_res -1;
212
if (Original.north > General.S) {
213
endrow = (Original.north - General.S) / Original.ns_res + 1;
219
if (General.W > Original.west)
220
startcol = (General.W - Original.west) / Original.ew_res - 1;
223
if (General.E > Original.west) {
224
endcol = (General.E - Original.west) / Original.ew_res + 1;
231
for (row = startrow; row < endrow; row++) {
232
for (col = startcol; col < endcol; col++) {
233
X = G_col_to_easting((double)(col) + 0.5, &Original);
234
Y = G_row_to_northing((double)(row) + 0.5, &Original);
236
if (Vect_point_in_box(X, Y, mean, &General)) { /* Here, mean is just for asking if obs point is in box */
240
dataInterpolateBilin(X, Y, passoE, passoN, nsplx,
241
nsply, Elaboration->west,
242
Elaboration->south, param);
245
dataInterpolateBicubic(X, Y, passoE, passoN, nsplx,
246
nsply, Elaboration->west,
247
Elaboration->south, param);
249
interpolation += mean;
251
if (Vect_point_in_box(X, Y, interpolation, &Overlap)) { /* (5) */
252
matrix[row][col] = interpolation;
255
if ((X > Overlap.E) && (X < General.E)) {
256
if ((Y > Overlap.N) && (Y < General.N)) { /* (3) */
257
csi = (General.E - X) / overlap;
258
eta = (General.N - Y) / overlap;
260
interpolation *= weight;
261
matrix[row][col] += interpolation;
263
else if ((Y < Overlap.S) && (Y > General.S)) { /* (1) */
264
csi = (General.E - X) / overlap;
265
eta = (Y - General.S) / overlap;
267
interpolation *= weight;
268
matrix[row][col] = interpolation;
270
else if ((Y >= Overlap.S) && (Y <= Overlap.N)) { /* (1) */
271
weight = (General.E - X ) / overlap;
272
interpolation *= weight;
273
matrix[row][col] = interpolation;
276
else if ((X < Overlap.W) && (X > General.W)) {
277
if ((Y > Overlap.N) && (Y < General.N)) { /* (4) */
278
csi = (X - General.W) / overlap;
279
eta = (General.N - Y) / overlap;
281
interpolation *= weight;
282
matrix[row][col] += interpolation;
284
else if ((Y < Overlap.S) && (Y > General.S)) { /* (2) */
285
csi = (X - General.W) / overlap;
286
eta = (Y - General.S) / overlap;
288
interpolation *= weight;
289
matrix[row][col] += interpolation;
291
else if ((Y >= Overlap.S) && (Y <= Overlap.N)) { /* (2) */
292
weight = (X - General.W) / overlap;
293
interpolation *= weight;
294
matrix[row][col] += interpolation;
297
else if ((X >= Overlap.W) && (X <= Overlap.E)) {
298
if ((Y > Overlap.N) && (Y < General.N)) { /* (3) */
299
weight = (General.N - Y) / overlap;
300
interpolation *= weight;
301
matrix[row][col] += interpolation;
303
else if ((Y < Overlap.S) && (Y > General.S)) { /* (1) */
304
weight = (Y - General.S) / overlap;
305
interpolation *= weight;
306
matrix[row][col] = interpolation;