[GRASS-SVN] r52160 - grass/trunk/raster/r.in.xyz

svn_grass at osgeo.org svn_grass at osgeo.org
Wed Jun 20 03:03:25 PDT 2012


Author: hamish
Date: 2012-06-20 03:03:24 -0700 (Wed, 20 Jun 2012)
New Revision: 52160

Modified:
   grass/trunk/raster/r.in.xyz/local_proto.h
   grass/trunk/raster/r.in.xyz/main.c
   grass/trunk/raster/r.in.xyz/r.in.xyz.html
Log:
add support for reading from alternate value column while filtering on z

Modified: grass/trunk/raster/r.in.xyz/local_proto.h
===================================================================
--- grass/trunk/raster/r.in.xyz/local_proto.h	2012-06-20 09:33:07 UTC (rev 52159)
+++ grass/trunk/raster/r.in.xyz/local_proto.h	2012-06-20 10:03:24 UTC (rev 52160)
@@ -38,7 +38,7 @@
 #define METHOD_TRIMMEAN   13
 
 /* main.c */
-int scan_bounds(FILE *, int, int, int, char *, int, int, double);
+int scan_bounds(FILE *, int, int, int, int, char *, int, int, double, double);
 
 /* support.c */
 int blank_array(void *, int, int, RASTER_MAP_TYPE, int);

Modified: grass/trunk/raster/r.in.xyz/main.c
===================================================================
--- grass/trunk/raster/r.in.xyz/main.c	2012-06-20 09:33:07 UTC (rev 52159)
+++ grass/trunk/raster/r.in.xyz/main.c	2012-06-20 10:03:24 UTC (rev 52160)
@@ -3,7 +3,7 @@
  *
  *  Calculates univariate statistics from the non-null cells of a GRASS raster map
  *
- *   Copyright 2006 by M. Hamish Bowman, and The GRASS Development Team
+ *   Copyright 2006-2012 by M. Hamish Bowman, and The GRASS Development Team
  *   Author: M. Hamish Bowman, University of Otago, Dunedin, New Zealand
  *
  *   Extended 2007 by Volker Wichmann to support the aggregate functions
@@ -98,11 +98,11 @@
     FILE *in_fp;
     int out_fd;
     char *infile, *outmap;
-    int xcol, ycol, zcol, max_col, percent;
-    int do_zfilter;
+    int xcol, ycol, zcol, vcol, max_col, percent;
+    int do_zfilter, do_vfilter;
     int method = -1;
     int bin_n, bin_min, bin_max, bin_sum, bin_sumsq, bin_index;
-    double zrange_min, zrange_max, d_tmp;
+    double zrange_min, zrange_max, vrange_min, vrange_max, d_tmp;
     char *fs;			/* field delim */
     off_t filesize;
     int linesize;
@@ -133,6 +133,7 @@
     double min = 0.0 / 0.0;	/* init as nan */
     double max = 0.0 / 0.0;	/* init as nan */
     double zscale = 1.0;
+    double vscale = 1.0;
     size_t offset, n_offset;
     int n = 0;
     double sum = 0.;
@@ -149,7 +150,7 @@
     struct Option *input_opt, *output_opt, *delim_opt, *percent_opt,
 	*type_opt;
     struct Option *method_opt, *xcol_opt, *ycol_opt, *zcol_opt, *zrange_opt,
-	*zscale_opt;
+	*zscale_opt, *vcol_opt, *vrange_opt, *vscale_opt;
     struct Option *trim_opt, *pth_opt;
     struct Flag *scan_flag, *shell_style, *skipline;
 
@@ -212,7 +213,10 @@
     zcol_opt->type = TYPE_INTEGER;
     zcol_opt->required = NO;
     zcol_opt->answer = "3";
-    zcol_opt->description = _("Column number of data values in input file");
+    zcol_opt->label = _("Column number of data values in input file");
+    zcol_opt->description =
+	_("If a separate value column is given, this option refers to the "
+	  "z-coordinate column to be filtered by the zrange option");
     zcol_opt->guisection = _("Input");
 
     zrange_opt = G_define_option();
@@ -229,6 +233,31 @@
     zscale_opt->answer = "1.0";
     zscale_opt->description = _("Scale to apply to z data");
 
+    vcol_opt = G_define_option();
+    vcol_opt->key = "value_column";
+    vcol_opt->type = TYPE_INTEGER;
+    vcol_opt->required = NO;
+    vcol_opt->answer = "0";
+    vcol_opt->label = _("Alternate column number of data values in input file");
+    vcol_opt->description = _("If not given (or set to 0) the z-column data is used");
+    vcol_opt->guisection = _("Advanced Input");
+
+    vrange_opt = G_define_option();
+    vrange_opt->key = "vrange";
+    vrange_opt->type = TYPE_DOUBLE;
+    vrange_opt->required = NO;
+    vrange_opt->key_desc = "min,max";
+    vrange_opt->description = _("Filter range for alternate value column data (min,max)");
+    vrange_opt->guisection = _("Advanced Input");
+
+    vscale_opt = G_define_option();
+    vscale_opt->key = "vscale";
+    vscale_opt->type = TYPE_DOUBLE;
+    vscale_opt->required = NO;
+    vscale_opt->answer = "1.0";
+    vscale_opt->description = _("Scale to apply to alternate value column data");
+    vscale_opt->guisection = _("Advanced Input");
+
     percent_opt = G_define_option();
     percent_opt->key = "percent";
     percent_opt->type = TYPE_INTEGER;
@@ -292,15 +321,19 @@
     xcol = atoi(xcol_opt->answer);
     ycol = atoi(ycol_opt->answer);
     zcol = atoi(zcol_opt->answer);
-    if ((xcol < 0) || (ycol < 0) || (zcol < 0))
+    vcol = atoi(vcol_opt->answer);
+    if ((xcol < 0) || (ycol < 0) || (zcol < 0) || (vcol < 0))
 	G_fatal_error(_("Please specify a reasonable column number."));
     max_col = (xcol > ycol) ? xcol : ycol;
     max_col = (zcol > max_col) ? zcol : max_col;
+    if(vcol)
+	max_col = (vcol > max_col) ? vcol : max_col;
 
     percent = atoi(percent_opt->answer);
     zscale = atof(zscale_opt->answer);
+    vscale = atof(vscale_opt->answer);
 
-    /* parse zrange */
+    /* parse zrange and vrange */
     do_zfilter = FALSE;
     if (zrange_opt->answer != NULL) {
 	if (zrange_opt->answers[0] == NULL)
@@ -317,6 +350,22 @@
 	}
     }
 
+    do_vfilter = FALSE;
+    if (vrange_opt->answer != NULL) {
+	if (vrange_opt->answers[0] == NULL)
+	    G_fatal_error(_("Invalid vrange"));
+
+	sscanf(vrange_opt->answers[0], "%lf", &vrange_min);
+	sscanf(vrange_opt->answers[1], "%lf", &vrange_max);
+	do_vfilter = TRUE;
+
+	if (vrange_min > vrange_max) {
+	    d_tmp = vrange_max;
+	    vrange_max = vrange_min;
+	    vrange_min = d_tmp;
+	}
+    }
+
     /* figure out what maps we need in memory */
     /*  n               n
        min              min
@@ -484,11 +533,11 @@
     }
 
     if (scan_flag->answer) {
-	if (zrange_opt->answer)
-	    G_warning(_("zrange will not be taken into account during scan"));
+	if (zrange_opt->answer || vrange_opt->answer)
+	    G_warning(_("range filters will not be taken into account during scan"));
 
-	scan_bounds(in_fp, xcol, ycol, zcol, fs, shell_style->answer,
-		    skipline->answer, zscale);
+	scan_bounds(in_fp, xcol, ycol, zcol, vcol, fs, shell_style->answer,
+		    skipline->answer, zscale, vscale);
 
 	if (!from_stdin)
 	    fclose(in_fp);
@@ -638,7 +687,6 @@
 	    if (1 != sscanf(tokens[zcol - 1], "%lf", &z))
 		G_fatal_error(_("Bad z-coordinate line %lu column %d. <%s>"),
 			      line, zcol, tokens[zcol - 1]);
-
 	    z = z * zscale;
 
 	    if (zrange_opt->answer) {
@@ -648,8 +696,23 @@
 		}
 	    }
 
+	    if(vcol) {
+		if (1 != sscanf(tokens[vcol - 1], "%lf", &z))
+		    G_fatal_error(_("Bad data value line %lu column %d. <%s>"),
+				    line, vcol, tokens[vcol - 1]);
+		/* we're past the zrange check, so pass over control of the variable */
+		z = z * vscale;
+
+		if (vrange_opt->answer) {
+		    if (z < vrange_min || z > vrange_max) {
+		    	G_free_tokens(tokens);
+		    	continue;
+		    }
+		}
+	    }
+
 	    count++;
-	    /*          G_debug(5, "x: %f, y: %f, z: %f", x, y, z); */
+	    /* G_debug(5, "x: %f, y: %f, z: %f", x, y, z); */
 	    G_free_tokens(tokens);
 
 	    /* find the bin in the current array box */
@@ -1066,19 +1129,21 @@
 
 
 
-int scan_bounds(FILE * fp, int xcol, int ycol, int zcol, char *fs,
-		int shell_style, int skipline, double zscale)
+int scan_bounds(FILE * fp, int xcol, int ycol, int zcol, int vcol, char *fs,
+		int shell_style, int skipline, double zscale, double vscale)
 {
     unsigned long line;
     int first, max_col;
     char buff[BUFFSIZE];
-    double min_x, max_x, min_y, max_y, min_z, max_z;
+    double min_x, max_x, min_y, max_y, min_z, max_z, min_v, max_v;
     char **tokens;
     int ntokens;		/* number of tokens */
-    double x, y, z;
+    double x, y, z, v;
 
     max_col = (xcol > ycol) ? xcol : ycol;
     max_col = (zcol > max_col) ? zcol : max_col;
+    if(vcol)
+	max_col = (vcol > max_col) ? vcol : max_col;
 
     line = 0;
     first = TRUE;
@@ -1157,7 +1222,8 @@
 	if (first) {
 	    min_z = z;
 	    max_z = z;
-	    first = FALSE;
+	    if(!vcol)
+		first = FALSE;
 	}
 	else {
 	    if (z < min_z)
@@ -1166,22 +1232,47 @@
 		max_z = z;
 	}
 
+	if(vcol) {
+	    if (1 != sscanf(tokens[vcol - 1], "%lf", &v))
+	    	G_fatal_error(_("Bad data value line %lu column %d. <%s>"), line,
+	    		      vcol, tokens[vcol - 1]);
 
+	    if (first) {
+	    	min_v = v;
+	    	max_v = v;
+		first = FALSE;
+	    }
+	    else {
+	    	if (v < min_v)
+	    	    min_v = v;
+	    	if (v > max_v)
+	    	    max_v = v;
+	    }
+	}
+
 	G_free_tokens(tokens);
     }
 
     if (!shell_style) {
 	fprintf(stderr, _("Range:     min         max\n"));
-	fprintf(stdout, "x: %11f %11f\n", min_x, max_x);
-	fprintf(stdout, "y: %11f %11f\n", min_y, max_y);
-	fprintf(stdout, "z: %11f %11f\n", min_z * zscale, max_z * zscale);
+	fprintf(stdout, "x: %11.15g %11.15g\n", min_x, max_x);
+	fprintf(stdout, "y: %11.15g %11.15g\n", min_y, max_y);
+	fprintf(stdout, "z: %11.15g %11.15g\n", min_z * zscale, max_z * zscale);
+	if(vcol)
+	    fprintf(stdout, "v: %11.15g %11.15g\n", min_v * vscale, max_v * vscale);
     }
-    else
-	fprintf(stdout, "n=%f s=%f e=%f w=%f b=%f t=%f\n",
+    else {
+	fprintf(stdout, "n=%.15g s=%.15g e=%.15g w=%.15g b=%.15g t=%.15g",
 		max_y, min_y, max_x, min_x, min_z * zscale, max_z * zscale);
+	if(vcol)
+	    fprintf(stdout, " min=%.15g max=%.15g\n", min_v * vscale,
+		    max_v * vscale);
+	else
+	    fprintf(stdout, "\n");
+    }
 
     G_debug(1, "Processed %lu lines.", line);
-    G_debug(1, "region template: g.region n=%f s=%f e=%f w=%f",
+    G_debug(1, "region template: g.region n=%.15g s=%.15g e=%.15g w=%.15g",
 	    max_y, min_y, max_x, min_x);
 
     return 0;

Modified: grass/trunk/raster/r.in.xyz/r.in.xyz.html
===================================================================
--- grass/trunk/raster/r.in.xyz/r.in.xyz.html	2012-06-20 09:33:07 UTC (rev 52159)
+++ grass/trunk/raster/r.in.xyz/r.in.xyz.html	2012-06-20 10:03:24 UTC (rev 52160)
@@ -9,10 +9,10 @@
 for example raw LIDAR or sidescan sonar swath data. It has been tested with
 datasets as large as tens of billion of points (705GB in a single file).
  <!-- Doug Newcomb, US Fish & Wildlife Service -->
+
 <p>
 Available statistics for populating the raster are:<br>
-<ul>
-<li>
+<blockquote>
 <table>
 <tr><td><em>n</em></td>        <td>number of points in cell</td></tr>
 <tr><td><em>min</em></td>      <td>minimum value of points in cell</td></tr>
@@ -29,13 +29,21 @@
 <tr><td><em>skewness</em></td> <td>skewness of points in cell</td></tr>
 <tr><td><em>trimmean</em></td> <td>trimmed mean of points in cell</td></tr>
 </table><br>
+</blockquote>
 
+<ul>
 <li><em>Variance</em> and derivatives use the biased estimator (n). [subject to change]
 <li><em>Coefficient of variance</em> is given in percentage and defined as
 <tt>(stddev/mean)*100</tt>.
 </ul>
 <br>
 
+<p>
+It is also possible to bin and store another data column (e.g. backscatter)
+while simultaneously filtering and scaling both the data column values and
+the z range.
+
+
 <h2>NOTES</h2>
 
 <h3>Gridded data</h3>
@@ -82,6 +90,7 @@
 If reading data from a <tt>stdin</tt> stream, the program can only run using
 a single pass.
 
+
 <h3>Setting region bounds and resolution</h3>
 
 You can use the <b>-s</b> scan flag to find the extent of the input data
@@ -140,6 +149,18 @@
 <em>r.neighbors</em> to smooth the stddev map before further use.]
 
 
+<h3>Alternate value column</h3>
+
+The <b>value_column</b> parameter can be used in specialized cases when you
+want to filter by z-range but bin and store another column's data. For
+example if you wanted to look at backscatter values between 1000 and 1500
+meters elevation. This is particularly useful when using <em>r.in.xyz</em>
+to prepare depth slices for a 3D raster — the <b>zrange</b> option defines
+the depth slice but the data values stored in the voxels describe an
+additional dimension. As with the z column, a filtering range and scaling
+factor may be applied.
+
+
 <h3>Reprojection</h3>
 
 If the raster map is to be reprojected, it may be more appropriate to reproject
@@ -166,6 +187,7 @@
 </pre></div>
 <br>
 
+
 <h2>EXAMPLE</h2>
 
 Import the <a href="http://www.grassbook.org/data_menu2nd.phtml">Jockey's
@@ -203,12 +225,16 @@
 
 <ul>
 <li> Support for multiple map output from a single run.<br>
-     <tt>method=string[,string,...] output=name[,name,...]</tt>
+     <tt>method=string[,string,...] output=name[,name,...]</tt><br>
+     This can be easily handled by a wrapper script, with the added
+     benefit of it being very simple to parallelize that way.
 <li> Add two new flags for support for direct binary input from libLAS
      for LIDAR data and MB-System's mbio for multi-beam bathymetry data.
      <!-- Bob Covill has supplied patches for MBIO interface already -->
+     <br><i>note</i>: See the new <em>r.in.lidar</em> module for this.
 </ul>
 
+
 <h2>BUGS</h2>
 
 <ul>
@@ -229,6 +255,7 @@
 If you encounter any problems (or solutions!) please contact the GRASS
 Development Team.
 
+
 <h2>SEE ALSO</h2>
 
 <i>
@@ -236,6 +263,8 @@
 <a href="m.proj.html">m.proj</a><br>
 <a href="r.fillnulls.html">r.fillnulls</a><br>
 <a href="r.in.ascii.html">r.in.ascii</a><br>
+<a href="r.in.lidar.html">r.in.lidar</a><br>
+<a href="r3.in.xyz.html">r3.in.xyz</a><br>
 <a href="r.mapcalc.html">r.mapcalc</a><br>
 <a href="r.neighbors.html">r.neighbors</a><br>
 <a href="r.out.xyz.html">r.out.xyz</a><br>



More information about the grass-commit mailing list