[R-sig-Geo] Fuzzy k-means & raster
Andy Wilson
andy.a.wilson at gmail.com
Thu Mar 31 10:33:32 CEST 2011
Hi all,
I'm using an example (p213) in Hengl's A Practical Guide to Statistical
Mapping (an excellent book btw) as the basis to use fuzzy k-means for
the unsupervised extraction of landforms from land surface parameter
rasters. I've found that the classes are not reproducible. When I run
the same code on the same data 5 times I wont get the same clusters
every time - sometimes the same, but sometimes there will be different
numbers of cells attributed to each class. Is this to be expected from
fuzzy k-means or could this be a problem with my approach.
grids50m <- readGDAL("ELEV.asc")
LSP.list <- c("RELELEV.asc", "PROFILE.asc")
rsaga.sgrd.to.esri(in.sgrds=set.file.extension(LSP.list, ".sgrd"),
out.grids=LSP.list, prec=4, out.path=getwd())
for(i in 1:length(LSP.list)){
grids50m at data[strsplit(LSP.list[i], ".asc")[[1]]] <-
readGDAL(LSP.list[i])$band1
}
pc.dem <- prcomp( ~ RELELEV+PROFILE, scale=TRUE, grids50m at data)
demdata <- as.data.frame(pc.dem$x)
kmeans.dem5 <- kmeans(demdata,7)
grids50m$kmeans.dem5 <- kmeans.dem5$cluster
grids50m$landform5 <- as.factor(kmeans.dem5$cluster)
# Initiate a raster to load the cluster data into
r_class7 <- r_elev
# Extract the landform data into a vector
v_class7 <- as.numeric(grids50m$landform5)
# Load the landform data into the raster
r_class7 <- setValues(r_class5, v_class5)
Many thanks for your advice...
Andy Wilson
More information about the R-sig-Geo
mailing list