[GRASS-SVN] r45130 - grass/branches/develbranch_6/imagery/i.rectify
svn_grass at osgeo.org
svn_grass at osgeo.org
Fri Jan 21 06:09:13 EST 2011
Author: mmetz
Date: 2011-01-21 03:09:13 -0800 (Fri, 21 Jan 2011)
New Revision: 45130
Modified:
grass/branches/develbranch_6/imagery/i.rectify/exec.c
grass/branches/develbranch_6/imagery/i.rectify/global.h
grass/branches/develbranch_6/imagery/i.rectify/main.c
grass/branches/develbranch_6/imagery/i.rectify/rectify.c
grass/branches/develbranch_6/imagery/i.rectify/report.c
Log:
clean up report, check input answers, manually check for overwrite (backport from trunk r45129)
Modified: grass/branches/develbranch_6/imagery/i.rectify/exec.c
===================================================================
--- grass/branches/develbranch_6/imagery/i.rectify/exec.c 2011-01-21 10:42:54 UTC (rev 45129)
+++ grass/branches/develbranch_6/imagery/i.rectify/exec.c 2011-01-21 11:09:13 UTC (rev 45130)
@@ -22,18 +22,19 @@
char *name;
char *mapset;
char *result;
- char *type;
- int i, n;
+ char *type = "raster";
+ int n;
struct Colors colr;
struct Categories cats;
struct History hist;
int colr_ok, cats_ok;
- long start_time, rectify_time, compress_time;
+ long start_time, rectify_time;
+ G_message("-----------------------------------------------");
+
/* rectify each file */
for (n = 0; n < ref.nfiles; n++) {
- if ((i = ref_list[n]) < 0) {
- /* continue; */
+ if (ref_list[n]) {
name = ref.file[n].name;
mapset = ref.file[n].mapset;
@@ -42,8 +43,6 @@
G_malloc(strlen(ref.file[n].name) + strlen(extension) + 1);
strcpy(result, ref.file[n].name);
strcat(result, extension);
- G_message(_("Rectified input raster map <%s> will be saved as <%s>"),
- name, result);
select_current_env();
@@ -51,7 +50,6 @@
colr_ok = G_read_colors(name, mapset, &colr) > 0;
/* Initialze History */
- type = "raster";
G_short_history(name, type, &hist);
time(&start_time);
@@ -59,12 +57,6 @@
if (rectify(name, mapset, result, order, interp_method)) {
select_target_env();
- /***
- * This clobbers (with wrong values) head
- * written by gislib. 99% sure it should
- * be removed. EGM 2002/01/03
- G_put_cellhd (result,&target_window);
- */
if (cats_ok) {
G_write_cats(result, &cats);
G_free_cats(&cats);
@@ -84,18 +76,14 @@
select_current_env();
time(&rectify_time);
- compress_time = rectify_time;
- report(name, mapset, result, rectify_time - start_time,
- compress_time - rectify_time, 1);
+ report(rectify_time - start_time, 1);
}
else
- report(name, mapset, result, (long)0, (long)0, 0);
+ report((long)0, 0);
G_free(result);
}
}
- G_done_msg(" ");
-
return 0;
}
Modified: grass/branches/develbranch_6/imagery/i.rectify/global.h
===================================================================
--- grass/branches/develbranch_6/imagery/i.rectify/global.h 2011-01-21 10:42:54 UTC (rev 45129)
+++ grass/branches/develbranch_6/imagery/i.rectify/global.h 2011-01-21 11:09:13 UTC (rev 45130)
@@ -84,7 +84,7 @@
#define CPTR(c,y,x) (&(*BLOCK((c),HI((y)),HI((x))))[LO((y))][LO((x))])
/* report.c */
-int report(char *, char *, char *, long, long, int);
+int report(long, int);
/* target.c */
int get_target(char *);
Modified: grass/branches/develbranch_6/imagery/i.rectify/main.c
===================================================================
--- grass/branches/develbranch_6/imagery/i.rectify/main.c 2011-01-21 10:42:54 UTC (rev 45129)
+++ grass/branches/develbranch_6/imagery/i.rectify/main.c 2011-01-21 11:09:13 UTC (rev 45130)
@@ -15,7 +15,7 @@
* PURPOSE: calculate a transformation matrix and then convert x,y cell
* coordinates to standard map coordinates for each pixel in the
* image (control points can come from i.points or i.vpoints)
- * COPYRIGHT: (C) 2002-2006 by the GRASS Development Team
+ * COPYRIGHT: (C) 2002-2011 by the GRASS Development Team
*
* This program is free software under the GNU General Public
* License (>=v2). Read the file COPYING that comes with GRASS
@@ -75,7 +75,8 @@
char *ipolname; /* name of interpolation method */
int method;
int n, i, m, k = 0;
- int got_file = 0;
+ int got_file = 0, target_overwrite = 0;
+ char *overstr;
struct Cell_head cellhd;
struct Option *grp, /* imagery group */
@@ -209,29 +210,43 @@
if (a->answer) {
for (n = 0; n < ref.nfiles; n++) {
- ref_list[n] = -1;
+ ref_list[n] = 1;
}
}
else {
- char xname[GNAME_MAX], xmapset[GMAPSET_MAX], *name;
+ char xname[GNAME_MAX], xmapset[GMAPSET_MAX], *name, *mapset;
for (n = 0; n < ref.nfiles; n++)
ref_list[n] = 0;
for (m = 0; m < k; m++) {
got_file = 0;
- if (G__name_is_fully_qualified(ifile->answers[m], xname, xmapset))
+ if (G__name_is_fully_qualified(ifile->answers[m], xname, xmapset)) {
name = xname;
- else
+ mapset = xmapset;
+ }
+ else {
name = ifile->answers[m];
+ mapset = 0;
+ }
got_file = 0;
for (n = 0; n < ref.nfiles; n++) {
- if (strcmp(name, ref.file[n].name) == 0) {
- got_file = 1;
- ref_list[n] = -1;
- break;
+ if (mapset) {
+ if (strcmp(name, ref.file[n].name) == 0 &&
+ strcmp(mapset, ref.file[n].mapset) == 0) {
+ got_file = 1;
+ ref_list[n] = 1;
+ break;
+ }
}
+ else {
+ if (strcmp(name, ref.file[n].name) == 0) {
+ got_file = 1;
+ ref_list[n] = 1;
+ break;
+ }
+ }
}
if (got_file == 0)
err_exit(ifile->answers[m], group);
@@ -244,6 +259,39 @@
/* get the target */
get_target(group);
+ /* Check the GRASS_OVERWRITE environment variable */
+ if ((overstr = getenv("GRASS_OVERWRITE"))) /* OK ? */
+ target_overwrite = atoi(overstr);
+
+ if (!target_overwrite) {
+ /* check if output exists in target location/mapset */
+ char result[GNAME_MAX];
+
+ select_target_env();
+ for (i = 0; i < ref.nfiles; i++) {
+ if (!ref_list[i])
+ continue;
+
+ strcpy(result, ref.file[i].name);
+ strcat(result, extension);
+
+ if (G_legal_filename(result) < 0)
+ G_fatal_error(_("Extension <%s> is illegal"), extension);
+
+ if (G_find_cell(result, G_mapset())) {
+ G_warning(_("The following raster map already exists in"));
+ G_warning(_("target LOCATION %s, MAPSET %s:"),
+ G_location(), G_mapset());
+ G_warning("<%s>", result);
+ G_fatal_error(_("Orthorectification cancelled."));
+ }
+ }
+
+ select_current_env();
+ }
+ else
+ G_debug(1, "Overwriting OK");
+
/* do not use current region in target location */
if (!c->answer) {
double res = -1;
@@ -273,6 +321,8 @@
exec_rectify(order, extension, interpol->answer);
+ G_done_msg(" ");
+
exit(EXIT_SUCCESS);
}
Modified: grass/branches/develbranch_6/imagery/i.rectify/rectify.c
===================================================================
--- grass/branches/develbranch_6/imagery/i.rectify/rectify.c 2011-01-21 10:42:54 UTC (rev 45129)
+++ grass/branches/develbranch_6/imagery/i.rectify/rectify.c 2011-01-21 11:09:13 UTC (rev 45130)
@@ -40,8 +40,12 @@
G_close_cell(infd); /* (pmx) 17 april 2000 */
+ G_message(_("Rectify <%s@%s> (location <%s>)"),
+ name, mapset, G_location());
select_target_env();
G_set_window(&target_window);
+ G_message(_("into <%s@%s> (location <%s>) ..."),
+ result, G_mapset(), G_location());
nrows = target_window.rows;
ncols = target_window.cols;
Modified: grass/branches/develbranch_6/imagery/i.rectify/report.c
===================================================================
--- grass/branches/develbranch_6/imagery/i.rectify/report.c 2011-01-21 10:42:54 UTC (rev 45129)
+++ grass/branches/develbranch_6/imagery/i.rectify/report.c 2011-01-21 11:09:13 UTC (rev 45130)
@@ -1,20 +1,13 @@
#include <grass/glocale.h>
#include "global.h"
-int report(char *name, char *mapset, char *result,
- long rectify, long compress, int ok)
+int report(long rectify, int ok)
{
int minutes, hours;
long seconds;
long ncells;
- select_current_env();
- G_message(_("Rectify <%s@%s> (location <%s>)"),
- name, mapset, G_location());
- select_target_env();
- G_message(_("into <%s@%s> (location <%s>) ... %s"),
- result, G_mapset(), G_location(), ok ? _("complete") : _("failed"));
- select_current_env();
+ G_message("%s", ok ? _("complete") : _("failed"));
if (!ok)
return 1;
@@ -27,30 +20,14 @@
G_verbose_message(_("%d rows, %d cols (%ld cells) completed in"),
target_window.rows, target_window.cols, ncells);
if (hours)
- G_verbose_message("%d:%02d:%02ld", hours, minutes, seconds % 60);
+ G_verbose_message(_("%d:%02d:%02ld hours"), hours, minutes, seconds % 60);
else
- G_verbose_message("%d:%02ld", minutes, seconds % 60);
+ G_verbose_message(_("%d:%02ld minutes"), minutes, seconds % 60);
if (seconds)
G_verbose_message(_("%.1f cells per minute"),
(60.0 * ncells) / ((double)seconds));
- seconds = compress;
-
- if (seconds <= 0) {
- G_message("-----------------------------------------------");
- return 1;
- }
-
- minutes = seconds / 60;
- hours = minutes / 60;
- minutes -= hours * 60;
- G_verbose_message(_("data compression required an additional"));
- if (hours)
- G_verbose_message("%d:%02d:%02ld", hours, minutes, seconds % 60);
- else
- G_verbose_message("%d:%02ld\n", minutes, seconds % 60);
-
G_message("-----------------------------------------------");
- return 0;
+ return 1;
}
More information about the grass-commit
mailing list