[R-sig-Geo] xyValues, S4 methods and the dreaded NA

Robert J. Hijmans r.hijmans at gmail.com
Mon Jul 5 21:07:39 CEST 2010


Roman,

xyValues (raster package) with a buffer argument, returned NA if the
both of the extreme NS or extreme EW points of the buffer where
outside the raster. This was correct for points outside the raster
with a small buffer, but not for points inside the raster with a very
large buffer (larger than the raster itself). I have fixed this, I
think, in version: 1.2-10 (5-July-2010). Should be available from
R-Forge in 24 hours.

You could have debugged this function by making .xyvBuf visible. E.g. like this:
.xyvBuf <- raster:::.xyvBuf
# and you also need to do this one, because it is inside  .xyvBuf
.couldBeLonLat <- raster:::.couldBeLonLat

Robert

On Mon, Jul 5, 2010 at 1:58 AM, Roman Luštrik <roman.lustrik at gmail.com> wrote:
> Dear List,
>
> I have a list of xy coordinates
>
>> origin.point
> [[1]]
>           x         y
> 196 35.65648  4.268407
> 267 26.97161 -0.921370
>
> [[2]]
>            x         y
> 2396 25.82682 -34.30095
> 2485 24.36276 -31.83600
> ...
>
> and I'm tryig to extract raster cell values within the radius like so:
>
> cell.num <- unlist(xyValues(object = rst, xy = origin.point, buffer = 50))
>
> For most coordinates, I get a list of vectors as expected, however, some
> fail and produce only (one) NA. The raster serving as object is always the
> same. For instance, in the list mentioned above, only coordinate 2 (
> xy[[1]][2,]) in list 1 is causing such problems. I have tried rounding the
> coordinates to no avail. Unfortunately I'm unable to reproduce the same
> behavior outside my function. If I do it manually like so
>
> cell.num1 <- unlist(xyValues(object = rst, xy = matrix(c(35.656483,
> 4.268407), nrow = 1, ncol = 2), buffer = 50)) #first coordinate
>
> cell.num2 <- unlist(xyValues(object = rst, xy = matrix(c(26.97161,
> -0.92137), nrow = 1, ncol = 2), buffer = 50)) #second coordinate
>
> things go through without a problem.
>
> This leads me to believe there is something in or around my custom function.
> What is confusing me is the unpredictable behavior which makes it harder for
> me to pinpoint the source where everything breaks. I tried following the
> xyValues() but debugging S4 methods is not something I'm versed at (yet?!).
> I have tried extracting xyValues() with
>
> selectMethod(xyValues, c('RasterLayer', 'matrix'))
>
> but the function calls even more internal functions and here is where I get
> stuck.
>
> I guess my questions are: what could be causing xyValues() to produce NA for
> particular coordinates (but working fine with others) and - how to debug
> xyValues() and it's internals like .xyvBuf, .readCells...? I would really
> like to get to the bottom of this and move on.
>
> Cheers,
> Roman
>
>
>
> --
> In God we trust, all others bring data.
>
>        [[alternative HTML version deleted]]
>
> _______________________________________________
> 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