[GRASS-SVN] r64291 - grass/trunk/scripts/i.spectral
svn_grass at osgeo.org
svn_grass at osgeo.org
Fri Jan 23 12:28:49 PST 2015
Author: ychemin
Date: 2015-01-23 12:28:49 -0800 (Fri, 23 Jan 2015)
New Revision: 64291
Modified:
grass/trunk/scripts/i.spectral/i.spectral.py
Log:
added text file output of spectrum
Modified: grass/trunk/scripts/i.spectral/i.spectral.py
===================================================================
--- grass/trunk/scripts/i.spectral/i.spectral.py 2015-01-23 20:13:19 UTC (rev 64290)
+++ grass/trunk/scripts/i.spectral/i.spectral.py 2015-01-23 20:28:49 UTC (rev 64291)
@@ -48,7 +48,7 @@
#%end
#%option G_OPT_F_OUTPUT
#% key: output
-#% description: Name for output image
+#% description: Name for output image (or text file for -t)
#% guisection: Output
#% required : no
#%end
@@ -69,6 +69,10 @@
#% key: g
#% description: Use gnuplot for display
#%end
+#% flag
+#% key: t
+#% description: output to text file
+#%end
import os
import atexit
@@ -79,6 +83,13 @@
def cleanup():
try_rmdir(tmp_dir)
+def write2textf(what, output):
+ outf = open(output, 'w')
+ i=0
+ for row in enumerate(what):
+ i=i+1
+ outf.write("%d, %s\n" % (i,row))
+ outf.close()
def draw_gnuplot(what, xlabels, output, img_format, coord_legend):
xrange = 0
@@ -187,7 +198,8 @@
img_fmt = options['format']
coord_legend = flags['c']
gnuplot = flags['g']
-
+ textfile = flags['t']
+
global tmp_dir
tmp_dir = grass.tempdir()
@@ -197,6 +209,10 @@
if group and raster:
grass.fatal(_("group= and raster= are mutually exclusive"))
+ # -t needs an output filename
+ if textfile and not output:
+ grass.fatal(_("Writing to text file requires output=filename"))
+
# check if gnuplot is present
if gnuplot and not grass.find_program('gnuplot', '-V'):
grass.fatal(_("gnuplot required, please install first"))
@@ -232,6 +248,8 @@
# build data files
if gnuplot:
draw_gnuplot(what, xlabels, output, img_fmt, coord_legend)
+ elif textfile:
+ write2textf(what, output)
else:
draw_linegraph(what)
More information about the grass-commit
mailing list