[GRASSLIST:7187] grass commands with python script

hello

I was wondering if it was possible to write grass commands
in python script.

can you send me an example, link, doc ?

regards

Ahmet Temiz

______________________________________
XamimeLT - installed on mailserver for domain @deprem.gov.tr
Queries to: postmaster@deprem.gov.tr
______________________________________
The views and opinions expressed in this e-mail message are the sender's own
and do not necessarily represent the views and the opinions of Earthquake Research Dept.
of General Directorate of Disaster Affairs.

Bu e-postadaki fikir ve gorusler gonderenin sahsina ait olup, yasal olarak T.C.
B.I.B. Afet Isleri Gn.Mud. Deprem Arastirma Dairesi'ni baglayici nitelikte degildir.

Hello orkun,

On Thu, 16 Jun 2005 17:33:38 +0300 orkun <temiz@deprem.gov.tr> wrote:

hello

I was wondering if it was possible to write grass commands
in python script.

can you send me an example, link, doc ?

As my python knowledge is near to zero here an untested code-snippet:
<snippet>
cmds = [ 'd.mon stop=x6',
                 'g.region -d res=1',
                 'r.colors map=ortho col=grey',
                 'd.mon x6',
                 'd.mon sel=x6',
                 'd.rast ortho' ]
        for cmd in cmds:
                dlg.ShowModal()
                dlg.Destroy()
                return
</snippet>

Perhaps some python-gurus can provide better help...

Best
  Stephan
  
--
GDF Hannover - Solutions for spatial data analysis and remote sensing
Hannover Office (TCH) - Vahrenwalder Straße 7 - D-30165 Hannover
Internet: www.gdf-hannover.de - Email: holl@gdf-hannover.de
Phone : ++49-(0)511-9357560 - Fax: ++49-(0)511-9357100

Here is a little example that shows running a Python script from within grass:

**** start script ***

#!/cygdrive/c/python23/python
import os

# Run a command (no return)
os.system('d.rast dem_sd')

# Run a command and connect to the output stream (pipe)
pipe_in = os.popen('g.gisenv', 'r')

# Read the output from the pipe just like a file
output = pipe_in.readlines()

# Step through the output data
for line in output:
    field = line.split('=')
    print "%s is set to: %s" % (field[0], field[1])

**** end script *****

This script paints a raster (change the name to suit your dataset of
course) and then prints the grass environment variables.

You can also use popen to pipe data to a command. Note that this works
on Windows Grass too (in fact I am using the windows version of python
above!)

Hope that gets you started,

David

On 6/17/05, Stephan Holl <holl@gdf-hannover.de> wrote:

Hello orkun,

On Thu, 16 Jun 2005 17:33:38 +0300 orkun <temiz@deprem.gov.tr> wrote:

> hello
>
> I was wondering if it was possible to write grass commands
> in python script.
>
> can you send me an example, link, doc ?

As my python knowledge is near to zero here an untested code-snippet:
<snippet>
cmds = [ 'd.mon stop=x6',
                 'g.region -d res=1',
                 'r.colors map=ortho col=grey',
                 'd.mon x6',
                 'd.mon sel=x6',
                 'd.rast ortho' ]
        for cmd in cmds:
                dlg.ShowModal()
                dlg.Destroy()
                return
</snippet>

Perhaps some python-gurus can provide better help...

Best
        Stephan

--
GDF Hannover - Solutions for spatial data analysis and remote sensing
Hannover Office (TCH) - Vahrenwalder Straße 7 - D-30165 Hannover
Internet: www.gdf-hannover.de - Email: holl@gdf-hannover.de
Phone : ++49-(0)511-9357560 - Fax: ++49-(0)511-9357100

--
David Finlayson
Marine Geology & Geophysics
School of Oceanography
Box 357940
University of Washington
Seattle, WA 98195-7940
USA

Office: Marine Sciences Building, Room 112
Phone: (206) 616-9407
Web: http://students.washington.edu/dfinlays