[GRASS-SVN] r70131 - in grass/trunk/doc/python: . script

svn_grass at osgeo.org svn_grass at osgeo.org
Mon Dec 26 08:20:33 PST 2016


Author: wenzeslaus
Date: 2016-12-26 08:20:33 -0800 (Mon, 26 Dec 2016)
New Revision: 70131

Added:
   grass/trunk/doc/python/script/
   grass/trunk/doc/python/script/Makefile
   grass/trunk/doc/python/script/r.example.html
   grass/trunk/doc/python/script/r.example.py
Log:
doc: add python raster module example to source code

Added: grass/trunk/doc/python/script/Makefile
===================================================================
--- grass/trunk/doc/python/script/Makefile	                        (rev 0)
+++ grass/trunk/doc/python/script/Makefile	2016-12-26 16:20:33 UTC (rev 70131)
@@ -0,0 +1,7 @@
+MODULE_TOPDIR = ../..
+
+PGM = r.example
+
+include $(MODULE_TOPDIR)/include/Make/Script.make
+
+default: script

Added: grass/trunk/doc/python/script/r.example.html
===================================================================
--- grass/trunk/doc/python/script/r.example.html	                        (rev 0)
+++ grass/trunk/doc/python/script/r.example.html	2016-12-26 16:20:33 UTC (rev 70131)
@@ -0,0 +1,18 @@
+<h2>DESCRIPTION</h2>
+
+<em>r.example</em> selects values from raster above value of mean plus
+standard deviation
+
+<h2>SEE ALSO</h2>
+
+<em>
+<a href="r.univar.html">r.univar</a>,
+<a href="r.mapcalc.html">r.mapcalc</a>
+</em>
+
+
+<h2>AUTHOR</h2>
+
+GRASS Development Team
+
+<p><i>Last changed: $Date: 2014-08-05 17:45:01 -0400 (Tue, 05 Aug 2014) $</i>

Added: grass/trunk/doc/python/script/r.example.py
===================================================================
--- grass/trunk/doc/python/script/r.example.py	                        (rev 0)
+++ grass/trunk/doc/python/script/r.example.py	2016-12-26 16:20:33 UTC (rev 70131)
@@ -0,0 +1,39 @@
+#!/usr/bin/env python
+
+#%module
+#% description: Selects values from raster above value of mean plus standard deviation
+#% keyword: raster
+#% keyword: select
+#% keyword: standard deviation
+#%end
+#%option G_OPT_R_INPUT
+#%end
+#%option G_OPT_R_OUTPUT
+#%end
+
+
+import sys
+
+import grass.script as gscript
+from grass.exceptions import CalledModuleError
+
+
+def main():
+    options, flags = gscript.parser()
+    input_raster = options['input']
+    output_raster = options['output']
+
+    try:
+        stats = gscript.parse_command('r.univar', map=input_raster, flags='g')
+    except CalledModuleError as e:
+        gscript.fatal('{}'.format(e))
+    raster_mean = float(stats['mean'])
+    raster_stddev = float(stats['stddev'])
+    raster_high = raster_mean + raster_stddev
+    gscript.mapcalc('{r} = {i} > {v}'.format(r=output_raster, i=input_raster,
+                                             v=raster_high))
+    return 0
+
+
+if __name__ == "__main__":
+    sys.exit(main())



More information about the grass-commit mailing list