1
/* **************************************************************************
4
* AUTHOR(S): See other files as well...
5
* Eric G. Miller <egm2@jps.net>
7
* DB support added by Martin Landa (08/2007)
9
* PURPOSE: To transform a vector layer's coordinates via a set of tie
12
* COPYRIGHT: (C) 2002-2007 by the GRASS Development Team
14
* This program is free software under the GNU General Public
15
* License (>=v2). Read the file COPYING that comes with GRASS
18
*****************************************************************************/
21
#include <grass/libtrans.h>
22
#include <grass/Vect.h>
2
#include <grass/vector.h>
23
3
#include <grass/gis.h>
24
4
#include <grass/dbmi.h>
25
5
#include <grass/glocale.h>
31
transform_digit_file(struct Map_info *Old, struct Map_info *New,
32
int shift_file, double ztozero, int swap, double *trans_params_def,
33
char *table, char **columns, int field)
10
int transform_digit_file(struct Map_info *Old, struct Map_info *New,
11
double ztozero, int swap, double *trans_params_def,
12
char **columns, int field)
35
int i, type, cat, ret;
14
int i, type, cat, line, ret;
37
17
double *trans_params;
50
30
Points = Vect_new_line_struct();
51
31
Cats = Vect_new_cats_struct();
53
if (table || field > 0) {
55
fi = Vect_default_field_info(Old, 1, NULL, GV_1TABLE);
59
fi = Vect_get_field(Old, field);
36
fi = Vect_get_field(Old, field);
62
38
driver = db_start_driver_open_database(fi->driver, fi->database);
70
46
trans_params = trans_params_def;
71
47
ang = PI * trans_params[IDX_ZROT] / 180;
52
format = G_info_format();
53
verbose = G_verbose() > G_verbose_min();
78
55
type = Vect_read_next_line(Old, Points, Cats);
80
57
if (type == -1) { /* error */
67
if (field != -1 && !Vect_cat_get(Cats, field, NULL))
70
if (verbose && line % 1000 == 0) {
71
if (format == G_INFO_FORMAT_PLAIN)
72
fprintf(stderr, "%d..", line);
74
fprintf(stderr, "%11d\b\b\b\b\b\b\b\b\b\b\b", line);
91
78
for (i = 0; i < Points->n_points; i++) {
145
132
/* transform points */
146
133
for (i = 0; i < Points->n_points; i++) {
148
transform_a_into_b(Points->x[i], Points->y[i],
149
&(Points->x[i]), &(Points->y[i]));
152
G_debug(3, "idx=%d, cat=%d, xshift=%g, yshift=%g, zshift=%g, "
153
"xscale=%g, yscale=%g, zscale=%g, zrot=%g",
154
i, cat, trans_params[IDX_XSHIFT],
155
trans_params[IDX_YSHIFT], trans_params[IDX_ZSHIFT],
156
trans_params[IDX_XSCALE], trans_params[IDX_YSCALE],
157
trans_params[IDX_ZSCALE], trans_params[IDX_ZROT]);
134
G_debug(3, "idx=%d, cat=%d, xshift=%g, yshift=%g, zshift=%g, "
135
"xscale=%g, yscale=%g, zscale=%g, zrot=%g",
136
i, cat, trans_params[IDX_XSHIFT],
137
trans_params[IDX_YSHIFT], trans_params[IDX_ZSHIFT],
138
trans_params[IDX_XSCALE], trans_params[IDX_YSCALE],
139
trans_params[IDX_ZSCALE], trans_params[IDX_ZROT]);
159
/* transform point */
160
x = trans_params[IDX_XSHIFT] +
161
trans_params[IDX_XSCALE] * Points->x[i] * cos(ang)
162
- trans_params[IDX_YSCALE] * Points->y[i] * sin(ang);
163
y = trans_params[IDX_YSHIFT] +
164
trans_params[IDX_XSCALE] * Points->x[i] * sin(ang)
165
+ trans_params[IDX_YSCALE] * Points->y[i] * cos(ang);
141
/* transform point */
142
x = trans_params[IDX_XSHIFT] +
143
trans_params[IDX_XSCALE] * Points->x[i] * cos(ang)
144
- trans_params[IDX_YSCALE] * Points->y[i] * sin(ang);
145
y = trans_params[IDX_YSHIFT] +
146
trans_params[IDX_XSCALE] * Points->x[i] * sin(ang)
147
+ trans_params[IDX_YSCALE] * Points->y[i] * cos(ang);
170
151
/* ztozero shifts oldmap z to zero, zshift shifts rescaled object
171
152
* to target elevation: */