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

Johannes Radinger JRadinger at gmx.at
Mon Feb 13 09:19:34 EST 2012



-------- Original-Nachricht --------
> Datum: Mon, 13 Feb 2012 13:18:58 +0100
> Von: Moritz Lennert <mlennert at club.worldonline.be>
> An: Johannes Radinger <JRadinger at gmx.at>
> CC: grass-user at lists.osgeo.org, glynn at gclements.plus.com
> Betreff: Re: [GRASS-user] v.to.rast in a python loop, error

> On 13/02/12 12:26, Johannes Radinger wrote:
> >
> >
> > -------- Original-Nachricht --------
> >> Datum: Mon, 13 Feb 2012 11:46:21 +0100 Von: Moritz
> >> Lennert<mlennert at club.worldonline.be> An: Johannes
> >> Radinger<JRadinger at gmx.at> CC: grass-user at lists.osgeo.org,
> >> glynn at gclements.plus.com Betreff: Re: [GRASS-user] v.to.rast in a
> >> python loop, error
> >
> >> On 13/02/12 11:32, Johannes Radinger wrote:
> >>> 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
> >> ^^^^^^^^^^^^^^^ ^^^^^^^^^^^
> >>
> >> Both maps _do_ exist in mapset user1. So it is normal that the
> >> error appears.
> >
> > That is the strange behavior I am describing: Although g.list is
> > first in the script, v.to.rast is processed first (at least
> > partly)...or something like that...
> 
> Sounds weird to me. You could try to suspend execution after each line 
> using time.sleep(secs).
> 
> Note that in the last version of the script you posted the line with 
> g.remove is commented out.

Hi again...

I know, g.remove was commented out. If not everything is working. My interpretation is: the new raster maps are created first (before anything else is performed) then g.remove removes these and thereafter v.to.rast is processed...

This is also supported when i try your suggestion (with time.sleep). Here what I run (and please look at the order of the output)? Is there anything running in parallel?

#!/usr/bin/env python

import sys
import time

import grass.script as grass
import grass.script.setup as gsetup

def main():

	print "start"
	sys.stdout.flush()

	grass.run_command("g.list",
					type = "rast")

	time.sleep(5)
	print "1st g.list over"
	sys.stdout.flush()

	grass.run_command("g.list",
					type = "rast")

	time.sleep(5)
	print "2nd g.list over"
	sys.stdout.flush()

	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)

	time.sleep(5)

	return 0

if __name__ == "__main__":
	sys.exit(main())


Output:

Launching script '/Users/Johannes Radinger/Desktop/test2.py'...                 
(Mon Feb 13 15:08:07 2012)                                                      
/Users/Johannes Radinger/Desktop/test2.py                                       
start
----------------------------------------------
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
----------------------------------------------
1st g.list over
----------------------------------------------
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.
2nd g.list over
(Mon Feb 13 15:08:23 2012) Command finished (15 sec) 


Looks weird as "2nd g.list over" is printed after the ERROR, resp.
the ERROR is produced by v.to.rast before the print statement is processed...

I launch the script from within GRASS6.5SVN (Mac OSX) from File -> launch script. 

/johannes


> 
> 
> > Yes I am sure... That is the strange thing...I run g.remove (select
> > all raster maps available for user1)...I can even run g.list manually
> > before and there is no map... The maps are there as soon as I start
> > the script (and then found by the g.list)
> 
> Nothing in your script creates these maps except for v.to.rast and its 
> v.to.rast that complains about them existing...
> 
> Maybe by using several time.sleep() and g.list calls you can check 
> exactly when this happens.
> 
> Moritz
> _______________________________________________
> grass-user mailing list
> grass-user at lists.osgeo.org
> http://lists.osgeo.org/mailman/listinfo/grass-user

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