[GRASS-SVN] r58552 - grass/trunk/raster/r.horizon

svn_grass at osgeo.org svn_grass at osgeo.org
Sun Dec 29 15:43:08 PST 2013


Author: neteler
Date: 2013-12-29 15:43:08 -0800 (Sun, 29 Dec 2013)
New Revision: 58552

Modified:
   grass/trunk/raster/r.horizon/main.c
   grass/trunk/raster/r.horizon/r.horizon.html
Log:
r.horizon: added output parameter (CSV file) for single point mode

Modified: grass/trunk/raster/r.horizon/main.c
===================================================================
--- grass/trunk/raster/r.horizon/main.c	2013-12-29 23:18:13 UTC (rev 58551)
+++ grass/trunk/raster/r.horizon/main.c	2013-12-29 23:43:08 UTC (rev 58552)
@@ -56,7 +56,7 @@
 #define DISTANCE1(x1, x2, y1, y2) (sqrt((x1 - x2)*(x1 - x2) + (y1 - y2)*(y1 - y2)))
 
 
-FILE *fw;
+FILE *fp;
 
 const double pihalf = M_PI * 0.5;
 const double twopi = M_PI * 2.;
@@ -70,6 +70,7 @@
 const char *mapset = NULL;
 const char *per;
 char shad_filename[GNAME_MAX];
+char *outfile;
 
 struct Cell_head cellhd;
 struct Key_value *in_proj_info, *in_unit_info;
@@ -163,7 +164,7 @@
     struct
     {
 	struct Option *elevin, *dist, *coord, *direction, *horizon, *step,
-	    *bufferzone, *e_buff, *w_buff, *n_buff, *s_buff, *maxdistance;
+	    *bufferzone, *e_buff, *w_buff, *n_buff, *s_buff, *maxdistance, *output;
     } parm;
 
     struct
@@ -289,6 +290,11 @@
     parm.dist->description = _("Sampling distance step coefficient (0.5-1.5)");
     parm.dist->guisection = _("Output options");
 
+    parm.output = G_define_standard_option(G_OPT_F_OUTPUT);
+    parm.output->required = NO;
+    parm.output->answer = "-";
+    parm.output->description =
+        _("Name of file for output (use output=- for stdout)");
 
     flag.degreeOutput = G_define_flag();
     flag.degreeOutput->key = 'd';
@@ -350,6 +356,15 @@
 	   xcoord = (int) ((xcoord-xmin)/stepx);
 	   ycoord = (int) ((ycoord-ymin)/stepy);
 	 */
+         
+	/* Open ASCII file for output or stdout */
+	outfile = parm.output->answer;
+
+	if ((strcmp("-", outfile)) == 0) {
+	    fp = stdout;
+	}
+	else if (NULL == (fp = fopen(outfile, "w")))
+	     G_fatal_error(_("Unable to open file <%s>"), outfile);
     }
 
     if (parm.direction->answer != NULL)
@@ -765,8 +780,8 @@
 
     angle = (single_direction * deg2rad) + pihalf;
 
-
     maxlength = fixedMaxLength;
+    fprintf(fp, "azimuth,horizon_height\n");
 
     for (i = 0; i < printCount; i++) {
 
@@ -814,10 +829,8 @@
 	stepsinangle = stepxy * delt_nor / delt_dist;
 	stepcosangle = stepxy * delt_east / delt_dist;
 
-
 	shadow_angle = horizon_height();
 
-
 	if (degreeOutput) {
 	    shadow_angle *= rad2deg;
 	}
@@ -827,7 +840,7 @@
 	else if (printangle >= 360.)
 	    printangle -= 360;
 
-	G_message("%lf,%lf", printangle, shadow_angle);
+	fprintf(fp, "%lf,%lf\n", printangle, shadow_angle);
 
 	angle += dfr_rad;
 
@@ -1060,6 +1073,7 @@
 	z_orig = zp = z[yindex][xindex];
 
 	calculate_shadow();
+        fclose(fp);
 
     }
     else {

Modified: grass/trunk/raster/r.horizon/r.horizon.html
===================================================================
--- grass/trunk/raster/r.horizon/r.horizon.html	2013-12-29 23:18:13 UTC (rev 58551)
+++ grass/trunk/raster/r.horizon/r.horizon.html	2013-12-29 23:43:08 UTC (rev 58552)
@@ -93,6 +93,9 @@
 upwards from 0 to total number of directions. If you use <b>r.horizon</b>
 in the single point mode this option will be ignored. 
 
+<p>The <i>output</i> parameter allows to save the resulting horizon
+angles in a comma separated ASCII file (single point mode only). If
+you use <b>r.horizon</b> in the raster mode this option will be ignored.
 
 <p>At the moment the elevation and maximum distance must be measured in meters, 
 even if you use geographical coordinates (longitude/latitude). If your 
@@ -119,7 +122,6 @@
 cardinal directions caused by the projection (see above). 
 
 
-
 <h2>EXAMPLES</h2>
 
 The examples are intended for the North Carolina sample dataset:
@@ -131,8 +133,9 @@
     coordinate=638871.6,223384.4 maxdistance=5000
 
 # determine horizon values starting at 90 deg (North), step size of 5 deg:
+# save result in CSV file
 r.horizon elev_in=elevation direction=90 horizon_step=5 bufferzone=200 \
-    coordinate=638871.6,223384.4 maxdistance=5000
+    coordinate=638871.6,223384.4 maxdistance=5000 output=horizon.csv
 </pre></div>
 
 



More information about the grass-commit mailing list