[GRASS-dev] Re: [GRASS-user] v.surf.rst limitations?

Hamish hamish_nospam at yahoo.com
Mon Dec 4 20:20:39 EST 2006


Hi Roberto,

here are some updates for v.surf.bspline vs. today's CVS.

The most important is not calling G_write_history() until after
the raster map is closed with G_close_cell().

Also:
* added opt->guisection for some options to make the GUI less
cluttered. (feel free to come up with a better name for the tab)

* added G_command_history() to save the command line into the history
file so you can later know what the input map and settings were, and
G_put_cell_title() to set the output map title. (see r.resamp.interp)
I think it is good policy that all modules which create a new raster map
should use those.


Hamish
-------------- next part --------------
? OBJ.i686-pc-linux-gnu
? vsb_5dec.diff
Index: main.c
===================================================================
RCS file: /home/grass/grassrepository/grass6/vector/lidar/v.bspline/main.c,v
retrieving revision 1.5
diff -u -r1.5 main.c
--- main.c	4 Sep 2006 23:58:47 -0000	1.5
+++ main.c	5 Dec 2006 01:16:40 -0000
@@ -38,7 +38,7 @@
     int last_row, last_column, grid, bilin, flag_ext, flag_auxiliar; 	/* booleans */
     double passoN, passoE, lambda, mean;		
     
-    char *mapset, *dvr, *db, *vector, *map, table_name[1024];			/* */
+    char *mapset, *dvr, *db, *vector, *map, table_name[1024], title[64];
     
     int *lineVect;				/* Vector restoring primitive's ID*/
     double **raster_matrix;			/* Matrix to store the auxiliar raster values*/
@@ -49,10 +49,10 @@
     struct Map_info In, In_ext, Out;
     
     struct GModule *module;
-    struct Option *in_opt, *in_ext_opt, *out_opt, *out_map_opt, *dbdriver, *dbdatabase, \
-    			*passoE_opt, *passoN_opt, *lambda_f_opt, *type; 
+    struct Option *in_opt, *in_ext_opt, *out_opt, *out_map_opt, *dbdriver,
+		*dbdatabase, *passoE_opt, *passoN_opt, *lambda_f_opt, *type;
     struct History history;
-    
+
     struct Cell_head elaboration_reg, original_reg;
     struct Reg_dimens dims;
     BOUND_BOX general_box, overlap_box;
@@ -67,16 +67,11 @@
 /* Options' declaration */
     module = G_define_module();
     module->keywords = _("vector, interpolation");
-    module->description = _("Bicubic or bilineal interpolation with Tykhonov regularization");
+    module->description =
+	_("Bicubic or bilineal interpolation with Tykhonov regularization");
+
+    in_opt = G_define_standard_option(G_OPT_V_INPUT);
 
-    in_opt = G_define_option () ;
-    	in_opt->key 		= "input";
-    	in_opt->type 		= TYPE_STRING;
-    	in_opt->key_desc    	= "name";
-	in_opt->required    	= YES;
-	in_opt->gisprompt    	= "old,vector,vector";
-	in_opt->description  	= _("Name of input vector map");
-	
     in_ext_opt = G_define_option () ;
     	in_ext_opt->key 	= "input_ext";
 	in_ext_opt->type 	= TYPE_STRING;
@@ -85,22 +80,13 @@
 	in_ext_opt->gisprompt   = "old,vector,vector";
 	in_ext_opt->description = _("Name of input vector map of sparse points");
 	
-    out_opt = G_define_option () ;
-    	out_opt->key 		= "output";
-    	out_opt->type 		= TYPE_STRING;
-    	out_opt->key_desc       = "name";
+    out_opt = G_define_standard_option(G_OPT_V_OUTPUT);
 	out_opt->required       = NO;
-	out_opt->gisprompt      = "new,vector,vector";
-	out_opt->description    = _("Name of output vector map");
-	
-    out_map_opt = G_define_option () ;
+
+    out_map_opt = G_define_standard_option(G_OPT_R_OUTPUT);
     	out_map_opt->key 	  = "raster_out";
-    	out_map_opt->type 	  = TYPE_STRING;
-    	out_map_opt->key_desc     = "name";
-	out_map_opt->gisprompt 	  = "new,cell,raster";
 	out_map_opt->required 	  = NO;
-	out_map_opt->description  = _("Name of output raster map");
-    
+
     dbdatabase = G_define_option() ;
     	dbdatabase->key        	= "database" ;
     	dbdatabase->type       	= TYPE_STRING ;
@@ -109,7 +95,7 @@
     	dbdatabase->description	= _("Database name");
     if ( (db=G__getenv2("DB_DATABASE",G_VAR_MAPSET)) )
 	    dbdatabase->answer = G_store ( db );
-    	
+
     dbdriver = G_define_option() ;
    	dbdriver->key         = "driver" ;
     	dbdriver->type        = TYPE_STRING ;
@@ -119,20 +105,24 @@
     	dbdriver->description = _("Driver name");
     if ( (dvr = G__getenv2("DB_DRIVER",G_VAR_MAPSET)) )
 	    dbdriver->answer = G_store ( dvr );
-    
+
     passoE_opt = G_define_option();
         passoE_opt->key		= "sie";
 	passoE_opt->type	= TYPE_DOUBLE;
         passoE_opt->required	= NO;
 	passoE_opt->answer 	= "4";
-	passoE_opt->description	= _("Interpolation spline step value in east direction");
-	
+	passoE_opt->guisection	= "Settings";
+	passoE_opt->description	=
+	  _("Interpolation spline step value in east direction");
+
     passoN_opt = G_define_option();
         passoN_opt->key		= "sin";	
         passoN_opt->type	= TYPE_DOUBLE;
         passoN_opt->required	= NO;
         passoN_opt->answer 	= "4";
-	passoN_opt->description	= _("Interpolation spline step value in north direction");		
+	passoN_opt->guisection	= "Settings";
+	passoN_opt->description	=
+	  _("Interpolation spline step value in north direction");		
 
     type = G_define_option();
 	type->key	  = "type";	
@@ -141,13 +131,15 @@
         type->description = _("Spline type of interpolation");	
 	type->options	  = "bilinear,bicubic";
 	type->answer	  = "bilinear";
-	
+	type->guisection  = "Settings";
+
     lambda_f_opt = G_define_option();
 	lambda_f_opt->key    	  = "lambda_i";
 	lambda_f_opt->type	  = TYPE_DOUBLE;
 	lambda_f_opt->required	  = NO;
         lambda_f_opt->description =_("Thychonov regularization weigth");
 	lambda_f_opt->answer	  = "1";
+	lambda_f_opt->guisection  = "Settings";
 
 /* Parsing */	
     G_gisinit(argv[0]);
@@ -190,7 +182,7 @@
     } else {
 	flag_ext = TRUE;
     	G_warning (_("<%s> vector map will be interpolated"), in_ext_opt->answer);
-	
+
     	if ((mapset = G_find_vector2 (in_ext_opt->answer, "")) == NULL) 
 	    G_fatal_error ( _("Could not find input map <%s>"), in_ext_opt->answer);
 
@@ -234,9 +226,6 @@
 
 	if ((raster = G_open_fp_cell_new (out_map_opt->answer)) < 0) 
 	    G_fatal_error (_("Raster <%s> could not be open."), out_map_opt->answer);
-	
-	G_short_history (out_map_opt->answer, "raster", &history);
-	G_write_history (out_map_opt->answer, &history);
     }
 
     driver = db_start_driver_open_database (dbdriver->answer, dbdatabase->answer);
@@ -457,8 +446,19 @@
     Vect_close (&In);
     if (flag_ext != FALSE) Vect_close (&In_ext);
     if (vector) Vect_close (&Out);
-    
-    if (map) G_close_cell (raster);
+
+    if (map) {
+	G_close_cell(raster);
+
+	/* set map title */
+	sprintf(title, "%s interpolation with Tykhonov regularization",
+	    type->answer);
+	G_put_cell_title(out_map_opt->answer, title);
+	/* write map history */
+	G_short_history(out_map_opt->answer, "raster", &history);
+	G_command_history(&history);
+	G_write_history(out_map_opt->answer, &history);
+    }
 
     G_done_msg("");
     exit(EXIT_SUCCESS);


More information about the grass-dev mailing list