[GRASS-SVN] r70930 - grass/trunk/general/g.parser

svn_grass at osgeo.org svn_grass at osgeo.org
Sat Apr 22 12:39:11 PDT 2017


Author: neteler
Date: 2017-04-22 12:39:11 -0700 (Sat, 22 Apr 2017)
New Revision: 70930

Modified:
   grass/trunk/general/g.parser/g.parser.html
Log:
g.parser manual: added creation of a script example

Modified: grass/trunk/general/g.parser/g.parser.html
===================================================================
--- grass/trunk/general/g.parser/g.parser.html	2017-04-22 18:13:23 UTC (rev 70929)
+++ grass/trunk/general/g.parser/g.parser.html	2017-04-22 19:39:11 UTC (rev 70930)
@@ -228,7 +228,7 @@
 
 The flag <b>--script</b> added to a GRASS command, generates shell
 output. To write out a <em>g.parser</em> boilerplate for easy
-prototyping of shell scripts, the flag <b>--script</b> can be added
+prototyping of Python scripts, the flag <b>--script</b> can be added
 to any GRASS command. Example:
 
 <div class="code"><pre>
@@ -515,9 +515,125 @@
 printf ("Value of GIS_OPT_vect: '%s'\n", $ENV{'GIS_OPT_VECTOR'});
 
 #### end of your code ####
+</pre></div>
 
+<h3>Easy creation of a script</h3>
+
+By using the <b>--script</b> flag with any GRASS GIS module (must be run in
+a GRASS GIS session) header, description, keywords, parameters, flags and
+a template main Python script section will be printed in the terminal which
+can be saved to a file and used for further script programming.
+<p>
+In this example, the module <em>v.what.rast</em> is used as an example.
+The output is shown below:
+
+<div class="code"><pre>
+v.what.rast --script
+
+#!/usr/bin/env python
+############################################################################
+#
+# MODULE:       v.what.rast_wrapper
+# AUTHOR(S):    username
+# PURPOSE:      Wrapper for v.what.rast
+# COPYRIGHT:    (C) 2017 by username, and the GRASS Development Team
+#
+#  This program is free software; you can redistribute it and/or modify
+#  it under the terms of the GNU General Public License as published by
+#  the Free Software Foundation; either version 2 of the License, or
+#  (at your option) any later version.
+#
+#  This program is distributed in the hope that it will be useful,
+#  but WITHOUT ANY WARRANTY; without even the implied warranty of
+#  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+#  GNU General Public License for more details.
+#
+############################################################################
+
+#%module
+#% description: Uploads raster values at positions of vector points to the table.
+#% keyword: vector, sampling, raster, position, querying, attribute table, surface information
+#%end
+#%flag
+#% key: i
+#% description: Interpolate values from the nearest four cells
+#%end
+#%flag
+#% key: p
+#% description: Print categories and values instead of updating the database
+#%end
+#%option
+#% key: map
+#% type: string
+#% required: yes
+#% multiple: no
+#% key_desc: name
+#% label: Name of vector points map for which to edit attributes
+#% description: Or data source for direct OGR access
+#% gisprompt: old,vector,vector
+#%end
+#%option
+#% key: layer
+#% type: string
+#% required: no
+#% multiple: no
+#% label: Layer number or name
+#% description: Vector features can have category values in different layers. This number determines which layer to use. When used with direct OGR access this is the layer name.
+#% answer: 1
+#% gisprompt: old,layer,layer
+#%end
+#%option
+#% key: type
+#% type: string
+#% required: no
+#% multiple: yes
+#% options: point,centroid
+#% description: Input feature type
+#% answer: point
+#%end
+#%option
+#% key: raster
+#% type: string
+#% required: yes
+#% multiple: no
+#% key_desc: name
+#% description: Name of existing raster map to be queried
+#% gisprompt: old,cell,raster
+#%end
+#%option
+#% key: column
+#% type: string
+#% required: no
+#% multiple: no
+#% key_desc: name
+#% description: Name of attribute column to be updated with the query result
+#% gisprompt: old,dbcolumn,dbcolumn
+#%end
+#%option
+#% key: where
+#% type: string
+#% required: no
+#% multiple: no
+#% key_desc: sql_query
+#% label: WHERE conditions of SQL statement without 'where' keyword
+#% description: Example: income < 1000 and population >= 10000
+#%end
+
+import sys
+
+import grass.script as grass
+
+def main():
+    # put code here
+
+    return 0
+
+if __name__ == "__main__":
+    options, flags = grass.parser()
+    sys.exit(main())
 </pre></div>
 
+
 <h2>SEE ALSO</h2>
 
 <em>



More information about the grass-commit mailing list