[GRASS-user] Python scripting and GRASS

Markus Neteler neteler at osgeo.org
Sun Jan 17 18:59:33 EST 2010


Hi Sonja,

On Thu, Jan 14, 2010 at 11:06 AM, Sonja Jankowfsky
<sonja.jankowfsky at cemagref.fr> wrote:
> Greetings,
>
> I have some questions concerning Python scripting for GRASS under windows.

[I don't have much experience on Windows]

> I'm relatively new to GRASS, and I'm neither familiar with Python nor UNIX
> (but I have some programming experience, C++, Java). I have six months, in
> which I have to work on the preprocessing of a hydrologic model with GRASS.
> For that it will be necessary to write some scripts. The idea was to use
> Python for this, as it is platform independent and more powerfull than UNIX

You mean Shell script: yes, that's right that Python offers way more than
shell scripting. Due to that all shell scripts in GRASS 7 have been rewritten
to Python (they are a good resource to learn how to do it).

> (I'm working on windows as the model only runs on windows) . However, I have
> some problems getting started and all what I found on the internet was quite
> confusing.

In case that GRASS sources are involved, please indicate how to improve
them. We are always happy about detailed feedback.

> I would appreciate all advice concerning the following questions:
>
> Which compiler is usually used for Python scripting with GRASS? Is there a
> standard way?

Python does not require any compiler. You just need Python installed
(Python 2.x, not 3.x).

> Is it possible to do the scripting inside GRASS?

Right. See
http://grass.osgeo.org/wiki/GRASS_and_Python
http://grass.osgeo.org/wiki/Using_Eclipse_to_develop_GRASS_Python_programs

> Can I use SWIG? Do I have to install it extra, or is there an integrated
> version?

SWIG is an extra software which generates extra Python bindings.
You do not necessarily need it for GRASS-Python programming, it
depends on the level of integration you want to achieve between your
model and GRASS.

> I found a description how to configure Eclipse for python and GRASS, but up
> to now I get some Attribut errors while compiling the simple test code (I
> think there are still some problems with the environment variables).

You will need to post the errors to let us better understand the problem.

> Can I run python scripts with MySYS?

I think so (Python needs to be installed).

> Can I access to all the GRASS functions with Python?

In general yes, but there are different levels of doing so.
Please see the Python in GRASS 7 for inspiration:
http://svn.osgeo.org/grass/grass/trunk/scripts/
(or your download GRASS 7 source code).

> Is it usefull to use IDLE?

Perhaps some GRASS-Python developer can comment:
http://en.wikipedia.org/wiki/IDLE_(Python)

I would say: personal taste: try and decide...

> Is the GRASS plugin for QGIS written in Python?

No, it is in C++:
https://svn.osgeo.org/qgis/branches/Release-1_4_0/src/plugins/grass/

> Or is it just easier to write the scripts in UNIX?

(you mean Unix shell)
Maybe slightly easier but Python offers way more. So better to invest
in Python.

> Is it possible to execute the UNIX scripts with MySYS under windows?

Very limited only. So better Python....

Best
Markus


More information about the grass-user mailing list