[R-sig-Geo] subsetting a SpatialGridDataFrame image.SpatialGridDataFrame

Patrick Giraudoux patrick.giraudoux at univ-fcomte.fr
Fri Aug 13 15:33:16 CEST 2010


  Thank you both, that is very clear now. SpatialPixelsDataFrame objects 
can be "indexed" as a data frame, but not SpatialGridDataFrame where 
row, col, band must be specified (thanks also not to have written, 
please read the doc, which was all what I deserved..)

Actually, my question was simplified  with regard to what I intend to 
do: to display pixels selected on their value. With the meuse example 
and after your explanations, this gives:

data(meuse.grid)
coordinates(meuse.grid)<-~x+y
gridded(meuse.grid)<-TRUE
names(meuse.grid at data)

idx<-meuse.grid at data$dist<0.1
image(meuse.grid[idx,],useRasterImage=F)

... and it works well.

Well, looks like if a similar selection was quite hard to achieve 
straightfully  with a SpatialGridDataFrame, as long as each row and col 
number should be identified according to the criterion (eg 
meuse.grid at data$dist<0.1). Then I suppose that the simplest way is to 
coerce SpatialGridDataFrame to SpatialPixelsDataFrame. Agreed ?

Patrick



Le 13/08/2010 14:31, Roger Bivand a écrit :
> On Fri, 13 Aug 2010, Patrick Giraudoux wrote:
>
>>
>> Hi,
>>
>> I am trying to subset a SpatialGridDataFrame object as following:
>>
>> idx<-ChinaTempUTM47 at data[,1]>10 # select elements of column1  whose 
>> values are > 10
>> idx[is.na(idx)]<-FALSE # make a vector of class "logical" (replacing 
>> NA by FALSE)
>>
>> and this gives:
>>
>> ChinaTempUTM47[idx,]
>> Error in ChinaTempUTM47[idx, ] : (subscript) logical subscript too long
>>
>> However,
>>
>>> length(idx)
>> [1] 13536
>>> nrow(ChinaTempUTM47 at data)
>> [1] 13536
>>
>
> This was discussed in:
>
> https://stat.ethz.ch/pipermail/r-sig-geo/2010-August/008973.html
>
> Use one of the solutions suggested there, and note that the "[" method 
> for SpatialGridDataFrame takes [ row, col, band, ...], like an array 
> but not like a data.frame; see ?"SpatialGridDataFrame-class". You 
> could also coerce to SpatialPixelsDataFrame, which then behaves like a 
> data.frame, not an array.
>
> Hope this helps,
>
> Roger
>
>>
>> So, I canot sort out what happens.
>>
>> Any hint welcome
>>
>> Patrick
>>
>> _______________________________________________
>> R-sig-Geo mailing list
>> R-sig-Geo at stat.math.ethz.ch
>> https://stat.ethz.ch/mailman/listinfo/r-sig-geo
>>
>



More information about the R-sig-Geo mailing list