Dear Ethienne, thanks a lot for your help.
We finally manage to perform the svm classification in this  way:

library(spgrass6) ; G <- gmeta6()

TL_training_2006_id.raw<-readRAST6("TL_training_2006_id") #  classes
training area 

B1_B2_B3_train.raw<-readRAST6(c("AST_L1B_2008_05_2009_area_giusta_1_training","AST_L1B_2008_05_2009_area_giusta_2_training","AST_L1B_2008_05_2009_area_giusta_3N_training"))
#bands training area 

B1_B2_B3_compl.raw<-readRAST6(c("AST_L1B_2008_05_2009_area_giusta_1","AST_L1B_2008_05_2009_area_giusta_2","AST_L1B_2008_05_2009_area_giusta_3N"))
#bands, complete data

#transform classes from numeric to factor
is.numeric(TL_training_2006_id.raw@data$TL_training_2006_id) #TRUE
class(TL_training_2006_id.raw@data$TL_training_2006_id) #numeric
TL_training_2006_id.raw@data$TL_training_2006_id <-
as.factor(TL_training_2006_id.raw@data$TL_training_2006_id)


# create NA mask using complete.cases()
TL_training_2006_id.na_mask <- complete.cases(TL_training_2006_id.raw@data)
B1_B2_B3_train.na_mask <-complete.cases(B1_B2_B3_train.raw@data)
B1_B2_B3_compl.na_mask <-complete.cases(B1_B2_B3_compl.raw@data)


# get values based on na_mask
TL_training_2006_id <-
TL_training_2006_id.raw@data[TL_training_2006_id.na_mask, ] 
B1_B2_B3_train <- B1_B2_B3_train.raw@data[B1_B2_B3_train.na_mask, ]
B1_B2_B3_compl <- B1_B2_B3_compl.raw@data[B1_B2_B3_compl.na_mask, ]


# create SVM model
library(e1071)
x <- B1_B2_B3_train
y <- TL_training_2006_id
model_ASTER <- svm(x,y)

#predict 
pred <- predict(model_ASTER, B1_B2_B3_compl.raw@data)
#same as:
pred <- predict(model_ASTER, B1_B2_B3_compl.raw@data[B1_B2_B3_compl.na_mask,
], locations=coordinates(utm_wgs84))

#now the issue is that the "pred" object is
 str(pred)
 Factor w/ 4 levels "2","3","4","5": 3 3 3 3 3 3 3 3 3 3 ...
 - attr(*, "names")= chr [1:920591] "24389" "24390" "24391" "25729" ...

that is, it contains the predicted(classified) values but it is not an S4
object SGDF

Do you have any advice on how to tranform it back in SGDF having the
coordinates(B1_B2_B3_compl.raw)?

Thankyou ! 

Giuseppe

--
View this message in context: 
http://r.789695.n4.nabble.com/svm-with-GRASS-GIS-tp4388006p4422281.html
Sent from the R help mailing list archive at Nabble.com.

______________________________________________
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.

Reply via email to