[GRASS-user] Re: v.to.rast in a python loop, error

Margherita Di Leo diregola at gmail.com
Mon Feb 13 06:20:18 EST 2012


Hi,


> >
> > > Have you tried adding flags = '-o' as an argument to
> > > grass.run_command? That will overwrite the output raster if it already
> > > exists.
> >
> > Actually, it will raise a ScriptError if you're running anything later
> > than 6.4.1. If you want to pass the --overwrite flag to the module,
> > you should pass overwrite=True to run_command() etc.
>
> so if I understand you correctly: This error is normal to GRASS6.5SVN?
>
> It is really an interesting behavior. I remove the raster maps manually
> (with g.remove and f-flag) and cross check (g.list) so that the raster maps
> a really removed. Although the script gives this error...
> However when I include g.remove in the script to remove them before
> v.to.rast everything works fine.
> Interestingly when I include g.list before v.to.rast in the script (and
> all raster maps were removed before), g.list states that the maps are
> existing... So it seems that there is somehow a problem with the
> script/pyhton/GRASS interaction... although it works for Moritz Lennert.
> Somehow it seems that v.to.rast has two passes (or more)...and the first
> one is performed even before g.list is processed in the script???
>
> About my setup: GRASS6.5SVN (rev50782) on Mac OS X, Python 2.6.6...
>
> and here the script with g.remove and g.list:
>
> #!/usr/bin/env python
>
> import sys
>
> import grass.script as grass
> import grass.script.setup as gsetup
>
> def main():
>
>
>    #grass.run_command("g.remove",
>        #                               flags = "f",
>     #               rast = "rast_FULL_HYDRO,rast_LENGTH")
>
>    grass.run_command("g.list",
>                                        type = "rast")
>
>
>
>    for i in ['FULL_HYDRO','LENGTH']:
>
>        grass.run_command("v.to.rast",
>                    input = "streams at PERMANENT",
>                    output = "rast_"+i,
>                    type = "line",
>                    use = "attr",
>                    column = i)
>
>    return 0
>
> if __name__ == "__main__":
>    sys.exit(main())
>
>
>
> And my output with although all maps were removed manually with g.remove
> and cross checked:
>
> Launching script '/Users/Johannes Radinger/Desktop/test2.py'...
> (Mon Feb 13 11:12:27 2012)
> /Users/Johannes Radinger/Desktop/test2.py
> ----------------------------------------------
> raster files available in mapset <PERMANENT>:
> basins          elevation_shade lakes           soils
> elevation       geology         landuse
> raster files available in mapset <user1>:
> rast_FULL_HYDRO rast_LENGTH
> ----------------------------------------------
> ERROR: option <output>: <rast_FULL_HYDRO> exists.
> ERROR: option <output>: <rast_LENGTH> exists.
> (Mon Feb 13 11:12:27 2012) Command finished (0 sec)
>


Please try quiet option to remove them. Furthermore, remove them separately:

grass.run_command('g.remove', rast = 'rast_FULL_HYDRO', quiet = True)
grass.run_command('g.remove', rast = 'rast_LENGTH', quiet = True)

HTH,
regards madi

>
>
>
> Of course I can use the overwrite-flag (overwrite=TRUE) to overcome the
> problem (or use g.remove in the script). I just wanted to know if that is a
> plattform specific problem, a problem with my script or just a bug in the
> GRASS-Python code...
>
> Best regards
> /johannes
>
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.osgeo.org/pipermail/grass-user/attachments/20120213/fe49f8ca/attachment.html


More information about the grass-user mailing list