I'm using the new velox extract function to speed up raster extraction by shapefiles.
The old raster package's extract function by default returned a list of cell values, for example when you use the below format:
val.list <- raster::extract(raster, shapefile)
The new velox package requires a fun= argument and I can't for the life of me get it to return the values:
vx.raster <- velox(raster)
vx.vals <- vx.raster$extract(shapefile, fun=??????)
I have tried:
fun=values (returns error Error during wrapup: unable to find an inherited method for function 'values' for signature 'numeric'
fun=function(x){values(x)} (same error as above)
I get fun=sum, fun=mean to work just fine. Whats up with values? Am I just missing something obvious about a numeric vector and returning a values list (which I feel is the most likely case)?
Thank you!
?extract: "fun: (…) The function should take a single numeric vector as argument and return a single value". From?value: "Value: vector or matrix of raster values". Could that be the issue? - AkselAfun=function(x){x}orfun=as.numeric? - Kristoffer Winther Ballingvelox_extract: github.com/cran/velox/blob/master/R/velox_extract.R It seems that the output is a dataframe with only one value for each polygon (p) and one value for each column of the polygon associated dataframe. The case for a list of values has apparently not been implemented here. - Sébastien Rochette