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

Moritz Lennert mlennert at club.worldonline.be
Thu Feb 9 04:41:39 EST 2012


On 08/02/12 13:09, Johannes Radinger wrote:
> Hi,
>
>> On 8 February 2012 11:35, Johannes Radinger<JRadinger at gmx.at>  wrote:
>>> I try to run v.to.rast of a line in a loop
>>> to get a raster for each attribute of the vector (multiple columns).
>>> Therefore I created a short python script, which is working
>>> expept for that I am getting error messages:
>>> ERROR: option<output>:<raster_attribute>  exists.
>>>
>>> Here the code:
>>>
>>> #!/usr/bin/env python
>>>
>>> import sys
>>>
>>> import grass.script as grass
>>> import grass.script.setup as gsetup
>>>
>>> def main():
>>>
>>>     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())
>>
>> Have you tried adding flags = '-o' as an argument to
>> grass.run_command? That will overwrite the output raster if it already
>> exists.
>
> I haven't tried yet to use the overwrite option. It'll probably work. It is just that I am wondering why these rasters "exist" although all rasters are entirely removed from the mapset.
>
> Can you reproduce this behaviour with that script and the North Carolina dataset?

I tried in 6.4.2RC2 and in 6.5svn and it works like a charm. Obviously, 
if I try to run it a second time in the same mapset I get the output 
exists errors (i.e. I have to manually erase them).

Moritz



More information about the grass-user mailing list