I have a problem with performing RF in R for a WorldView-2 Scene. I've never ever before used R for remote sensing classification, so I simply followed what is written here. I've loaded scene (8-band TIFF) with raster::brick and called it abcd, loaded simple 4-point, 2-class shapefile with OGR, run randomForest model and called it wv2rf and tried to use predict:
predict(abcd, wv2rf, "rftes.img", index=1, na.rm=TRUE)
R returned an error, that I cannot handle with:
Error in `[.data.frame`(blockvals, , f[j]) : undefined columns selected
I guessed that it has to do something with index value, but I tried to change it and nothing worked
#loading data abcd <- brick("13AUG20094646-M2AS-13EUSI-1283-01.tif") sdata <- readOGR(dsn="mypath\\poligony testowe", layer="training") v <- extract(x=abcd, y=sdata, df=TRUE) sdata@data = data.frame(sdata@data, v[match(rownames(sdata@data), rownames(v)),] sdata@data <- NULL #classification wv2rf <- randomForest(x=sdata@data, y=(sdata@data[,"klasa"]), ntree=10, importance=TRUE) predict(abcd, wv2rf, "rftes.img", index=1, na.rm=TRUE)
Here are files with my sdata, wv2rf and abcd variables, should work with load("filename") in R. Hope they help you help me.