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

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

(attachments)

class.png

On Thursday 16 March 2006 01:24 pm, Dylan Beaudette wrote:

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 (?)

Well here I go again, replying to myself!

Looks like the answers were right in front of me. It is possible to add some
data back into the original sp-object that was read in from GRASS!!

I have posted details here:
http://casoilresource.lawr.ucdavis.edu/drupal/node/221

Thanks go to those who contributed to the GRASS newletter no.3 regarding GRASS
and R.

Cheers,

--
Dylan Beaudette
Soils and Biogeochemistry Graduate Group
University of California at Davis
530.754.7341