Bläddra i källkod

scripts/i.spectral: show error message if one of the supported monitor isn't running (#1991)

* scripts/i.spectral: show error message if one of the supported monitor isn't running

By default, d.linegraph is used internally to create a graph image
which requires the launch of one of the supported monitor (cairo, png, ps).

Co-authored-by: Markus Neteler <neteler@osgeo.org>,
Tomas Zigo 3 år sedan
förälder
incheckning
79b77ba902
2 ändrade filer med 50 tillägg och 10 borttagningar
  1. 12 7
      scripts/i.spectral/i.spectral.html
  2. 38 3
      scripts/i.spectral/i.spectral.py

+ 12 - 7
scripts/i.spectral/i.spectral.html

@@ -1,11 +1,11 @@
 <h2>DESCRIPTION</h2>
 
-<em>i.spectral</em> displays spectral response at user specified 
+<em>i.spectral</em> displays spectral response at user specified
 locations in images.
 
 <h2>NOTES</h2>
 
-This script needs gnuplot to be installed.
+This script requires the launch of one of the supported monitors (cairo, png, ps) or gnuplot to be installed.
 
 
 <h2>EXAMPLE</h2>
@@ -14,7 +14,7 @@ Analysis of LANDSAT TM7 channels (North Carolina dataset):
 
 <div class="code"><pre>
 g.region raster=lsat7_2002_10 -p
-i.spectral -g input=lsat7_2002_10,lsat7_2002_20,lsat7_2002_30,lsat7_2002_40,lsat7_2002_50,lsat7_2002_70 \
+i.spectral -g raster=lsat7_2002_10,lsat7_2002_20,lsat7_2002_30,lsat7_2002_40,lsat7_2002_50,lsat7_2002_70 \
            coordinates=636069,215440,637958,223393,633277,223605
 </pre></div>
 
@@ -30,10 +30,12 @@ North Carolina sample dataset:
 <div class="code"><pre>
 g.region raster=lsat7_2002_10 -p
 LIST=`g.list type=raster pattern="lsat7_2002_[1-5,7]0" separator=","`
-i.spectral input=$LIST coordinates=637502.25,221744.25
+d.mon start=cairo output=plot.png
+i.spectral raster=$LIST coordinates=637502.25,221744.25
+d.mon stop=cairo
 </pre></div>
 
-This will search all LANDSAT map for 2002 but select only the B, G, R, 
+This will search all LANDSAT map for 2002 but select only the B, G, R,
 NIR, and MIR channels.
 
 
@@ -41,10 +43,13 @@ NIR, and MIR channels.
 
 <em>
 <a href="d.where.html">d.where</a>,
-<a href="r.what.html">r.what</a>
+<a href="r.what.html">r.what</a>,
+<a href="cairodriver.html">Cairo driver</a>,
+<a href="pngdriver.html">PNG driver</a>,
+<a href="psdriver.html">PS driver (Postscript)</a>
 </em>
 
-<h2>AUTHOR</h2>
+<h2>AUTHORS</h2>
 
 Markus Neteler<br>
 Francesco Pirotti

+ 38 - 3
scripts/i.spectral/i.spectral.py

@@ -52,14 +52,14 @@
 # %end
 # %option G_OPT_F_OUTPUT
 # % key: output
-# % description: Name for output image (or text file for -t)
+# % description: Name for output image is valid for -g (or text file for -t flag)
 # % guisection: Output
 # % required : no
 # %end
 # %Option
 # % key: format
 # % type: string
-# % description: Graphics format for output file
+# % description: Graphics format for output file (valid for -g flag)
 # % options: png,eps,svg
 # % answer: png
 # % multiple: no
@@ -67,7 +67,7 @@
 # %End
 # %flag
 # % key: c
-# % description: Show sampling coordinates instead of numbering in the legend
+# % description: Show sampling coordinates instead of numbering in the legend (valid for -g flag)
 # %end
 # % flag
 # % key: g
@@ -187,6 +187,41 @@ def draw_linegraph(what):
         colors += gp_colors
     colors = colors[0 : len(what)]
 
+    supported_monitors = ("cairo", "png", "ps")
+    monitors = gcore.read_command("d.mon", flags="l", quiet=True)
+    found = []
+    for monitor in supported_monitors:
+        if monitor in monitors:
+            found.append(monitor)
+    if not found:
+        gcore.fatal(
+            _(
+                "Supported monitor isn't running. Please launch one of the"
+                " monitors {}.".format(", ".join(supported_monitors))
+            )
+        )
+    selected_monitor = gcore.read_command("d.mon", flags="p", quiet=True).replace(
+        "\n", ""
+    )
+    if selected_monitor not in supported_monitors:
+        gcore.fatal(
+            _(
+                "Supported monitor isn't selected. Please select one of the"
+                " monitors {}.".format(", ".join(supported_monitors))
+            )
+        )
+    with open(gcore.parse_command("d.mon", flags="g", quiet=True)["env"]) as f:
+        for line in f.readlines():
+            if "GRASS_RENDER_FILE=" in line:
+                gcore.info(
+                    _(
+                        "{} monitor is used, output file {}".format(
+                            selected_monitor.capitalize(), line.split("=")[-1]
+                        )
+                    )
+                )
+                break
+
     gcore.run_command(
         "d.linegraph",
         x_file=xfile,