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

Johannes Radinger JRadinger at gmx.at
Mon Feb 13 06:35:20 EST 2012


Hi,

-------- Original-Nachricht --------
> Datum: Mon, 13 Feb 2012 12:20:18 +0100
> Von: Margherita Di Leo <diregola at gmail.com>
> An: grass-user at lists.osgeo.org, JRadinger at gmx.at, glynn at gclements.plus.com, scott.sinclair.za at gmail.com
> Betreff: Re: v.to.rast in a python loop, error

> 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)


Dear madi,

Here is not a problem with deleting/removing the rasters. This works either in the script via grass.run_command or outside mannully with g.remove. They are defenitely deleted (checked with g.list and even checked in my explorer). There is nothing left...
In my opininon, the problem is probably with the v.to.rast command in the python script in my setup and might be just a bug...

/johannes

> 
> 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
> >
> >
> >

-- 
NEU: FreePhone 3-fach-Flat mit kostenlosem Smartphone!                                  
Jetzt informieren: http://www.gmx.net/de/go/freephone/


More information about the grass-user mailing list