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

svn_grass at osgeo.org svn_grass at osgeo.org
Sat May 11 09:50:19 PDT 2013


Author: martinl
Date: 2013-05-11 09:50:19 -0700 (Sat, 11 May 2013)
New Revision: 56203

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: use G_progress()
         message cosmetics
         assume layer=1 when column is given
         use standard error handlers


Modified: grass/trunk/vector/v.to.3d/main.c
===================================================================
--- grass/trunk/vector/v.to.3d/main.c	2013-05-11 15:12:39 UTC (rev 56202)
+++ grass/trunk/vector/v.to.3d/main.c	2013-05-11 16:50:19 UTC (rev 56203)
@@ -71,14 +71,13 @@
     Vect_set_open_level(1);
     if (Vect_open_old2(&In, opt.input->answer, "", opt.field->answer) < 1)
 	G_fatal_error(_("Unable to open vector map <%s>"), opt.input->answer);
+    Vect_set_error_handler_io(&In, &Out);
     
     if (opt.reverse->answer && !Vect_is_3d(&In)) {
-	Vect_close(&In);
 	G_fatal_error(_("Vector map <%s> is 2D"), opt.input->answer);
     }
 
     if (!opt.reverse->answer && Vect_is_3d(&In)) {
-	Vect_close(&In);
 	G_fatal_error(_("Vector map <%s> is 3D"), opt.input->answer);
     }
 
@@ -101,7 +100,6 @@
 	}
     }
 
-    G_message(_("Transforming features..."));
     ret = 0;
     if (opt.reverse->answer) {
 	/* 3d -> 2d */
@@ -118,9 +116,6 @@
     }
 
     if (ret < 0) {
-	Vect_close(&In);
-	Vect_close(&Out);
-	Vect_delete(opt.output->answer);
 	G_fatal_error(_("%s failed"), G_program_name());
     }
 

Modified: grass/trunk/vector/v.to.3d/trans2.c
===================================================================
--- grass/trunk/vector/v.to.3d/trans2.c	2013-05-11 15:12:39 UTC (rev 56202)
+++ grass/trunk/vector/v.to.3d/trans2.c	2013-05-11 16:50:19 UTC (rev 56203)
@@ -42,6 +42,11 @@
 
 	dbDriver *driver;
 
+        if (field == -1) {
+            G_warning(_("Invalid layer number %d, assuming 1"), field);
+            field = 1;
+        }
+
 	Fi = Vect_get_field(In, field);
 	if (!Fi) {
 	    G_warning(_("Database connection not defined for layer <%s>"),
@@ -68,6 +73,7 @@
 	    return -1;
 	}
 
+        G_message(_("Fetching height from <%s> column..."), column);
 	db_select_CatValArray(driver, Fi->table, Fi->key,
 			      column, NULL, &cvarr);
 
@@ -76,6 +82,7 @@
 	db_close_database_shutdown_driver(driver);
     }
 
+    G_message(_("Transforming features..."));
     line = 1;
     while (1) {
 	ltype = Vect_read_next_line(In, Points, Cats);
@@ -87,10 +94,8 @@
 	    break;
 	}
 
-	if (G_verbose() > G_verbose_min() && (line - 1) % 1000 == 0) {
-	    fprintf(stderr, "%7d\b\b\b\b\b\b\b", (line - 1));
-	}
-
+        G_progress(line, 1000);
+        
 	if (!(ltype & type))
 	    continue;
 
@@ -127,11 +132,8 @@
 
 	line++;
     }
-
-    if (G_verbose() > G_verbose_min())
-	fprintf(stderr, "\r");
-
-
+    G_progress(1, 1);
+    
     Vect_destroy_line_struct(Points);
     Vect_destroy_cats_struct(Cats);
 

Modified: grass/trunk/vector/v.to.3d/trans3.c
===================================================================
--- grass/trunk/vector/v.to.3d/trans3.c	2013-05-11 15:12:39 UTC (rev 56202)
+++ grass/trunk/vector/v.to.3d/trans3.c	2013-05-11 16:50:19 UTC (rev 56203)
@@ -44,6 +44,11 @@
     field = Vect_get_field_number(In, field_name);
 
     if (zcolumn) {
+        if (field == -1) {
+            G_warning(_("Invalid layer number %d, assuming 1"), field);
+            field = 1;
+        }
+
 	Fi = Vect_get_field(Out, field);
 	if (!Fi) {
 	    G_warning(_("Database connection not defined for layer <%s>"),
@@ -73,10 +78,12 @@
 	db_begin_transaction(driver);
 
 	/* select existing categories (layer) to array (array is sorted) */
+        G_message(_("Reading categories..."));
 	ncats = db_select_int(driver, Fi->table, Fi->key, NULL, &cats);
 	G_debug(3, "Existing categories: %d", ncats);
     }
 
+    G_message(_("Transforming features..."));
     line = 1;
     while (1) {
 	ltype = Vect_read_next_line(In, Points, Cats);
@@ -88,9 +95,7 @@
 	    break;
 	}
 
-	if (G_verbose() > G_verbose_min() && (line - 1) % 1000 == 0) {
-	    fprintf(stderr, "%7d\b\b\b\b\b\b\b", (line - 1));
-	}
+        G_progress(line, 1000);
 
 	if (!(ltype & type))
 	    continue;
@@ -137,10 +142,8 @@
 	Vect_write_line(Out, ltype, Points, Cats);
 	line++;
     }
+    G_progress(1, 1);
 
-    if (G_verbose() > G_verbose_min())
-	fprintf(stderr, "\r");
-
     if (zcolumn) {
 	db_commit_transaction(driver);
 



More information about the grass-commit mailing list