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

Sonja Jankowfsky sonja.jankowfsky at cemagref.fr
Thu Jan 28 04:38:28 EST 2010

Many thanks.

So, the forward slash does not work in windows. (and I know I should not 
use literal pathnames, but it's just for testing). So either two forward 
or backward slashs, or one  backward.

One other question concerning the flags: How can I put two flags at the 
same time, as for example -o --o for overwriting the projection check 
and an already existing file?

I tried everything: flags='o', flags='-o'

                flags='o -o' or flags='-o o'

                flags='o' '-o'

but the interpreter isn't happy with this solutions.

Is there any way to put several flags?



Glynn Clements a écrit :

> 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.:
> 	input='E:\\pythoninput\\mnyzeron5m.asc'
> or use a raw literal, i.e.:
> 	input=r'E:\pythoninput\mnyzeron5m.asc'
> 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')

Sonja Jankowfsky
UR Hydrologie-Hydraulique
Cemagref de Lyon
3 bis quai Chauveau CP 220
69336 Lyon Cedex 09
Tel : (+33)4 72 20 86 11 	 
Fax : (+33)4 78 47 78 75 

More information about the grass-user mailing list