~ubuntu-branches/ubuntu/wily/grass/wily

« back to all changes in this revision

Viewing changes to vector/lidar/lidarlib/raster.c

Tags: 7.0.0~rc1+ds1-1~exp1
* New upstream release candidate.
* Repack upstream tarball, remove precompiled Python objects.
* Add upstream metadata.
* Update gbp.conf and Vcs-Git URL to use the experimental branch.
* Update watch file for GRASS 7.0.
* Drop build dependencies for Tcl/Tk, add build dependencies:
  python-numpy, libnetcdf-dev, netcdf-bin, libblas-dev, liblapack-dev
* Update Vcs-Browser URL to use cgit instead of gitweb.
* Update paths to use grass70.
* Add configure options: --with-netcdf, --with-blas, --with-lapack,
  remove --with-tcltk-includes.
* Update patches for GRASS 7.
* Update copyright file, changes:
  - Update copyright years
  - Group files by license
  - Remove unused license sections
* Add patches for various typos.
* Fix desktop file with patch instead of d/rules.
* Use minimal dh rules.
* Bump Standards-Version to 3.9.6, no changes.
* Use dpkg-maintscript-helper to replace directories with symlinks.
  (closes: #776349)
* Update my email to use @debian.org address.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
#include <stdio.h>
2
 
#include <stdlib.h>
3
 
#include <string.h>
4
 
 
5
 
#include <grass/gis.h>
6
 
#include <grass/Vect.h>
7
 
#include <grass/dbmi.h>
8
 
#include <grass/glocale.h>
9
 
#include <grass/config.h>
10
 
 
11
 
#include "PolimiFunct.h"
12
 
 
13
 
/*------------------------------------------------------------------------------------------------*/
14
 
void
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)
21
 
{
22
 
    int i;
23
 
    char buf[1024];
24
 
    dbString sql;
25
 
 
26
 
    double interpolation, csi, eta, weight;
27
 
    struct line_pnts *point;
28
 
 
29
 
    point = Vect_new_line_struct();
30
 
 
31
 
    db_begin_transaction(driver);
32
 
    
33
 
    for (i = 0; i < num_points; i++) {
34
 
 
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 */
36
 
 
37
 
            if (bilin)
38
 
                interpolation =
39
 
                    dataInterpolateBilin(obs[i][0], obs[i][1], pe, pn, nsplx,
40
 
                                         nsply, Elaboration->west,
41
 
                                         Elaboration->south, param);
42
 
            else
43
 
                interpolation =
44
 
                    dataInterpolateBicubic(obs[i][0], obs[i][1], pe, pn,
45
 
                                           nsplx, nsply, Elaboration->west,
46
 
                                           Elaboration->south, param);
47
 
 
48
 
            interpolation += mean;
49
 
            Vect_copy_xyz_to_pnts(point, &obs[i][0], &obs[i][1],
50
 
                                  &interpolation, 1);
51
 
 
52
 
            if (Vect_point_in_box(obs[i][0], obs[i][1], interpolation, &Overlap)) {     /*(5) */
53
 
                Vect_write_line(Out, GV_POINT, point, categories);
54
 
            }
55
 
            else {
56
 
                db_init_string(&sql);
57
 
 
58
 
                sprintf(buf, "INSERT INTO %s (ID, X, Y, Interp)", tab_name);
59
 
                db_append_string(&sql, buf);
60
 
 
61
 
                sprintf(buf, " VALUES (");
62
 
                db_append_string(&sql, buf);
63
 
                sprintf(buf, "%d, %f, %f, ", line_num[i], obs[i][0],
64
 
                        obs[i][1]);
65
 
                db_append_string(&sql, buf);
66
 
 
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;
71
 
                        weight = csi * eta;
72
 
                        *point->z = weight * interpolation;
73
 
 
74
 
                        sprintf(buf, "%lf", *point->z);
75
 
                        db_append_string(&sql, buf);
76
 
                        sprintf(buf, ")");
77
 
                        db_append_string(&sql, buf);
78
 
 
79
 
                        if (db_execute_immediate(driver, &sql) != DB_OK)
80
 
                            G_fatal_error(_("Unable to access table <%s>"),
81
 
                                          buf);
82
 
                    }
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;
86
 
                        weight = csi * eta;
87
 
                        *point->z = weight * interpolation;
88
 
 
89
 
                        sprintf(buf, "%lf", *point->z);
90
 
                        db_append_string(&sql, buf);
91
 
                        sprintf(buf, ")");
92
 
                        db_append_string(&sql, buf);
93
 
 
94
 
                        if (db_execute_immediate(driver, &sql) != DB_OK)
95
 
                            G_fatal_error(_("Unable to access table <%s>"),
96
 
                                          buf);
97
 
                    }
98
 
                    else if ((*point->y <= Overlap.N) && (*point->y >= Overlap.S)) {    /*(1) */
99
 
                        weight = (General.E - *point->x) / overlap;
100
 
                        *point->z = weight * interpolation;
101
 
 
102
 
                        sprintf(buf, "%lf", *point->z);
103
 
                        db_append_string(&sql, buf);
104
 
                        sprintf(buf, ")");
105
 
                        db_append_string(&sql, buf);
106
 
 
107
 
                        if (db_execute_immediate(driver, &sql) != DB_OK)
108
 
                            G_fatal_error(_("Unable to access table <%s>"),
109
 
                                          buf);
110
 
                    }
111
 
                }
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;
116
 
                        weight = eta * csi;
117
 
                        *point->z = weight * interpolation;
118
 
 
119
 
                        sprintf(buf, "%lf", *point->z);
120
 
                        db_append_string(&sql, buf);
121
 
                        sprintf(buf, ")");
122
 
                        db_append_string(&sql, buf);
123
 
 
124
 
                        if (db_execute_immediate(driver, &sql) != DB_OK)
125
 
                            G_fatal_error(_("Unable to access table <%s>"),
126
 
                                          buf);
127
 
                    }
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;
131
 
                        weight = csi * eta;
132
 
                        *point->z = weight * interpolation;
133
 
 
134
 
                        sprintf(buf, "%lf", *point->z);
135
 
                        db_append_string(&sql, buf);
136
 
                        sprintf(buf, ")");
137
 
                        db_append_string(&sql, buf);
138
 
 
139
 
                        if (db_execute_immediate(driver, &sql) != DB_OK)
140
 
                            G_fatal_error(_("Unable to access table <%s>"),
141
 
                                          buf);
142
 
                    }
143
 
                    else if ((*point->y >= Overlap.S) && (*point->y <= Overlap.N)) {    /*(2) */
144
 
                        weight = (*point->x - General.W) / overlap;
145
 
                        *point->z = weight * interpolation;
146
 
 
147
 
                        sprintf(buf, "%lf", *point->z);
148
 
                        db_append_string(&sql, buf);
149
 
                        sprintf(buf, ")");
150
 
                        db_append_string(&sql, buf);
151
 
 
152
 
                        if (db_execute_immediate(driver, &sql) != DB_OK)
153
 
                            G_fatal_error(_("Unable to access table <%s>"),
154
 
                                          buf);
155
 
                    }
156
 
                }
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;
161
 
 
162
 
                        sprintf(buf, "%lf", *point->z);
163
 
                        db_append_string(&sql, buf);
164
 
                        sprintf(buf, ")");
165
 
                        db_append_string(&sql, buf);
166
 
 
167
 
                        if (db_execute_immediate(driver, &sql) != DB_OK)
168
 
                            G_fatal_error(_("Unable to access table <%s>"),
169
 
                                          buf);
170
 
                    }
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;
174
 
 
175
 
                        sprintf(buf, "%lf", *point->z);
176
 
                        db_append_string(&sql, buf);
177
 
                        sprintf(buf, ")");
178
 
                        db_append_string(&sql, buf);
179
 
 
180
 
                        if (db_execute_immediate(driver, &sql) != DB_OK)
181
 
                            G_fatal_error(_("Unable to access table <%s>"),
182
 
                                          buf);
183
 
                    }
184
 
                }
185
 
            }
186
 
        }  /*IF*/
187
 
    }  /*FOR*/
188
 
 
189
 
    db_commit_transaction(driver);
190
 
 
191
 
    return;
192
 
}
193
 
 
194
 
 
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)
201
 
{
202
 
 
203
 
    int col, row, startcol, endcol, startrow, endrow;
204
 
    double X, Y, interpolation, weight, csi, eta;
205
 
    struct Cell_head Original;
206
 
 
207
 
    G_get_window(&Original);
208
 
    if (Original.north > General.N)
209
 
        startrow = (Original.north - General.N) / Original.ns_res -1;
210
 
    else
211
 
        startrow = 0;
212
 
    if (Original.north > General.S) {
213
 
        endrow = (Original.north - General.S) / Original.ns_res + 1;
214
 
        if (endrow > nrows)
215
 
            endrow = nrows;
216
 
    }
217
 
    else
218
 
        endrow = nrows;
219
 
    if (General.W > Original.west)
220
 
        startcol = (General.W - Original.west) / Original.ew_res - 1;
221
 
    else
222
 
        startcol = 0;
223
 
    if (General.E > Original.west) {
224
 
        endcol = (General.E - Original.west) / Original.ew_res + 1;
225
 
        if (endcol > ncols)
226
 
            endcol = ncols;
227
 
    }
228
 
    else
229
 
        endcol = ncols;
230
 
 
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);
235
 
 
236
 
            if (Vect_point_in_box(X, Y, mean, &General)) {      /* Here, mean is just for asking if obs point is in box */
237
 
 
238
 
                if (bilin)
239
 
                    interpolation =
240
 
                        dataInterpolateBilin(X, Y, passoE, passoN, nsplx,
241
 
                                             nsply, Elaboration->west,
242
 
                                             Elaboration->south, param);
243
 
                else
244
 
                    interpolation =
245
 
                        dataInterpolateBicubic(X, Y, passoE, passoN, nsplx,
246
 
                                               nsply, Elaboration->west,
247
 
                                               Elaboration->south, param);
248
 
 
249
 
                interpolation += mean;
250
 
 
251
 
                if (Vect_point_in_box(X, Y, interpolation, &Overlap)) { /* (5) */
252
 
                    matrix[row][col] = interpolation;
253
 
                }
254
 
                else {
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;
259
 
                            weight = csi * eta;
260
 
                            interpolation *= weight;
261
 
                            matrix[row][col] += interpolation;
262
 
                        }
263
 
                        else if ((Y < Overlap.S) && (Y > General.S)) {  /* (1) */
264
 
                            csi = (General.E - X) / overlap;
265
 
                            eta = (Y - General.S) / overlap;
266
 
                            weight = csi * eta;
267
 
                            interpolation *= weight;
268
 
                            matrix[row][col] = interpolation;
269
 
                        }
270
 
                        else if ((Y >= Overlap.S) && (Y <= Overlap.N)) {        /* (1) */
271
 
                            weight = (General.E - X ) / overlap;
272
 
                            interpolation *= weight;
273
 
                            matrix[row][col] = interpolation;
274
 
                        }
275
 
                    }
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;
280
 
                            weight = eta * csi;
281
 
                            interpolation *= weight;
282
 
                            matrix[row][col] += interpolation;
283
 
                        }
284
 
                        else if ((Y < Overlap.S) && (Y > General.S)) {  /* (2) */
285
 
                            csi = (X - General.W) / overlap;
286
 
                            eta = (Y - General.S) / overlap;
287
 
                            weight = csi * eta;
288
 
                            interpolation *= weight;
289
 
                            matrix[row][col] += interpolation;
290
 
                        }
291
 
                        else if ((Y >= Overlap.S) && (Y <= Overlap.N)) {        /* (2) */
292
 
                            weight = (X - General.W) / overlap;
293
 
                            interpolation *= weight;
294
 
                            matrix[row][col] += interpolation;
295
 
                        }
296
 
                    }
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;
302
 
                        }
303
 
                        else if ((Y < Overlap.S) && (Y > General.S)) {  /* (1) */
304
 
                            weight = (Y - General.S) / overlap;
305
 
                            interpolation *= weight;
306
 
                            matrix[row][col] = interpolation;
307
 
                        }
308
 
                    }
309
 
                }
310
 
            }
311
 
        }                       /* END COL */
312
 
    }                           /* END ROW */
313
 
    return matrix;
314
 
}