~ubuntu-branches/ubuntu/vivid/grass/vivid-proposed

« back to all changes in this revision

Viewing changes to vector/v.transform/trans_digit.c

  • Committer: Package Import Robot
  • Author(s): Bas Couwenberg
  • Date: 2015-02-20 23:12:08 UTC
  • mfrom: (8.2.6 experimental)
  • Revision ID: package-import@ubuntu.com-20150220231208-1u6qvqm84v430b10
Tags: 7.0.0-1~exp1
* New upstream release.
* Update python-ctypes-ternary.patch to use if/else instead of and/or.
* Drop check4dev patch, rely on upstream check.
* Add build dependency on libpq-dev to grass-dev for libpq-fe.h.
* Drop patches applied upstream, refresh remaining patches.
* Update symlinks for images switched from jpg to png.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
/* **************************************************************************
2
 
 *
3
 
 * MODULE:       v.transform
4
 
 * AUTHOR(S):    See other files as well...
5
 
 *               Eric G. Miller <egm2@jps.net>
6
 
 *               Radim Blazek
7
 
 *               DB support added by Martin Landa (08/2007)
8
 
 *
9
 
 * PURPOSE:      To transform a vector layer's coordinates via a set of tie
10
 
 *               points.
11
 
 *
12
 
 * COPYRIGHT:    (C) 2002-2007 by the GRASS Development Team
13
 
 *
14
 
 *               This program is free software under the GNU General Public
15
 
 *              License (>=v2). Read the file COPYING that comes with GRASS
16
 
 *              for details.
17
 
 *
18
 
 *****************************************************************************/
19
 
 
20
1
#include <math.h>
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>
27
7
 
28
8
#define PI M_PI
29
9
 
30
 
int
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)
34
13
{
35
 
    int i, type, cat, ret;
 
14
    int i, type, cat, line, ret;
 
15
    int verbose, format;
36
16
    unsigned int j;
37
17
    double *trans_params;
38
18
    double ang, x, y;
50
30
    Points = Vect_new_line_struct();
51
31
    Cats = Vect_new_cats_struct();
52
32
 
53
 
    if (table || field > 0) {
54
 
        if (table) {
55
 
            fi = Vect_default_field_info(Old, 1, NULL, GV_1TABLE);
56
 
            fi->table = table;
57
 
        }
58
 
        else
59
 
            fi = Vect_get_field(Old, field);
60
 
        
 
33
    driver = NULL;
 
34
    fi = NULL;
 
35
    if (field > 0) {
 
36
        fi = Vect_get_field(Old, field);
61
37
 
62
38
        driver = db_start_driver_open_database(fi->driver, fi->database);
63
39
        if (!driver)
69
45
    else {
70
46
        trans_params = trans_params_def;
71
47
        ang = PI * trans_params[IDX_ZROT] / 180;
72
 
        fi = NULL;
73
 
        driver = NULL;
74
48
    }
75
49
 
 
50
    line = 0;
76
51
    ret = 1;
77
 
    while (1) {
 
52
    format = G_info_format();
 
53
    verbose = G_verbose() > G_verbose_min();
 
54
    while (TRUE) {
78
55
        type = Vect_read_next_line(Old, Points, Cats);
79
56
 
80
57
        if (type == -1) {       /* error */
87
64
            break;
88
65
        }
89
66
 
 
67
        if (field != -1 && !Vect_cat_get(Cats, field, NULL))
 
68
            continue;
 
69
        
 
70
        if (verbose && line % 1000 == 0) {
 
71
            if (format == G_INFO_FORMAT_PLAIN)
 
72
                fprintf(stderr, "%d..", line);
 
73
            else
 
74
                fprintf(stderr, "%11d\b\b\b\b\b\b\b\b\b\b\b", line);
 
75
        }
 
76
        
90
77
        if (swap) {
91
78
            for (i = 0; i < Points->n_points; i++) {
92
79
                x = Points->x[i];
111
98
                    case DB_C_TYPE_STRING:
112
99
                        break;
113
100
                    case -1:
114
 
                        G_fatal_error(_("Missing column <%s> in table <%s>"),
 
101
                        G_fatal_error(_("Column <%s> not found in table <%s>"),
115
102
                                      columns[j], fi->table);
116
103
                    default:
117
104
                        G_fatal_error(_("Unsupported column type of <%s>"),
144
131
 
145
132
        /* transform points */
146
133
        for (i = 0; i < Points->n_points; i++) {
147
 
            if (shift_file) {
148
 
                transform_a_into_b(Points->x[i], Points->y[i],
149
 
                                   &(Points->x[i]), &(Points->y[i]));
150
 
            }
151
 
            else {
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]);
158
140
 
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);
166
 
                Points->x[i] = x;
167
 
                Points->y[i] = y;
168
 
            }
 
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);
 
148
            Points->x[i] = x;
 
149
            Points->y[i] = y;
169
150
 
170
151
            /* ztozero shifts oldmap z to zero, zshift shifts rescaled object
171
152
             * to target elevation: */
175
156
        }
176
157
 
177
158
        Vect_write_line(New, type, Points, Cats);
 
159
        line++;
178
160
    }
179
161
 
 
162
    if (verbose && format != G_INFO_FORMAT_PLAIN)
 
163
        fprintf(stderr, "\r");
 
164
    
180
165
    if (field > 0) {
181
166
        db_close_database_shutdown_driver(driver);
182
167
        G_free((void *)trans_params);