[GRASS-SVN] r46423 - grass-addons/raster/r.viewshed

svn_grass at osgeo.org svn_grass at osgeo.org
Thu May 26 04:30:49 EDT 2011


Author: hamish
Date: 2011-05-26 01:30:49 -0700 (Thu, 26 May 2011)
New Revision: 46423

Modified:
   grass-addons/raster/r.viewshed/grass.cc
   grass-addons/raster/r.viewshed/main.cc
   grass-addons/raster/r.viewshed/visibility.h
Log:
add a flag to allow consideration of atmospheric refraction (thanks for the research Ben)


Modified: grass-addons/raster/r.viewshed/grass.cc
===================================================================
--- grass-addons/raster/r.viewshed/grass.cc	2011-05-26 08:29:16 UTC (rev 46422)
+++ grass-addons/raster/r.viewshed/grass.cc	2011-05-26 08:30:49 UTC (rev 46423)
@@ -54,9 +54,11 @@
 
 
 /* ------------------------------------------------------------ */
-/* if viewOptions.doCurv is on then adjust the passed height for
+/* If viewOptions.doCurv is on then adjust the passed height for
    curvature of the earth; otherwise return the passed height
-   unchanged. 
+   unchanged.
+   If viewOptions.doRefr is on then adjust the curved height for
+   the effect of atmospheric refraction too.
  */
 surface_type adjust_for_curvature(Viewpoint vp, double row,
 			   double col, surface_type h,
@@ -73,14 +75,35 @@
                              G_row_to_northing(vp.row + 0.5, &(hd->window)),
 			     G_col_to_easting(col + 0.5, &(hd->window)),
 			     G_row_to_northing(row + 0.5, &(hd->window)));
-		    
-    return h - ((dist * dist) / (2.0 * viewOptions.ellps_a));
+
+    double adjustment = (dist * dist) / (2.0 * viewOptions.ellps_a);
+
+    if (!viewOptions.doRefr)
+	return h - adjustment;
+
+    /* in future we should calculate this based on the physics, for now we
+       just fudge by the 1/7th approximation.
+
+	?? See ??
+
+	@article{yoeli1985making,
+	  title={The making of intervisibility maps with computer and plotter},
+	  author={Yoeli, Pinhas},
+	  journal={Cartographica: The International Journal for Geographic Information and Geovisualization},
+	  volume={22},
+	  number={3},
+	  pages={88--103},
+	  year={1985},
+	  publisher={UT Press}
+	}
+
+    */
+    return h - (adjustment * 6.0/7.0);
 }
 
 
 
 
-
 /* ************************************************************ */
 /*return a GridHeader that has all the relevant data filled in */
 GridHeader *read_header(char *rastName, Cell_head * region)

Modified: grass-addons/raster/r.viewshed/main.cc
===================================================================
--- grass-addons/raster/r.viewshed/main.cc	2011-05-26 08:29:16 UTC (rev 46422)
+++ grass-addons/raster/r.viewshed/main.cc	2011-05-26 08:30:49 UTC (rev 46423)
@@ -147,6 +147,7 @@
     viewOptions.maxDist = INFINITY_DISTANCE;
     viewOptions.outputMode = OUTPUT_ANGLE;
     viewOptions.doCurv = 0;
+    viewOptions.doRefr = 0;
 
     parse_args(argc, argv, &vpRow, &vpCol, &viewOptions, &memSizeBytes,
 	       &region);
@@ -454,7 +455,14 @@
     curvature->description =
 	_("Consider the curvature of the earth (current ellipsoid)");
 
+    /* atmospheric refraction flag */
+    struct Flag *refractionFlag;
 
+    refractionFlag = G_define_flag();
+    refractionFlag->key = 'r';
+    refractionFlag->description =
+	_("Consider the effect of atmospheric refraction");
+
     /* boolean output flag */
     struct Flag *booleanOutput;
 
@@ -471,6 +479,7 @@
     elevationFlag->description =
 	_("Output format is invisible = NULL, else current elev - viewpoint_elev");
 
+
     /* viewpoint coordinates */
     struct Option *viewLocOpt;
 
@@ -568,8 +577,14 @@
 	G_fatal_error(_("A negative max distance value is not allowed"));
     }
 
+    viewOptions->doCurv = curvature->answer;
+    viewOptions->doRefr = refractionFlag->answer;
 
-    viewOptions->doCurv = curvature->answer;
+    if (refractionFlag->answer && !curvature->answer)
+	G_fatal_error(_("Atmospheric refraction is only calculated with "
+			"respect to the curvature of the Earth. "
+			"Enable the -c flag as well."));
+
     if (booleanOutput->answer)
 	viewOptions->outputMode = OUTPUT_BOOL;
     else if (elevationFlag->answer)

Modified: grass-addons/raster/r.viewshed/visibility.h
===================================================================
--- grass-addons/raster/r.viewshed/visibility.h	2011-05-26 08:29:16 UTC (rev 46422)
+++ grass-addons/raster/r.viewshed/visibility.h	2011-05-26 08:30:49 UTC (rev 46423)
@@ -112,18 +112,19 @@
 
     OutputMode outputMode;
     /* The mode the viewshed is output; 
-
-       in angle mode, the values recorded are   {NODATA, INVISIBLE, angle}
-
-       in boolean mode, the values recorded are {BOOL_INVISIBLE, BOOL_VISIBLE}
-
-       in elev mode, the values recorded are    {NODATA, INVISIBLE, elevation}
+       - in angle mode, the values recorded are   {NODATA, INVISIBLE, angle}
+       - in boolean mode, the values recorded are {BOOL_INVISIBLE, BOOL_VISIBLE}
+       - in elev mode, the values recorded are    {NODATA, INVISIBLE, elevation}
      */
 
     int doCurv;
     /*determines if the curvature of the earth should be considered
        when calculating.  Only implemented for GRASS version. */
 
+    int doRefr;
+    /*determines if atmospheric refraction should be considered
+       when calculating.  Only implemented for GRASS version. */
+
     double ellps_a;		/* the parameter of the ellipsoid */
     float cellsize;		/* the cell resolution */
     char streamdir[GPATH_MAX];	/* directory for tmp files */



More information about the grass-commit mailing list