On 13/02/12 15:19, Johannes Radinger wrote:
-------- Original-Nachricht --------
Datum: Mon, 13 Feb 2012 13:18:58 +0100
Von: Moritz Lennert<[email protected]>
An: Johannes Radinger<[email protected]>
CC: [email protected], [email protected]
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<[email protected]> An: Johannes
Radinger<[email protected]> CC: [email protected],
[email protected] 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@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.
Ok, I can reproduce your error using File->Launch script. No idea where
that comes from, I'll try to look into it.
For the time being, just use g.remove or launch your script in the terminal.
Moritz
_______________________________________________
grass-user mailing list
[email protected]
http://lists.osgeo.org/mailman/listinfo/grass-user