[Qgis-user] Run R RandomForest classification Script using Sextante

geantsverts clardeux at yahoo.fr
Sun Feb 17 00:58:18 PST 2013


Thanks for your helpHere my sextante R script (I had remove original Cat
line)/##[RF_Classification]=group##shapefile=vector##attName=string
class##inImage=raster##numsamps=number 1000##outImage=output
rasterlibrary("maptools")library("sp")library("randomForest")library("raster")nd
=0vec =shapefilesatImage =inImagefor (b in 1:nlayers(satImage)) {
NAvalue(satImage at layers[[b]]) <- nd }allAtt <- slot(vec, "data")tabAtt
<-table(allAtt[[attName]])uniqueAtt <-as.numeric(names(tabAtt))for (x in
1:length(uniqueAtt)) {  class_data<- vec[vec[[attName]]==uniqueAtt[x],] 
areas <- sapply(slot(class_data, "polygons"), slot, "area")  nsamps <-
ceiling(numsamps*(areas/sum(areas)))  for (i in 1:dim(class_data)[1]) {   
xy_class <- spsample(class_data[i,], type="random", n=nsamps[i])    if (i ==
1) cpts <- xy_class    else cpts <- rbind(cpts, xy_class)  }classpts <- cpts 
if (x == 1) {    xy_allClasses<- classpts  } else {    xy_allClasses<-
rbind(xy_allClasses, classpts)  }} temp <- overlay(vec,
xy_allClasses)response <- temp[[attName]]trainvals <- cbind(response,
extract(satImage, xy_allClasses))randfor <- randomForest(as.factor(response)
~., data=trainvals, importance=TRUE,
na.action=na.omit)varImpPlot(randfor)predict(satImage, randfor,
filename=outImage, progress='text', format='GTiff', datatype='INT1U',
type='response', overwrite=TRUE)/Thanks again !



--
View this message in context: http://osgeo-org.1560.n6.nabble.com/Run-R-RandomForest-classification-Script-using-Sextante-tp5034709p5034740.html
Sent from the Quantum GIS - User mailing list archive at Nabble.com.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.osgeo.org/pipermail/qgis-user/attachments/20130217/de9c8837/attachment.html>


More information about the Qgis-user mailing list