[GRASSLIST:184] Terrain classification R-->GRASS

Dylan Beaudette dylan.beaudette at gmail.com
Thu Mar 16 16:24:06 EST 2006


Hi Roger,

I have been following the directions in the lastest GRASS newsletter in 
regards to moving GRASS6 data to and  from R.

e.g. :
library(spgrass6)
gmeta6 <- gmeta6()

x <- readFLOAT6sp(c("er9","crosc","longc","slope_n","profc","minic","maxic"))

I have been attempting to reproduce your terrain classification example in a 
paper that you wrote some time ago [1]. I am having a difficult time 
understanding how the results from the clara() clustering results can be 
applied converted back into a raster and sent to GRASS.

here is what I have done so far:

#make a matrix of "observations"
morph <- data.frame(cbind(x$er9, x$crosc, x$longc, x$slope_n, x$profc, 
x$minic, x$maxic))

#assign names
names(morph) <- c("er9","crosc","longc","slope_n","profc","minic","maxic")

#perform the clustering
require(cluster)
morph.clara <- clara(morph, k=5, stand=T)

#print a summary
print(data.frame(morph.clara$clusinfo))
    size  max_diss  av_diss isolation
1 121180  9.087186 2.110414  2.964906
2  69129  6.820200 2.041174  2.835463
3  84236 13.193372 2.561544  3.556510
4  53631 16.692732 2.725165  6.939917
5  70032 10.193958 1.827320  4.085314

#combine clustered results into a matrix and send to GRASS:
#original raster was 544 rows by 732 cols:
morph.image <- matrix(morph.clara$clustering, nrow=544, ncol=732, byrow=T)

#look at the results:
image(morph.image)

#... it is rotated 90deg CCW !
(see attached)

In your paper [1] you mention that GRASS and R make different assumptions 
about the indexing of a matrix... however, I cannot quite figure out from 
your example how to rotate this matrix... or if I am even doing this 
correctly.

Any thoughts would be greatly appreciated. 

Thanks,




[1] Roger Bivand. Integrating GRASS 5.0 and R: GIS and modern statistics for 
data analysis. Internal Paper (?)

-- 
Dylan Beaudette
Soils and Biogeochemistry Graduate Group
University of California at Davis
530.754.7341
-------------- next part --------------
A non-text attachment was scrubbed...
Name: class.png
Type: image/png
Size: 22002 bytes
Desc: not available
Url : http://lists.osgeo.org/pipermail/grass-user/attachments/20060316/82937337/class.png


More information about the grass-user mailing list