Kaynağa Gözat

v.to.3d: use G_progress()
message cosmetics
assume layer=1 when column is given
use standard error handlers


git-svn-id: https://svn.osgeo.org/grass/grass/trunk@56203 15284696-431f-4ddb-bdfa-cd5b030d7da7

Martin Landa 12 yıl önce
ebeveyn
işleme
2500ada66c
3 değiştirilmiş dosya ile 21 ekleme ve 21 silme
  1. 1 6
      vector/v.to.3d/main.c
  2. 11 9
      vector/v.to.3d/trans2.c
  3. 9 6
      vector/v.to.3d/trans3.c

+ 1 - 6
vector/v.to.3d/main.c

@@ -71,14 +71,13 @@ int main(int argc, char **argv)
     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 @@ int main(int argc, char **argv)
 	}
     }
 
-    G_message(_("Transforming features..."));
     ret = 0;
     if (opt.reverse->answer) {
 	/* 3d -> 2d */
@@ -118,9 +116,6 @@ int main(int argc, char **argv)
     }
 
     if (ret < 0) {
-	Vect_close(&In);
-	Vect_close(&Out);
-	Vect_delete(opt.output->answer);
 	G_fatal_error(_("%s failed"), G_program_name());
     }
 

+ 11 - 9
vector/v.to.3d/trans2.c

@@ -42,6 +42,11 @@ int trans2d(struct Map_info *In, struct Map_info *Out, int type,
 
 	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 @@ int trans2d(struct Map_info *In, struct Map_info *Out, int type,
 	    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 @@ int trans2d(struct Map_info *In, struct Map_info *Out, int type,
 	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 @@ int trans2d(struct Map_info *In, struct Map_info *Out, int type,
 	    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 @@ int trans2d(struct Map_info *In, struct Map_info *Out, int type,
 
 	line++;
     }
-
-    if (G_verbose() > G_verbose_min())
-	fprintf(stderr, "\r");
-
-
+    G_progress(1, 1);
+    
     Vect_destroy_line_struct(Points);
     Vect_destroy_cats_struct(Cats);
 

+ 9 - 6
vector/v.to.3d/trans3.c

@@ -44,6 +44,11 @@ int trans3d(struct Map_info *In, struct Map_info *Out, int type,
     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 @@ int trans3d(struct Map_info *In, struct Map_info *Out, int type,
 	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 @@ int trans3d(struct Map_info *In, struct Map_info *Out, int type,
 	    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,9 +142,7 @@ int trans3d(struct Map_info *In, struct Map_info *Out, int type,
 	Vect_write_line(Out, ltype, Points, Cats);
 	line++;
     }
-
-    if (G_verbose() > G_verbose_min())
-	fprintf(stderr, "\r");
+    G_progress(1, 1);
 
     if (zcolumn) {
 	db_commit_transaction(driver);