[GRASS-user] Python scripting and GRASS
Sonja Jankowfsky
sonja.jankowfsky at cemagref.fr
Mon Jan 18 03:31:28 EST 2010
Many thanks for your answers!
Eventually, I successed to execute some Grass commands with a python
script through Eclipse.
However, I only reached to call the standalone winGrass and not the
Osgeos integrated version, as the Osgeos grass do not has a lib
directory in its grass folder.
So, here are some corrections for windows to the wiki:
http://grass.osgeo.org/wiki/Using_Eclipse_to_develop_GRASS_Python_programs
pydev is now located uder: http://pydev.org/updates/
Pydev is not automatically installed, you have to click on the install button after the download.
Before creating a new project you have to add the python interpreters (click auto config and apply) and configure eclipse and pydev.
In windows the grass libraries can be found under the following directories:
C:\GRASS-4-SVN\etc
C:\GRASS-4-SVN\etc\python
C:\GRASS-4-SVN\scripts
C:\GRASS-4-SVN\bin
Concerning the script test.py, I think it should be
import grass.script as grass instead of import grass
I didn't success to run the test.py script, but the following one:
import os
import grass.script as grass
env = grass.gisenv()
print env
#list all vectors of the mapset
r = grass.read_command("g.list", type='vect')
print r
#union of two vector maps, data specific
grass.run_command("v.overlay", ainput = 'ocsol_mercier', binput =
'chaudanne_ocsol', output = 'ocsol_general', operator='or')
The environment variables for windows are as follows (depending on the
place of installation):
GISBASE C:\GRASS-4-SVN
GISRC C:\Documents and Settings\jankowfsky\.grassrc6
LD_LIBRARY_PATH C:\GRASS-4-SVN\lib
PATH
C:\GRASS-4-SVN\etc;C:\GRASS-4-SVN\etc\python;C:\GRASS-4-SVN\lib;C:\GRASS-4-SVN\bin;C:\GRASS-4-SVN\extralib;C:\GRASS-4-SVN\scripts;C:\Python26;
PYTHONLIB C:\Python26
PYTHONPATH
C:\GRASS-4-SVN\etc;C:\GRASS-4-SVN\etc\python;C:\GRASS-4-SVN\lib;C:\GRASS-4-SVN\bin;C:\GRASS-4-SVN\extralib;C:\GRASS-4-SVN\scripts;C:\Python26;
Sonja
Glynn Clements a écrit :
> Markus Neteler wrote:
>
>
>>> 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.
>>
>
> Also, the current SWIG bindings should be considered "experimental",
> and likely to change.
>
>
--
Sonja Jankowfsky
UR Hydrologie-Hydraulique
Cemagref de Lyon
3 bis quai Chauveau CP 220
69336 Lyon Cedex 09
FRANCE
Tel : (+33)4 72 20 86 11
Fax : (+33)4 78 47 78 75
More information about the grass-user
mailing list