[GRASS-user] simple Grass.script python script, how to?

Johannes Radinger JRadinger at gmx.at
Fri Jan 28 09:20:34 EST 2011

-------- Original-Nachricht --------
> Datum: Fri, 28 Jan 2011 12:56:27 +0100
> Von: Martin Landa <landa.martin at gmail.com>
> An: Johannes Radinger <JRadinger at gmx.at>
> CC: grass-user at lists.osgeo.org
> Betreff: Re: [GRASS-user] simple Grass.script python script, how to?

> Hi,
> 2011/1/28 Johannes Radinger <JRadinger at gmx.at>:
> > After reading the grass-website about python scripts, I still don't know
> how to start. I just want to create a .py file which i than want to run.
> >
> > This python script should do following simple grass command:
> >
> > v.to.rast input=river output=river_raster use=val value=1 --o
> > but how does a pyhton script look like for this command?
> use run_command from `core` module [1].
> grass.run_command('v.to.rast', overwrite = True, input = 'river',
> output = 'river_raster', use = 'val' value = 1)
> > I first need to define my location and my mapset and I have to import or
> define somehow the variable river. How do I set the region? In Grass I
> just do g.region vect=river res=10 save=region_river.
> same as above use run_command().

Thank you for your first hints, but there are still a lot of problems for me at the beginning. First i still don't know how to create the location and mapset (coordination system) and I don't know how the things work with the parser.

I have an existing mapset in a defined location set by GRASS GIS (inside the programme) and there is this vector-file stored. Now I tried to write a script:

import sys
from grass.script import core as grass

def main():
    grass.run_command('g.gisenv', set=options["MAPSET=C:\Users\MyName\Documents\Grass GIS\River_Location\River"])    
    grass.run_command('g.region', vect=options['River_GK'], res=options[10] save=options['River_Region'])              
    grass.run_command('v.to.rast', overwrite=options[True], input='River_GK', output='river_raster', use=options['val'], value=options[1])
if __name__ == "__main__":
    options, flags = grass.parser()

But nothing happens....I think there are a lot of things missing or wrong, but I can't find any nice describtion of a 'how to' for beginners.


> Martin
> [1]
> http://grass.osgeo.org/programming7/namespacepython_1_1core.html#af6691d41ff96f1e0f8c6c1822c6b808c
> -- 
> Martin Landa <landa.martin gmail.com> * http://geo.fsv.cvut.cz/~landa

Sicherer, schneller und einfacher. Die aktuellen Internet-Browser -
jetzt kostenlos herunterladen! http://portal.gmx.net/de/go/atbrowser

More information about the grass-user mailing list