PhilipMostert / PointedSDMs

Wrapper function for 'inlabru' for modeling species distribution models from disparate datasets.
23 stars 2 forks source link

Spatial Predictions error - "SpatialPoints" and "crs" #3

Closed BrentPease1 closed 1 year ago

BrentPease1 commented 1 year ago

I have been working through the vignettes with my personal data and everything has been going well up until I attempted to predict from my fieldsModel. I get the following error: Error in (function (classes, fdef, mtable) : unable to find an inherited method for function ‘proj4string<-’ for signature ‘"SpatialPoints", "crs"’

I have cross-checked object structure with those provided in the vignettes and everything seems to be similar. Without having a reprex in hand, is there any direction you can point me in to solve this? I can package everything up and send over, if needed.

PhilipMostert commented 1 year ago

Hi Brent, do you mind please sending me the data you are working with? I could try to have a look at it then.

BrentPease1 commented 1 year ago

Hello,

Data, sample script, and session info attached. Thanks! prediction_issue.zip

PhilipMostert commented 1 year ago

Hi, I think this is more of an sp issue, but the code seems to work if you change the crs of the mesh before running the predictions, like so:

box_mesh$crs <- sp_crs

spatial_predictions <- predict(fieldsModel, 
                               mesh = box_mesh,
                               mask = pred_box,
                               spatial = TRUE,
                               fun = 'linear')