TransWikia.com

Error in overlay - formula not vectorized

Geographic Information Systems Asked by Bianca Wolf on November 26, 2020

I’ve run into another error while trying to get my predictive model to work. My base model is basically done (extracting locational parameters from archaeological sites in an area, and calculating a predictive map for archaeological risk areas, containing slope, tpi, tpi_15, aspect and distance to water), but it is not as accurate as I’d like it to be. So I’m trying to assign different weights to the parameters (e.g. distance to water is more important than aspect), and that’s where I’m stuck.

weights <- apply(X = sn_sf_bind, MARGIN = 2, FUN = function(x)
{sqrt(1/sd(x)*range(x)[2]-range(x)[1])})

sn_sf_bind is my table with the archaeological sites and assigned locational parameters, looks like this:

enter image description here

For this I don’t get an error, but I don’t know if it could be in there already.

The code that isn’t working is this:

wba <- overlay(x = ter_par_big,
               fun=function(w,x,y,z){
                 return((v*weights[1])+
                          (w*weights[2])+
                          (x*weights[3])+
                          (y*weights[4])+
                          (z*weights[5]))},
               unstack = TRUE)

I’ve also tried this:

fw <- function(v,w,x,y,z){
  return((v*weights[1])+
           (w*weights[2])+
           (x*weights[3])+
           (y*weights[4])+
           (z*weights[5]))}

wba <- overlay(x = ter_par_big,
               fun=Vectorize(fw),
               unstack = TRUE)

But it didn’t change anything, I’m still getting the same error:

Error in .overlayList(x, fun = fun, filename = filename, forcefun = forcefun,  : 
  cannot use this formula, probably because it is not vectorized

ter_par_big is my Raster Brick, consisting of 5 layers with the locational parameters for the overall area, it looks like this:

enter image description here
enter image description here

One Answer

Thanks to @Spacedman I could fix my problem by adding

#deleting geometry from sn_sf_bind sn_sf_bind2 <- st_drop_geometry(sn_sf_bind)

before running weights. This got rid of the geometrycolumn and resulted in sn_sf_bind2being a data.frame, which I could smoothly run through my code.

Answered by Bianca Wolf on November 26, 2020

Add your own answers!

Ask a Question

Get help from others!

© 2024 TransWikia.com. All rights reserved. Sites we Love: PCI Database, UKBizDB, Menu Kuliner, Sharing RPP