[GRASS-user] Grass to R and back again (randomForest classification)

Daniel Victoria daniel.victoria at gmail.com
Fri Jun 11 08:12:41 EDT 2010


Hi list,

I'm trying to do a randomForest classification in a MODIS NDVI time
series. So far I've been able to generate the randomForest and get the
Grass NDVI images inside grass as a SpatialGridDataFrame. Then,
following some notes from Markus Neteler [1], I converted the
SpatialGridDataFrame to a DataFrame and sucessfully applied the
randomForest classifier. The problem is that now I'm struglling to
transform the DataFrame back to a grass image. What is giving me a
headach is that the images contains lots of null values (I need to
have a MASK in place) so, each NDVI image has 1023701 cells but the
DataFrame has only 264647 values since the conversion from SpatialGrid
to DataFrame skips the nulls.

So, the question is, how to convert my DataFrame back to a Grass image?

Cheers
Daniel

[1] http://mpa.fbk.eu/markus/shortcourse/notes7.html

PS - For completion sake...
Using Grass 6.4.0RC6 in Ubuntu 9.10
R 2.11

commands used in R:

# open images
ndvi <- readRAST6(<list of 23 ndvi images>)

# convert to dataframe
ndvi.df <- as.data.frame(ndvi)

class <- predict(RFmodel, ndvi.df)

# class contains 264647 classified pixels - how to get them back to an image?


More information about the grass-user mailing list