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

svn_grass at osgeo.org svn_grass at osgeo.org
Fri Aug 21 12:06:16 EDT 2009


Author: neteler
Date: 2009-08-21 12:06:16 -0400 (Fri, 21 Aug 2009)
New Revision: 38823

Modified:
   grass-addons/raster/r.viewshed/main.cc
   grass-addons/raster/r.viewshed/r.viewshed.html
   grass-addons/raster/r.viewshed/visibility.h
Log:
use streamdir mechanism from r.terraflow for tmp files; longer names; gettext fixes

Modified: grass-addons/raster/r.viewshed/main.cc
===================================================================
--- grass-addons/raster/r.viewshed/main.cc	2009-08-21 15:14:02 UTC (rev 38822)
+++ grass-addons/raster/r.viewshed/main.cc	2009-08-21 16:06:16 UTC (rev 38823)
@@ -138,6 +138,7 @@
     module->description = _("IO-efficient viewshed algorithm");
 
     struct Cell_head region;
+    char *optstreamdir;
 
     if (G_get_set_window(&region) == -1)
 	G_fatal_error("Error getting current region");
@@ -326,7 +327,7 @@
 	}
 	else {
 	    /*set it */
-	    sprintf(buf, "%s=%s", STREAM_TMPDIR, "/var/tmp/");
+	    sprintf(buf, "%s=%s", STREAM_TMPDIR, viewOptions.streamdir);
 	    fprintf(stderr, "setting %s ", buf);
 	    putenv(buf);
 	    if (getenv(STREAM_TMPDIR) == NULL) {
@@ -336,7 +337,7 @@
 	    else {
 		fprintf(stderr, ", ok.\n");
 	    }
-	    printf("Intermediate stream location: %s\n", "/var/tmp/");
+	    printf("Intermediate stream location: %s\n", viewOptions.streamdir);
 	}
 	fprintf(stderr, "Intermediate files will not be deleted "
 		"in case of abnormal termination.\n");
@@ -540,7 +541,7 @@
     elevationFlag = G_define_flag();
     elevationFlag->key = 'e';
     elevationFlag->description =
-	("Output format is {NODATA, -1 (invisible), elev-viewpoint_elev (visible)}");
+	_("Output format is {NODATA, -1 (invisible), elev-viewpoint_elev (visible)}");
 
     /* viewpoint coordinates */
     struct Option *viewLocOpt;
@@ -551,7 +552,7 @@
     viewLocOpt->required = YES;
     viewLocOpt->key_desc = "lat,long";
     viewLocOpt->description =
-	("Coordinates of viewing position in latitude-longitude (if -r flag is present, then coordinates are row-column)");
+	_("Coordinates of viewing position in latitude-longitude (if -r flag is present, then coordinates are row-column)");
     viewLocOpt->guisection = _("Input_options");
 
     /* observer elevation */
@@ -575,7 +576,7 @@
     maxDistOpt->required = NO;
     maxDistOpt->key_desc = "value";
     maxDistOpt->description =
-	("Maximum visibility radius. By default infinity (-1).");
+	_("Maximum visibility radius. By default infinity (-1).");
     char infdist[10];
 
     sprintf(infdist, "%d", INFINITY_DISTANCE);
@@ -594,6 +595,21 @@
 	_("The amount of main memory in MB to be used");
     memAmountOpt->answer = "500";
 
+    /* temporary STREAM path */
+    struct Option *streamdirOpt;
+
+    streamdirOpt = G_define_option() ;
+    streamdirOpt->key        = "stream_dir";
+    streamdirOpt->type       = TYPE_STRING;
+    streamdirOpt->required   = NO;
+#ifdef __MINGW32__
+    streamdirOpt->answer     = G_convert_dirseps_from_host(G_store(getenv("TEMP")));
+#else
+    streamdirOpt->answer     = G_store("/var/tmp/");
+#endif
+    streamdirOpt->description=
+       _("Directory to hold temporary files (they can be large)");
+
     /*fill the options and flags with G_parser */
     if (G_parser(argc, argv))
 	exit(EXIT_FAILURE);
@@ -602,6 +618,7 @@
     /* store the parameters into a structure to be used along the way */
     strcpy(viewOptions->inputfname, inputOpt->answer);
     strcpy(viewOptions->outputfname, outputOpt->answer);
+    strcpy(viewOptions->streamdir,streamdirOpt->answer);
 
     viewOptions->obsElev = atof(obsElevOpt->answer);
 
@@ -847,6 +864,7 @@
 
     G_message(_("---max memory = %d MB\n"), (int)(memSizeBytes >> 20));
     G_message(_("---------------------------------\n"));
+    G_message(_("---temporary files streamdir: %s\n"), viewOptions.streamdir);
 
 #else
     printf("---------------------------------\nOptions set as:\n");
@@ -880,6 +898,7 @@
 
     printf("max memory = %d MB\n", (int)(memSizeBytes >> 20));
     printf("---------------------------------\n");
+    printf("---temporary files streamdir: %s\n", viewOptions.streamdir);
 
 #endif
 

Modified: grass-addons/raster/r.viewshed/r.viewshed.html
===================================================================
--- grass-addons/raster/r.viewshed/r.viewshed.html	2009-08-21 15:14:02 UTC (rev 38822)
+++ grass-addons/raster/r.viewshed/r.viewshed.html	2009-08-21 16:06:16 UTC (rev 38823)
@@ -180,7 +180,8 @@
 of a mountain:
 
 <div class="code"><pre>
-r.viewshed input=elevation.dem output=viewshed coordinate=598869,4916642 mem=800
+g.region rast=elevation.10m
+r.viewshed input=elevation.10m output=viewshed coordinate=598869,4916642 mem=800
 </pre></div>
 
 <h3>REFERENCES</h3>

Modified: grass-addons/raster/r.viewshed/visibility.h
===================================================================
--- grass-addons/raster/r.viewshed/visibility.h	2009-08-21 15:14:02 UTC (rev 38822)
+++ grass-addons/raster/r.viewshed/visibility.h	2009-08-21 16:06:16 UTC (rev 38823)
@@ -54,6 +54,9 @@
 /*  default max distance */
 #define  INFINITY_DISTANCE  -1
 
+/* File/directory name lengths for GRASS compatibility */
+#define GNAME_MAX 256
+#define GPATH_MAX 4096
 
 
 typedef struct viewpoint_
@@ -96,10 +99,10 @@
 {
 
     /* the name of the input raster */
-    char inputfname[100];
+    char inputfname[GNAME_MAX];
 
     /* the name of the output raster */
-    char outputfname[100];
+    char outputfname[GNAME_MAX];
 
     float obsElev;
     /* observer elevation above the terrain */
@@ -124,6 +127,7 @@
 
     double ellps_a;		/* the parameter of the ellipsoid */
     float cellsize;		/* the cell resolution */
+    char streamdir[GPATH_MAX];	/* directory for tmp files */
 } ViewOptions;
 
 



More information about the grass-commit mailing list