velox package point extraction failure

221 Views Asked by At

I am trying to work with the velox package in R 3.4.1, using the current (0.2.0) velox package version. I want to extract raster pixel values using the VeloxRaster_extract_points functionality and after failures with my own data, I ran the exact code provided on page 19 of the current reference manual. This returned the error shown (below). I have been unable to find any relevant references to this error online. Any suggestions? Thanks

> ## Make VeloxRaster with two bands
> set.seed(0)
> mat1 <- matrix(rnorm(100), 10, 10)
> mat2 <- matrix(rnorm(100), 10, 10)
> vx <- velox(list(mat1, mat2), extent=c(0,1,0,1), res=c(0.1,0.1),crs="+proj=longlat +datum=WGS84 +no_defs")
> ## Make SpatialPoints
> library(sp)
> library(rgeos)
> coord <- cbind(runif(10), runif(10))
> spoint <- SpatialPoints(coords=coord)
> ## Extract
> vx$extract_points(sp=spoint)
Error in envRefInferField(x, what, getClass(class(x)), selfEnv) : 
  ‘extract_points’ is not a valid field or method name for reference class “VeloxRaster”
1

There are 1 best solutions below

0
Mohamed Ismaiel Ahmed On

When trying, it worked fine for my case:

library('velox')
## Make VeloxRaster with two bands
set.seed(0)
mat1 <- matrix(rnorm(100), 10, 10)
mat2 <- matrix(rnorm(100), 10, 10)
vx <- velox(list(mat1, mat2), extent=c(0,1,0,1), res=c(0.1,0.1),
            crs="+proj=longlat +datum=WGS84 +no_defs")
## Make SpatialPoints
library(sp)
library(rgeos)
coord <- cbind(runif(10), runif(10))
spoint <- SpatialPoints(coords=coord)
## Extract
vx$extract_points(sp=spoint)
        [,1]       [,2]
 [1,] 0.76359346 -0.4125199
 [2,] 0.35872890  0.3178857
 [3,] 0.25222345 -1.1195991
 [4,] 0.00837096  2.0247614
 [5,] 0.77214219 -0.5922254
 [6,] 0.00837096  2.0247614
 [7,] 1.10096910  0.5989751
 [8,] 1.15191175 -0.9558391
 [9,] 0.14377148 -1.5236149
[10,] 1.27242932  0.0465803

I think you may need to reinstall the package.