[GRASS-user] problems importing vector and raster data via python script

Glynn Clements glynn at gclements.plus.com
Wed Jan 27 12:35:33 EST 2010

Sonja Jankowfsky wrote:

> I'm running a python script under windows/eclipse, where I try to import 
> a shape and a raster file with v.in.ogr and r.in.gdal.
> grass.run_command("r.in.gdal",'-o', 
> input='E:\pythoninput\mnyzeron5m.asc', output='dem5m', '-o')

Python uses backslash as an escape character; if you need to use a
backslash in a string literal, either use two backslashes, i.e.:


or use a raw literal, i.e.:


Alternatively, a forward slash will work. But scripts should rarely
need to have literal pathnames embedded within them.

> grass.run_command("v.in.ogr", '-o', 
> dsn='E:\pythoninput\Mercier_ditch.shp', output='ditch2', '-o')

run_command() etc use the "flags" argument to specify flags (without
the leading '-'), e.g.:

grass.run_command("v.in.ogr", flags='o', dsn=r'E:\pythoninput\Mercier_ditch.shp', output='ditch2')

Glynn Clements <glynn at gclements.plus.com>

More information about the grass-user mailing list