[GRASS-stats] Load data multiple data from grass to R
Jarek Jasiewicz
jarekj at amu.edu.pl
Thu Nov 22 03:49:23 EST 2007
Roger Bivand wrote:
> On Thu, 22 Nov 2007, Jarek Jasiewicz wrote:
>
>> 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 ??
>
> What I suggested was putting all the rasters into the same object -
> their names become the column names of the object. Since the current
> region is respected, they will be conformal. If you want multiple
> objects, use assign() which takes a character string as the name if
> the object being assigned to, but watch the scoping if you are doing
> this in a function.
>
> Roger
>
>>
>> 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
>>
>>
>
that is solution!!
many thanks Roger!
Jarek
More information about the grass-stats
mailing list