[GRASS-SVN] r38297 - grass/trunk/vector/v.to.3d

svn_grass at osgeo.org svn_grass at osgeo.org
Tue Jul 7 15:37:00 EDT 2009


Author: martinl
Date: 2009-07-07 15:36:59 -0400 (Tue, 07 Jul 2009)
New Revision: 38297

Modified:
   grass/trunk/vector/v.to.3d/main.c
   grass/trunk/vector/v.to.3d/trans2.c
   grass/trunk/vector/v.to.3d/trans3.c
Log:
v.to.3d: cleanup if fails, see trac #550


Modified: grass/trunk/vector/v.to.3d/main.c
===================================================================
--- grass/trunk/vector/v.to.3d/main.c	2009-07-07 14:53:30 UTC (rev 38296)
+++ grass/trunk/vector/v.to.3d/main.c	2009-07-07 19:36:59 UTC (rev 38297)
@@ -29,7 +29,8 @@
     struct Map_info In, Out;
     BOUND_BOX box;
     int field, type;
-
+    int ret;
+    
     G_gisinit(argv[0]);
 
     module = G_define_module();
@@ -102,9 +103,10 @@
     }
 
     G_message(_("Transforming features..."));
+    ret = 0;
     if (opt.reverse->answer) {
 	/* 3d -> 2d */
-	trans3d(&In, &Out, type, field, opt.column->answer);
+	ret = trans3d(&In, &Out, type, field, opt.column->answer);
     }
     else {
 	/* 2d -> 3d */
@@ -113,9 +115,16 @@
 	if (opt.height->answer) {
 	    height = atof(opt.height->answer);
 	}
-	trans2d(&In, &Out, type, height, field, opt.column->answer);
+	ret = trans2d(&In, &Out, type, height, field, opt.column->answer);
     }
 
+    if (ret < 0) {
+	Vect_close(&In);
+	Vect_close(&Out);
+	Vect_delete(opt.output->answer);
+	G_fatal_error(_("%s failed"), G_program_name());
+    }
+
     if (!opt.reverse->answer && !opt.table->answer) {
 	G_message(_("Copying attributes..."));
 	if (Vect_copy_tables(&In, &Out, 0) == -1) {

Modified: grass/trunk/vector/v.to.3d/trans2.c
===================================================================
--- grass/trunk/vector/v.to.3d/trans2.c	2009-07-07 14:53:30 UTC (rev 38296)
+++ grass/trunk/vector/v.to.3d/trans2.c	2009-07-07 19:36:59 UTC (rev 38297)
@@ -16,6 +16,7 @@
    \param column attribute column used for height
 
    \return number of writen features
+   \return -1 on error
  */
 int trans2d(struct Map_info *In, struct Map_info *Out, int type,
 	    double height, int field, const char *column)
@@ -40,23 +41,29 @@
 	dbDriver *driver;
 
 	Fi = Vect_get_field(In, field);
-	if (!Fi)
-	    G_fatal_error(_("Database connection not defined for layer %d"),
-			  field);
+	if (!Fi) {
+	    G_warning(_("Database connection not defined for layer %d"),
+		      field);
+	    return -1;
+	}
 
 	driver = db_start_driver_open_database(Fi->driver, Fi->database);
 	if (!driver) {
-	    G_fatal_error(_("Unable to open database <%s> by driver <%s>"),
-			  Fi->database, Fi->driver);
+	    G_warning(_("Unable to open database <%s> by driver <%s>"),
+		      Fi->database, Fi->driver);
+	    return -1;
 	}
 
 	/* column type must numeric */
 	ctype = db_column_Ctype(driver, Fi->table, column);
-	if (ctype == -1)
-	    G_fatal_error(_("Column <%s> not found in table <%s>"),
-			  column, Fi->table);
+	if (ctype == -1) {
+	    G_warning(_("Column <%s> not found in table <%s>"),
+		      column, Fi->table);
+	    return -1;
+	}
 	if (ctype != DB_C_TYPE_INT && ctype != DB_C_TYPE_DOUBLE) {
-	    G_fatal_error(_("Column must be numeric"));
+	    G_warning(_("Column must be numeric"));
+	    return -1;
 	}
 
 	db_select_CatValArray(driver, Fi->table, Fi->key,
@@ -71,7 +78,8 @@
     while (1) {
 	ltype = Vect_read_next_line(In, Points, Cats);
 	if (ltype == -1) {
-	    G_fatal_error(_("Unable to read vector map"));
+	    G_warning(_("Unable to read vector map"));
+	    return -1;
 	}
 	if (ltype == -2) {	/* EOF */
 	    break;

Modified: grass/trunk/vector/v.to.3d/trans3.c
===================================================================
--- grass/trunk/vector/v.to.3d/trans3.c	2009-07-07 14:53:30 UTC (rev 38296)
+++ grass/trunk/vector/v.to.3d/trans3.c	2009-07-07 19:36:59 UTC (rev 38297)
@@ -17,6 +17,7 @@
    \param zcolumn attribute column where to store height
 
    \return number of writen features
+   \return -1 on error
  */
 int trans3d(struct Map_info *In, struct Map_info *Out, int type,
 	    int field, const char *zcolumn)
@@ -41,23 +42,29 @@
 
     if (zcolumn) {
 	Fi = Vect_get_field(Out, field);
-	if (!Fi)
-	    G_fatal_error(_("Database connection not defined for layer %d"),
-			  field);
+	if (!Fi) {
+	    G_warning(_("Database connection not defined for layer %d"),
+		      field);
+	    return -1;
+	}
 
 	driver = db_start_driver_open_database(Fi->driver, Fi->database);
 	if (!driver) {
-	    G_fatal_error(_("Unable to open database <%s> by driver <%s>"),
-			  Fi->database, Fi->driver);
+	    G_warning(_("Unable to open database <%s> by driver <%s>"),
+		      Fi->database, Fi->driver);
+	    return -1;
 	}
 
 	/* column type must numeric */
 	ctype = db_column_Ctype(driver, Fi->table, zcolumn);
-	if (ctype == -1)
-	    G_fatal_error(_("Column <%s> not found in table <%s>"),
-			  zcolumn, Fi->table);
+	if (ctype == -1) {
+	    G_warning(_("Column <%s> not found in table <%s>"),
+		      zcolumn, Fi->table);
+	    return -1;
+	}
 	if (ctype != DB_C_TYPE_INT && ctype != DB_C_TYPE_DOUBLE) {
-	    G_fatal_error(_("Column must be numeric"));
+	    G_warning(_("Column must be numeric"));
+	    return -1;
 	}
 
 	db_begin_transaction(driver);
@@ -71,7 +78,8 @@
     while (1) {
 	ltype = Vect_read_next_line(In, Points, Cats);
 	if (ltype == -1) {
-	    G_fatal_error(_("Unable to read vector map"));
+	    G_warning(_("Unable to read vector map"));
+	    return -1;
 	}
 	if (ltype == -2) {	/* EOF */
 	    break;



More information about the grass-commit mailing list