[GRASS-user] Re: Using shell and perl scripts via a python script in windows, or better change to Linux?

Nikos Alexandris nikos.alexandris at felis.uni-freiburg.de
Sat Jul 24 01:56:34 EDT 2010


On Friday 23 of July 2010 11:58:54 sonja1 wrote:
> Maybe I gave up to early, but my solution is the change to Linux.
> I finally got my python scripts, which call the Geomhydas shell and perl
> scripts, to work.
> I wrote some documentation:
> 
> How to run Python/Shell/Perl scripts in combination with Grass under Linux
> (here tested for Debian)
> 
> 
> 1.	Install Grass6.4 for the corresponding Linux version
> 2.	Install Python2.6
> 
> 
> Scripts Geo-Mhydas (in Perl and Shell)
> -	create folder segmentation in home/user/
> -	give you administrator rights in this folder
> -	copy the scripts inside this folder
> 
> Environment variables to set:
> The following paragraph has to be added at the end of the file .bashrc
> (which is located as hidden file in home/user/. A hidden file can be seen
> and modified in an editor à open à right click in this window à mark show
> hidden files)
> Then edit:
> 
> export GISBASE=usr/lib/grass64
> export
> PATH=$PATH:/home/user/segmentation:/$GISBASE/bin:/$GISBASE/scripts:/$GISBAS
> E/etc:/$GISBASE/lib:/usr/lib/python2.5:/$GISBASE/etc/python/grass:/$GISBASE
> /etc/python/grass/lib:/$GISBASE/etc/python/grass/script export
> GISRC=$HOME/.grassrc6
> export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:$GISBASE/lib
> export PYTHONPATH=$GISBASE/etc/python
> export PYTHONLIB=/usr/lib/python2.5
> 
> export GIS_LOCK=$$
> 
> Replace user with your user name.
> Linux has to be restarted in order to consider these variables.
> You can check if the variables are right in the terminal with:
> 
> echo $PATH
> 
> The variables should contain the values shown above. $GISBASE is a
> variable, if it is not recognised correctly, just replace it by its value
> in the following variables.
> 
> Once restarted you can start Grass via the terminal with the command
> grass64.
> 
> The Python scripts should look as follows and have to contain the first
> line.
> 
> #!usr/bin/env python
> 
> import grass.script as grass
> 
> '''Affiche le contenu du mapset'''
> '''Display the mapset'''
> env = grass.gisenv()
> print env
> vectors = grass.read_command("g.list", type='vect')
> print vectors
> 
> filvoirie=raw_input("Please enter the name of the input vector (line) file
> : ")
> grass.run_command("m.disline", input=filvoirie, output='filvoirie_disline',
> length='10',overwrite=True)
> 
> Save the script as script.py
> 
> Here m.disline is a combination of shell and perl scripts of Geo-Mhydas.
> 
> To run the python script go to your terminal where you started Grass.
> 
> Type python /location of script/script.py
> 
> And watch your program execute!

A candidate for the wiki, right?
Thanks, Nikos


More information about the grass-user mailing list