Benjamin,
This is a bug I recently introduced (my efforts to speed things up have
these nasty side effects; sorry about that).
I fixed it yesterday, and the fixed version, 1.9-44, is on CRAN now (for
linux, other OSes will follow shortly).
Thanks, Robert

On Fri, Nov 18, 2011 at 9:19 AM, Benjamin Mack <bmack@uni-bonn.de> wrote:

> Hello all,
> I'm getting crazy with a really basic problem but can't figure out what I
> am doing wrong. I found a way (see below) to solve the problem but it is
> everything but not elegant.
> I have an raster img with 72 layers which I read from an envi file.
>
> > img <- stack(fname)
>
> Now I want to extract some pixel values using an SpatialPointsDataFrame
> img_vals <- extract(img, ref)
> The problem is, that the output tells my that the values in the 72 bands
> are all equal - which is not true!
>
> > img_vals
>  [1,]         0.034341563           0.034341563 ...
>  [2,]         0.014481238           0.014481238 ...
>  [...,]
>
> To show you the strange behaviour look at the following.
>
> Trying to do the following (which I suppose to be somehow equal than using
> extract but with the pixel row/col -locations) I get the same problem
> (equal values in all bands):
>
> >img[1,1]
> [1,]         0.008778242           0.008778242  ...
>
> BUT when I do it in a different way I get the truth (controlled in ENVI)
> with differnet values in each layer.
>
> > getValues(img@layers[[1]])[1]
> [1] 0.008778242
> > getValues(img@layers[[2]])[1]
> [1] 0.006187854
> > getValues(img@layers[[3]])[1]
> [1] 0.01333527
>
> Has anybody an idea what is wrong here and how I have to use the extract
> command correctly? Any suggestions are highly appreciated!
>
> Thanks in advance!
>
> ------------------------------**---------------------
> My (ugly) workaround:
>
> img <- stack(fname)
> ci <- rasterize(ref,img,'ID')
> ind_sampling <- which(is.na(getValues(ci))==F)
>
> vals <- c()
> for (ii in 1:dim(img)[3]) {
>  vals <- rbind(vals, getValues(img@layers[[ii]])[**ind_sampling]) }
>
> ______________________________**_________________
> R-sig-Geo mailing list
> R-sig-Geo@r-project.org
> https://stat.ethz.ch/mailman/**listinfo/r-sig-geo<https://stat.ethz.ch/mailman/listinfo/r-sig-geo>
>

	[[alternative HTML version deleted]]

