1 #include <grass/config.h>
5 #include <grass/lidar.h>
10 struct bound_box General,
struct bound_box Overlap,
double **obs,
11 double *param,
int *line_num,
double pe,
double pn,
12 double overlap,
int nsplx,
int nsply,
int num_points,
13 int bilin,
struct line_cats *categories, dbDriver *
driver,
14 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, &General)) {
34 nsply, Elaboration->west,
35 Elaboration->south, param);
39 nsplx, nsply, Elaboration->west,
40 Elaboration->south, param);
42 interpolation += mean;
43 Vect_copy_xyz_to_pnts(point, &obs[i][0], &obs[i][1],
46 if (Vect_point_in_box(obs[i][0], obs[i][1], interpolation, &Overlap)) {
47 Vect_write_line(Out, GV_POINT, point, categories);
52 sprintf(buf,
"INSERT INTO %s (ID, X, Y, Interp)", tab_name);
53 db_append_string(&sql, buf);
55 sprintf(buf,
" VALUES (");
56 db_append_string(&sql, buf);
57 sprintf(buf,
"%d, %f, %f, ", line_num[i], obs[i][0],
59 db_append_string(&sql, buf);
61 if ((*point->x > Overlap.E) && (*point->x < General.E)) {
62 if ((*point->y > Overlap.N) && (*point->y < General.N)) {
63 csi = (General.E - *point->x) / overlap;
64 eta = (General.N - *point->y) / overlap;
66 *point->z = weight * interpolation;
68 sprintf(buf,
"%lf", *point->z);
69 db_append_string(&sql, buf);
71 db_append_string(&sql, buf);
73 if (db_execute_immediate(
driver, &sql) != DB_OK)
77 else if ((*point->y < Overlap.S) && (*point->y > General.S)) {
78 csi = (General.E - *point->x) / overlap;
79 eta = (*point->y - General.S) / overlap;
81 *point->z = weight * interpolation;
83 sprintf(buf,
"%lf", *point->z);
84 db_append_string(&sql, buf);
86 db_append_string(&sql, buf);
88 if (db_execute_immediate(
driver, &sql) != DB_OK)
92 else if ((*point->y <= Overlap.N) && (*point->y >= Overlap.S)) {
93 weight = (General.E - *point->x) / overlap;
94 *point->z = weight * interpolation;
96 sprintf(buf,
"%lf", *point->z);
97 db_append_string(&sql, buf);
99 db_append_string(&sql, buf);
101 if (db_execute_immediate(
driver, &sql) != DB_OK)
106 else if ((*point->x < Overlap.W) && (*point->x > General.W)) {
107 if ((*point->y > Overlap.N) && (*point->y < General.N)) {
108 csi = (*point->x - General.W) / overlap;
109 eta = (General.N - *point->y) / overlap;
111 *point->z = weight * interpolation;
113 sprintf(buf,
"%lf", *point->z);
114 db_append_string(&sql, buf);
116 db_append_string(&sql, buf);
118 if (db_execute_immediate(
driver, &sql) != DB_OK)
122 else if ((*point->y < Overlap.S) && (*point->y > General.S)) {
123 csi = (*point->x - General.W) / overlap;
124 eta = (*point->y - General.S) / overlap;
126 *point->z = weight * interpolation;
128 sprintf(buf,
"%lf", *point->z);
129 db_append_string(&sql, buf);
131 db_append_string(&sql, buf);
133 if (db_execute_immediate(
driver, &sql) != DB_OK)
137 else if ((*point->y >= Overlap.S) && (*point->y <= Overlap.N)) {
138 weight = (*point->x - General.W) / overlap;
139 *point->z = weight * interpolation;
141 sprintf(buf,
"%lf", *point->z);
142 db_append_string(&sql, buf);
144 db_append_string(&sql, buf);
146 if (db_execute_immediate(
driver, &sql) != DB_OK)
151 else if ((*point->x >= Overlap.W) && (*point->x <= Overlap.E)){
152 if ((*point->y > Overlap.N) && (*point->y < General.N)) {
153 weight = (General.N - *point->y) / overlap;
154 *point->z = weight * interpolation;
156 sprintf(buf,
"%lf", *point->z);
157 db_append_string(&sql, buf);
159 db_append_string(&sql, buf);
161 if (db_execute_immediate(
driver, &sql) != DB_OK)
165 else if ((*point->y < Overlap.S) && (*point->y > General.S)) {
166 weight = (*point->y - General.S) / overlap;
167 *point->z = (1 - weight) * interpolation;
169 sprintf(buf,
"%lf", *point->z);
170 db_append_string(&sql, buf);
172 db_append_string(&sql, buf);
174 if (db_execute_immediate(
driver, &sql) != DB_OK)
183 db_commit_transaction(
driver);
191 struct bound_box General,
struct bound_box Overlap,
192 SEGMENT *out_seg,
double *param,
193 double passoN,
double passoE,
double overlap,
194 double mean,
int nsplx,
int nsply,
195 int nrows,
int ncols,
int bilin)
198 int col, row, startcol, endcol, startrow, endrow;
199 double X,
Y, interpolation, weight, csi, eta, dval;
202 if (Original->north > General.N)
203 startrow = (Original->north - General.N) / Original->ns_res - 1;
206 if (Original->north > General.S) {
207 endrow = (Original->north - General.S) / Original->ns_res + 1;
213 if (General.W > Original->west)
214 startcol = (General.W - Original->west) / Original->ew_res - 1;
217 if (General.E > Original->west) {
218 endcol = (General.E - Original->west) / Original->ew_res + 1;
225 for (row = startrow; row < endrow; row++) {
226 for (col = startcol; col < endcol; col++) {
228 X = Rast_col_to_easting((
double)(col) + 0.5, Original);
229 Y = Rast_row_to_northing((
double)(row) + 0.5, Original);
231 if (Vect_point_in_box(
X,
Y, mean, &General)) {
236 nsply, Elaboration->west,
237 Elaboration->south, param);
241 nsply, Elaboration->west,
242 Elaboration->south, param);
244 interpolation += mean;
246 if (Vect_point_in_box(
X,
Y, interpolation, &Overlap)) {
247 dval = interpolation;
251 if ((
X > Overlap.E) && (
X < General.E)) {
252 if ((
Y > Overlap.N) && (
Y < General.N)) {
253 csi = (General.E -
X) / overlap;
254 eta = (General.N -
Y) / overlap;
256 interpolation *= weight;
257 dval += interpolation;
259 else if ((
Y < Overlap.S) && (
Y > General.S)) {
260 csi = (General.E -
X) / overlap;
261 eta = (
Y - General.S) / overlap;
263 interpolation *= weight;
264 dval = interpolation;
266 else if ((
Y >= Overlap.S) && (
Y <= Overlap.N)) {
267 weight = (General.E -
X ) / overlap;
268 interpolation *= weight;
269 dval = interpolation;
272 else if ((
X < Overlap.W) && (
X > General.W)) {
273 if ((
Y > Overlap.N) && (
Y < General.N)) {
274 csi = (
X - General.W) / overlap;
275 eta = (General.N -
Y) / overlap;
277 interpolation *= weight;
278 dval += interpolation;
280 else if ((
Y < Overlap.S) && (
Y > General.S)) {
281 csi = (
X - General.W) / overlap;
282 eta = (
Y - General.S) / overlap;
284 interpolation *= weight;
285 dval += interpolation;
287 else if ((
Y >= Overlap.S) && (
Y <= Overlap.N)) {
288 weight = (
X - General.W) / overlap;
289 interpolation *= weight;
290 dval += interpolation;
293 else if ((
X >= Overlap.W) && (
X <= Overlap.E)) {
294 if ((
Y > Overlap.N) && (
Y < General.N)) {
295 weight = (General.N -
Y) / overlap;
296 interpolation *= weight;
297 dval += interpolation;
299 else if ((
Y < Overlap.S) && (
Y > General.S)) {
300 weight = (
Y - General.S) / overlap;
301 interpolation *= weight;
302 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)
if(!DBFLoadRecord(psDBF, hEntity)) return NULL
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)