[GRASS-stats] Load data multiple data from grass to R

Jarek Jasiewicz jarekj at amu.edu.pl
Thu Nov 22 03:00:49 EST 2007


Roger Bivand wrote:
> On Wed, 21 Nov 2007, Jarek Jasiewicz wrote:
>
>> I'd like to write R sript to read more rasters from grass to R and 
>> writeh them to objects with unique
>>
>> what I try to do:
>>
>> system("g.mlist type=rast pattern=a_* >tmp_file")
>> k=c(scan("temp_file, what="string")) //maybe is simpler way
>>
>> for (i in k) {
>> here_I_need_obect_with_unique_name=readRAST6(i, paste(i))
>> }
>> operations_on_obiects
>
> Could you use the fact that the first argument to readRAST6() can be a 
> character vector of raster layer names? If k is such a character 
> vector, you could try readRAST6(k). The second argument is a logical 
> vector, not vname= as you seem to think - that is in writeRAST6().
>
> Hope this helps,
>
> Roger
>
> obiect <-readRAST6(k)
well maybe presented problem not enough clear
First - there is en mistake in code i typed
shuoud be:

for (i in k) {
here_I_need_obect_with_unique_name=readRAST6(i)
}

but in that way I recive obiect which every iteration will be 
overwritten by nex raster map. At the end I will have obiect with last 
raster map in string vector

How to preserve obiect created in the loop and control its name?
I think about something like this (for example) in the loop ??

ob_a=readRAST6("a")
ob_b=readRAST6("b")
ob_c=readRAST6("c")
...
ob_z=readRAST6("z")

if I use this

obiect <-readRAST6(k)

there will be the problem with converting every layer (I mean: 
"obiect at data$raster_name" i SpGridDataFrame) in multilayer 
SpGridDataFrame to "im" class obiect

In general it is the problem how to control names of obiect if in the 
loop we need to create more than one obiect

Hope I presented it clear

greetings
Jarek


More information about the grass-stats mailing list