[R-sig-Geo] Error: NA/NaN/Inf in foreign function call (arg 7) while using Predict function with Raster

aniruddha ghosh aniru123 at gmail.com
Wed Oct 3 16:23:15 CEST 2012


Dear List,
I'm trying to classify a multiband raster with point shapefiles as
training data. I used the following:
vec<-readOGR(".","training")
raster<-stack("test.tif")   #it contains around 100000 pixels and 240 layers
outImage<-"classified.tif"
#then extract the training values
train<-extract(raster,vec)
#after that used "caret" package to train the model
rfFit <- train(as.data.frame(train),as.factor(vec$class),
 method = "rf", tuneLength = 5,
 trControl = trainControl(method = "repeatedcv",
 repeats = 5,
 verboseIter = FALSE),
 metric = "Kappa")
# then to classify the entire data
rfPred <- predict(raster,rfFit, filename=outImage,na.rm=TRUE,
progress='text', format='GTiff', datatype='INT1U', overwrite=TRUE)

after some progress (more than 20 %) I'm getting this error:
"NA/NaN/Inf in foreign function call (arg 7)"

I have checked the code for small test image (around 10000 pixels with
125 layers) and it worked fine. I suspect it is due to the "-Inf"
present in the large raster. How to deal with this?

Thanks,
-- 
Ani



More information about the R-sig-Geo mailing list