87
87
row, col, /* counters */
88
88
irows, icols, /* original rows, cols */
89
89
orows, ocols, have_colors, /* Input map has a colour table */
90
overwrite; /* Overwrite */
90
overwrite, /* Overwrite */
91
curr_proj; /* output projection (see gis.h) */
92
93
void *obuffer, /* buffer that holds one output row */
93
94
*obufptr; /* column ptr in output buffer */
100
101
row_idx, /* row index in input matrix */
101
102
onorth, osouth, /* save original border coords */
102
103
oeast, owest, inorth, isouth, ieast, iwest;
104
char north_str[30], south_str[30], east_str[30], west_str[30];
104
106
struct Colors colr; /* Input map colour table */
105
107
struct History history;
114
116
struct GModule *module;
116
118
struct Flag *list, /* list files in source location */
117
*nocrop; /* don't crop output map */
119
*nocrop, /* don't crop output map */
120
*print_bounds, /* print output bounds and exit */
121
*gprint_bounds; /* same but print shell style */
119
123
struct Option *imapset, /* name of input mapset */
120
124
*inmap, /* name of input layer */
132
136
G_gisinit(argv[0]);
134
138
module = G_define_module();
135
module->keywords = _("raster, projection");
136
module->description =
139
module->keywords = _("raster, projection, transformation");
140
module->description =
137
141
_("Re-projects a raster map from one location to the current location.");
139
143
inmap = G_define_standard_option(G_OPT_R_INPUT);
140
144
inmap->description = _("Name of input raster map to re-project");
141
145
inmap->required = NO;
146
inmap->guisection = _("Source");
143
148
inlocation = G_define_option();
144
149
inlocation->key = "location";
145
150
inlocation->type = TYPE_STRING;
146
151
inlocation->required = YES;
147
inlocation->description = _("Location of input raster map");
152
inlocation->description = _("Location containing input raster map");
153
inlocation->gisprompt = "old,location,location";
154
inlocation->key_desc = "name";
149
156
imapset = G_define_option();
150
157
imapset->key = "mapset";
151
158
imapset->type = TYPE_STRING;
152
159
imapset->required = NO;
153
imapset->description = _("Mapset of input raster map");
160
imapset->description = _("Mapset containing input raster map");
161
imapset->gisprompt = "old,mapset,mapset";
162
imapset->key_desc = "name";
163
imapset->guisection = _("Source");
155
165
indbase = G_define_option();
156
166
indbase->key = "dbase";
157
167
indbase->type = TYPE_STRING;
158
168
indbase->required = NO;
159
169
indbase->description = _("Path to GRASS database of input location");
170
indbase->gisprompt = "old,dbase,dbase";
171
indbase->key_desc = "path";
172
indbase->guisection = _("Source");
161
174
outmap = G_define_standard_option(G_OPT_R_OUTPUT);
162
175
outmap->required = NO;
163
176
outmap->description = _("Name for output raster map (default: input)");
177
outmap->guisection = _("Target");
165
179
ipolname = make_ipol_list();
167
181
interpol = G_define_option();
171
185
interpol->answer = "nearest";
172
186
interpol->options = ipolname;
173
187
interpol->description = _("Interpolation method to use");
188
interpol->guisection = _("Target");
175
190
memory = G_define_option();
176
191
memory->key = "memory";
192
208
nocrop->key = 'n';
193
209
nocrop->description = _("Do not perform region cropping optimization");
211
print_bounds = G_define_flag();
212
print_bounds->key = 'p';
213
print_bounds->description =
214
_("Print input map's bounds in the current projection and exit");
215
print_bounds->guisection = _("Target");
217
gprint_bounds = G_define_flag();
218
gprint_bounds->key = 'g';
219
gprint_bounds->description =
220
_("Print input map's bounds in the current projection and exit (shell style)");
221
gprint_bounds->guisection = _("Target");
195
223
/* The parser checks if the map already exists in current mapset,
196
224
we switch out the check and do it
197
225
in the module after the parser */
216
245
G_fatal_error(_("option <%s>: <%s> exists."), "output", mapname);
218
247
setname = imapset->answer ? imapset->answer : G_store(G_mapset());
220
if (strcmp(inlocation->answer, G_location()) == 0)
221
G_fatal_error(_("You have to use a different location for input than the current"));
248
if (strcmp(inlocation->answer, G_location()) == 0 &&
249
(!indbase->answer || strcmp(indbase->answer, G_gisdbase()) == 0))
251
G_fatal_error(_("Input and output locations can not be the same"));
253
G_warning(_("Input and output locations are the same"));
223
255
G_get_window(&outcellhd);
257
if(gprint_bounds->answer && !print_bounds->answer)
258
print_bounds->answer = gprint_bounds->answer;
259
curr_proj = G_projection();
225
261
/* Get projection info for output mapset */
226
262
if ((out_proj_info = G_get_projinfo()) == NULL)
227
263
G_fatal_error(_("Unable to get projection info of output raster map"));
247
283
/* if requested, list the raster maps in source location - MN 5/2001 */
248
284
if (list->answer) {
249
if (isatty(0)) /* check if on command line */
250
G_message(_("Checking location <%s>, mapset <%s>..."),
251
inlocation->answer, setname);
252
G_list_element("cell", "raster", setname, 0);
253
exit(EXIT_SUCCESS); /* leave r.proj after listing */
287
G_verbose_message(_("Checking location <%s> mapset <%s>"),
288
inlocation->answer, imapset->answer);
289
list = G_list(G_ELEMENT_RASTER, G__getenv("GISDBASE"),
290
G__getenv("LOCATION_NAME"), imapset->answer);
291
for (i = 0; list[i]; i++) {
292
fprintf(stdout, "%s\n", list[i]);
295
exit(EXIT_SUCCESS); /* leave v.proj after listing */
256
298
if (!inmap->answer)
302
344
orows = outcellhd.rows;
303
345
ocols = outcellhd.cols;
348
if (print_bounds->answer) {
349
G_message(_("Input map <%s@%s> in location <%s>:"),
350
inmap->answer, setname, inlocation->answer);
352
if (pj_do_proj(&iwest, &isouth, &iproj, &oproj) < 0)
353
G_fatal_error(_("Error in pj_do_proj (projection of input coordinate pair)"));
354
if (pj_do_proj(&ieast, &inorth, &iproj, &oproj) < 0)
355
G_fatal_error(_("Error in pj_do_proj (projection of input coordinate pair)"));
357
G_format_northing(inorth, north_str, curr_proj);
358
G_format_northing(isouth, south_str, curr_proj);
359
G_format_easting(ieast, east_str, curr_proj);
360
G_format_easting(iwest, west_str, curr_proj);
362
if(gprint_bounds->answer) {
363
fprintf(stdout, "n=%s s=%s w=%s e=%s rows=%d cols=%d\n",
364
north_str, south_str, west_str, east_str, irows, icols);
367
fprintf(stdout, "Source cols: %d\n", icols);
368
fprintf(stdout, "Source rows: %d\n", irows);
369
fprintf(stdout, "Local north: %s\n", north_str);
370
fprintf(stdout, "Local south: %s\n", south_str);
371
fprintf(stdout, "Local west: %s\n", west_str);
372
fprintf(stdout, "Local east: %s\n", east_str);
375
/* somehow approximate local ewres, nsres ?? (use 'g.region -m' on lat/lon side) */
305
381
/* Cut non-overlapping parts of input map */
306
382
if (!nocrop->answer)
307
383
bordwalk(&outcellhd, &incellhd, &oproj, &iproj);
358
434
G_adjust_Cell_head(&outcellhd, 0, 0);
359
435
G_set_window(&outcellhd);
362
438
G_message(_("Input:"));
363
439
G_message(_("Cols: %d (%d)"), incellhd.cols, icols);
364
440
G_message(_("Rows: %d (%d)"), incellhd.rows, irows);
368
444
G_message(_("East: %f (%f)"), incellhd.east, ieast);
369
445
G_message(_("EW-res: %f"), incellhd.ew_res);
370
446
G_message(_("NS-res: %f"), incellhd.ns_res);
373
449
G_message(_("Output:"));
374
450
G_message(_("Cols: %d (%d)"), outcellhd.cols, ocols);
375
451
G_message(_("Rows: %d (%d)"), outcellhd.rows, orows);
379
455
G_message(_("East: %f (%f)"), outcellhd.east, oeast);
380
456
G_message(_("EW-res: %f"), outcellhd.ew_res);
381
457
G_message(_("NS-res: %f"), outcellhd.ns_res);
384
460
/* open and read the relevant parts of the input map and close it */