<div dir="ltr">I actually forgot one useful thing which is not documented anywhere, as far as I know: You can run some module which has similar parameters as the module (script) you want to write (or you can just use any module) with the parameter --script and you will get the template for your script. This is useful for building a nice interface for your script (command line processing ).<div>

<br></div><div><br></div><div><br></div><div>For example:</div><div><br></div><div>r.regression.line --script<br></div><div><br></div><div><div>#!/usr/bin/env python</div><div>############################################################################</div>

<div>#</div><div># MODULE:       r.regression.line_wrapper</div><div># AUTHOR(S):    vasek</div><div># PURPOSE:      Wrapper for r.regression.line</div><div># COPYRIGHT:    (C) 2014 by vasek, and the GRASS Development Team</div>

<div>#</div><div>#  This program is free software; you can redistribute it and/or modify</div><div>#  it under the terms of the GNU General Public License as published by</div><div>#  the Free Software Foundation; either version 2 of the License, or</div>

<div>#  (at your option) any later version.</div><div>#</div><div>#  This program is distributed in the hope that it will be useful,</div><div>#  but WITHOUT ANY WARRANTY; without even the implied warranty of</div><div>#  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the</div>

<div>#  GNU General Public License for more details.</div><div>#</div><div>############################################################################</div><div>#%module</div><div>#% description: Calculates linear regression from two raster maps: y = a + b*x.</div>

<div>#% keywords: raster, statistics</div><div>#%end</div><div>#%flag</div><div>#% key: g</div><div>#% description: Print in shell script style</div><div>#%end</div><div>#%option</div><div>#% key: map1</div><div>#% type: string</div>

<div>#% required: yes</div><div>#% multiple: no</div><div>#% key_desc: name</div><div>#% description: Map for x coefficient</div><div>#% gisprompt: old,cell,raster</div><div>#%end</div><div>#%option</div><div>#% key: map2</div>

<div>#% type: string</div><div>#% required: yes</div><div>#% multiple: no</div><div>#% key_desc: name</div><div>#% description: Map for y coefficient</div><div>#% gisprompt: old,cell,raster</div><div>#%end</div><div>#%option</div>

<div>#% key: output</div><div>#% type: string</div><div>#% required: no</div><div>#% multiple: no</div><div>#% key_desc: name</div><div>#% description: ASCII file for storing regression coefficients (output to screen if file not specified).</div>

<div>#% gisprompt: new,file,file</div><div>#%end</div><div>import sys</div><div>import grass.script as grass</div><div>def main():</div><div>    # put code here</div><div>    return 0</div><div>if __name__ == "__main__":</div>

<div>    options, flags = grass.parser()</div><div>    sys.exit(main())</div></div></div><div class="gmail_extra"><br><br><div class="gmail_quote">On Tue, Mar 18, 2014 at 10:22 AM, Vaclav Petras <span dir="ltr"><<a href="mailto:wenzeslaus@gmail.com" target="_blank">wenzeslaus@gmail.com</a>></span> wrote:<br>

<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div dir="ltr"><div style="font-family:arial,sans-serif;font-size:13px">Hi,</div><div style="font-family:arial,sans-serif;font-size:13px">

<br></div><div style="font-family:arial,sans-serif;font-size:13px">the scripting interface is appropriate for beginners. You can script in Python or in Bash (or other shell). You can also start with Graphical Modeler and then export the model as a script and improve that script.</div>


<div style="font-family:arial,sans-serif;font-size:13px"><br></div><div style="font-family:arial,sans-serif;font-size:13px">Here is a page about how to call GRASS modules from Python, especially note the section Usage Examples:</div>


<div style="font-family:arial,sans-serif;font-size:13px"><br><div><a href="http://grasswiki.osgeo.org/wiki/GRASS_Python_Scripting_Library" target="_blank">http://grasswiki.osgeo.org/wiki/GRASS_Python_Scripting_Library</a><br>


</div><div><br></div><div>You have to run your script from GRASS, i.e. on MS Windows, you go to main menu File -> Launch Script and perhaps agree to some dialogs, or you can use Python shell in GRASS GUI call your script using execfile; or just command line is enough.</div>


<div><br></div><div>The commands (calls of GRASS modules) are usually written in manual and in tutorials for command line (including the Command console in GRASS GUI) and looks like this:<br></div><div><div><br><pre style="white-space:pre-wrap;vertical-align:top;line-height:1.2em;font-size:11.818181991577148px;background-color:rgb(249,249,249);margin-bottom:0px;font-family:monospace,monospace;margin-top:0px;border:0px none white;padding:0px;background-image:none">

r.profile <span style="color:rgb(102,0,51)">-g</span> <span style="color:rgb(0,120,0)">input</span>=mymap <span style="color:rgb(0,120,0)">output</span>=newfile <span style="color:rgb(0,120,0)">profile</span>=12244.256,-295112.597,12128.012,-295293.77</pre>


</div><div><br></div><div>And this could be rewritten to Python like this:</div><div><br></div><div><pre style="white-space:pre-wrap;vertical-align:top;line-height:1.2em;font-size:11.818181991577148px;background-color:rgb(249,249,249);margin-bottom:0px;font-family:monospace,monospace;margin-top:0px;border:0px none white;padding:0px;background-image:none">

grass.run_command(<span style="color:rgb(72,61,139)">'r.profile'</span><span style="color:rgb(102,204,102)">,</span>
               <span style="color:rgb(0,128,0)">input</span> <span style="color:rgb(102,204,102)">=</span> input_map<span style="color:rgb(102,204,102)">,</span>
               output <span style="color:rgb(102,204,102)">=</span> output_file<span style="color:rgb(102,204,102)">,</span>
               <span style="color:rgb(220,20,60)">profile</span> <span style="color:rgb(102,204,102)">=</span> [<span style="color:rgb(255,69,0)">12244.256</span><span style="color:rgb(102,204,102)">,</span>-<span style="color:rgb(255,69,0)">295112.597</span><span style="color:rgb(102,204,102)">,</span><span style="color:rgb(255,69,0)">12128.012</span><span style="color:rgb(102,204,102)">,</span>-<span style="color:rgb(255,69,0)">295293.77</span>]</pre>


</div></div><div><br></div><div>This applies to any GRASS module.</div><div><br></div></div><div style="font-family:arial,sans-serif;font-size:13px">There is one new Python interface for GRASS which is more advanced, so if you would like to use the latest (future) GRASS 7 (not current GRASS 6.4.3), you can try this:</div>


<div style="font-family:arial,sans-serif;font-size:13px"><br></div><div style="font-family:arial,sans-serif;font-size:13px"><a href="http://grasswiki.osgeo.org/wiki/Python/pygrass" target="_blank">http://grasswiki.osgeo.org/wiki/Python/pygrass</a></div>


<div style="font-family:arial,sans-serif;font-size:13px"><br></div><div style="font-family:arial,sans-serif;font-size:13px">All the best in your studies,</div><div style="font-family:arial,sans-serif;font-size:13px">Vaclav</div>


<div style="font-family:arial,sans-serif;font-size:13px"><br></div></div><div class="HOEnZb"><div class="h5"><div class="gmail_extra"><br><br><div class="gmail_quote">On Mon, Mar 17, 2014 at 10:02 PM, 杨泽龙 <span dir="ltr"><<a href="mailto:yangzelong@whu.edu.cn" target="_blank">yangzelong@whu.edu.cn</a>></span> wrote:<br>


<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">Dear Developers,<br>
     I'm a student majoring in GIS. Now, I feel interested in the open source GIS. I want to know whether there are secondary development interfaces for newers to easily develop their desired function?<br>
_______________________________________________<br>
grass-dev mailing list<br>
<a href="mailto:grass-dev@lists.osgeo.org" target="_blank">grass-dev@lists.osgeo.org</a><br>
<a href="http://lists.osgeo.org/mailman/listinfo/grass-dev" target="_blank">http://lists.osgeo.org/mailman/listinfo/grass-dev</a></blockquote></div><br></div>
</div></div></blockquote></div><br></div>