22
24
struct cache *ibuffer;
24
26
select_current_env();
25
if (G_get_cellhd(name, mapset, &cellhd) < 0)
27
Rast_get_cellhd(name, mapset, &cellhd);
28
29
/* open the file to be rectified
29
30
* set window to cellhd first to be able to read file exactly
31
G_set_window(&cellhd);
32
infd = G_open_cell_old(name, mapset);
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);
39
37
ibuffer = readcell(infd, seg_mb);
41
G_close_cell(infd); /* (pmx) 17 april 2000 */
39
Rast_close(infd); /* (pmx) 17 april 2000 */
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());
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);
58
55
/* open the result file into target window
61
58
* but those open for reading are
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);
67
64
for (row = 0; row < nrows; row++) {
68
65
n1 = target_window.north - (row + 0.5) * target_window.ns_res;
70
67
G_percent(row, nrows, 2);
72
G_set_null_value(trast, ncols, map_type);
69
Rast_set_null_value(trast, ncols, map_type);
74
71
for (col = 0; col < ncols; col++) {
75
72
e1 = target_window.west + (col + 0.5) * target_window.ew_res;
77
74
/* backwards transformation of target cell center */
78
CRS_georef(e1, n1, &ex, &nx, E21, N21, order);
76
I_georef_tps(e1, n1, &ex, &nx, E21_t, N21_t, &cp, 0);
78
I_georef(e1, n1, &ex, &nx, E21, N21, order);
80
80
/* convert to row/column indices of source raster */
81
81
row_idx = (cellhd.north - nx) / cellhd.ns_res;
87
87
tptr = G_incr_void_ptr(tptr, cell_size);
89
G_put_raster_row(outfd, trast, map_type);
89
Rast_put_row(outfd, trast, map_type);
91
91
G_percent(1, 1, 1);
93
G_close_cell(outfd); /* (pmx) 17 april 2000 */
93
Rast_close(outfd); /* (pmx) 17 april 2000 */
96
96
close(ibuffer->fd);
99
if (G_get_cellhd(result, G_mapset(), &cellhd) < 0)
99
Rast_get_cellhd(result, G_mapset(), &cellhd);
102
101
if (cellhd.proj == 0) { /* x,y imagery */
103
102
cellhd.proj = target_window.proj;