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

« back to all changes in this revision

Viewing changes to imagery/i.rectify/rectify.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
1
#include <unistd.h>
2
2
#include <string.h>
 
3
 
 
4
#include <grass/raster.h>
3
5
#include <grass/glocale.h>
 
6
 
4
7
#include "global.h"
5
 
#include "crs.h"                /* CRS HEADER FILE */
6
8
 
7
9
/* Modified to support Grass 5.0 fp format 11 april 2000
8
10
 *
22
24
    struct cache *ibuffer;
23
25
 
24
26
    select_current_env();
25
 
    if (G_get_cellhd(name, mapset, &cellhd) < 0)
26
 
        return 0;
 
27
    Rast_get_cellhd(name, mapset, &cellhd);
27
28
 
28
29
    /* open the file to be rectified
29
30
     * set window to cellhd first to be able to read file exactly
30
31
     */
31
 
    G_set_window(&cellhd);
32
 
    infd = G_open_cell_old(name, mapset);
33
 
    if (infd < 0) {
34
 
        return 0;
35
 
    }
36
 
    map_type = G_get_raster_map_type(infd);
37
 
    cell_size = G_raster_size(map_type);
 
32
    Rast_set_input_window(&cellhd);
 
33
    infd = Rast_open_old(name, mapset);
 
34
    map_type = Rast_get_map_type(infd);
 
35
    cell_size = Rast_cell_size(map_type);
38
36
 
39
37
    ibuffer = readcell(infd, seg_mb);
40
38
 
41
 
    G_close_cell(infd);         /* (pmx) 17 april 2000 */
 
39
    Rast_close(infd);           /* (pmx) 17 april 2000 */
42
40
 
43
41
    G_message(_("Rectify <%s@%s> (location <%s>)"),
44
42
              name, mapset, G_location());
45
43
    select_target_env();
46
 
    G_set_window(&target_window);
47
44
    G_message(_("into  <%s@%s> (location <%s>) ..."),
48
45
              result, G_mapset(), G_location());
49
46
 
52
49
 
53
50
    if (strcmp(interp_method, "nearest") != 0) {
54
51
        map_type = DCELL_TYPE;
55
 
        cell_size = G_raster_size(map_type);
 
52
        cell_size = Rast_cell_size(map_type);
56
53
    }
57
54
 
58
55
    /* open the result file into target window
61
58
     * but those open for reading are
62
59
     */
63
60
 
64
 
    outfd = G_open_raster_new(result, map_type);
65
 
    trast = G_allocate_raster_buf(map_type);
 
61
    outfd = Rast_open_new(result, map_type);
 
62
    trast = Rast_allocate_output_buf(map_type);
66
63
 
67
64
    for (row = 0; row < nrows; row++) {
68
65
        n1 = target_window.north - (row + 0.5) * target_window.ns_res;
69
66
 
70
67
        G_percent(row, nrows, 2);
71
 
        
72
 
        G_set_null_value(trast, ncols, map_type);
 
68
 
 
69
        Rast_set_null_value(trast, ncols, map_type);
73
70
        tptr = trast;
74
71
        for (col = 0; col < ncols; col++) {
75
72
            e1 = target_window.west + (col + 0.5) * target_window.ew_res;
76
73
 
77
74
            /* backwards transformation of target cell center */
78
 
            CRS_georef(e1, n1, &ex, &nx, E21, N21, order);
 
75
            if (order == 0)
 
76
                I_georef_tps(e1, n1, &ex, &nx, E21_t, N21_t, &cp, 0);
 
77
            else
 
78
                I_georef(e1, n1, &ex, &nx, E21, N21, order);
79
79
 
80
80
            /* convert to row/column indices of source raster */
81
81
            row_idx = (cellhd.north - nx) / cellhd.ns_res;
86
86
 
87
87
            tptr = G_incr_void_ptr(tptr, cell_size);
88
88
        }
89
 
        G_put_raster_row(outfd, trast, map_type);
 
89
        Rast_put_row(outfd, trast, map_type);
90
90
    }
91
91
    G_percent(1, 1, 1);
92
92
 
93
 
    G_close_cell(outfd);                /* (pmx) 17 april 2000 */
 
93
    Rast_close(outfd);          /* (pmx) 17 april 2000 */
94
94
    G_free(trast);
95
95
 
96
96
    close(ibuffer->fd);
97
97
    G_free(ibuffer);
98
98
 
99
 
    if (G_get_cellhd(result, G_mapset(), &cellhd) < 0)
100
 
        return 0;
 
99
    Rast_get_cellhd(result, G_mapset(), &cellhd);
101
100
 
102
101
    if (cellhd.proj == 0) {     /* x,y imagery */
103
102
        cellhd.proj = target_window.proj;