R Point Clustering Tools Error

2633
4
04-10-2011 03:25 PM
GabriellaTurek
New Contributor
Hello,
I am trying to use the R Point Clustering Tools posted through the Resource Center here
http://resources.esri.com/geoprocessing/index.cfm?fa=codeGallery&page=2

I am working on a Windows machine, running ArcGIS 10.0, R 2.12.2, and Python 2.6.
When I try to run the R Point Cluster tool, I receive the error:

: Failed to execute. Parameters are not valid.
ERROR 000732: Input Dataset or Feature Class: Dataset XXXXX does not exist or is not supported
Failed to execute (DefineProjection).

The dataset is a shapefile and clearly exists.

Has anyone run into this problem?
Thanx
Gaby
0 Kudos
4 Replies
AngelaBlanco
New Contributor
Hello
I am having the same problem.
I have shapefile of points and it looks fine.

Thank.
Angela
0 Kudos
JeffreyEvans
Occasional Contributor III
Is your shapefile multipart? If so the spatial classes in R do not support multipart shapefiles at this time. If you get stuck, you can forgo using ArcGIS and directly use R for this analysis. Here is a example in R that runs an optimized K-medoid clustering. You can use readOGR in the rgdal library or readPointsShape in the maptools library to read shapefiles into a R spatial class. Your dataframe can be accessed using the @data slot notation.

require(cluster)
require(rgdal)
require(sp)

# READ SHAPEFILE (rgdal example)
shape <- readOGR(dsn="C:/ANALYSIS", layer="shape_points")

# OPTIMIZED K-MEDOIDS FUNCTION
OptK <- function(x, nk=10, plot=TRUE, cluster=TRUE, clara=FALSE, ...) {
if (!require(cluster)) stop("cluster PACKAGE MISSING")
asw <- numeric(nk)
  for (k in 2:nk) {  
    if(clara==TRUE) { asw <- clara(x, k, ...)$silinfo$avg.width }
    if(clara==FALSE) { asw <- pam(x, k, ...)$silinfo$avg.width }
      k.best <- which.max(asw)
     }
   print(paste("OPTIMAL-K", k.best, sep=": "))
  if(plot==TRUE) {      
    plot(1:nk, asw, type="s", main="Clustering Optimization using K-Mediods",
        xlab="K (number of clusters)", ylab = "mean silhouette width")
          axis(1, k.best, paste("best",k.best,sep="\n"), col="red",
               col.axis="red")
    }
  if(cluster==TRUE) {
    if(clara==TRUE) { return(clara(x, k.best, ...)) }
    if(clara==FALSE) { return(pam(x, k.best, ...)) }  
  }   
}
   
# CLUSTER DATA AND PLOT FIT
point.clust <- OptK(shape@data[,2:5], 20, plot=TRUE, cluster=TRUE, clara=TRUE, sample=500)
     plot(silhouette(point.clust), col = c("red", "green"), main="Cluster Silhouette's")
     plot(point.clust, which.plots=1, main="K-MEDIOD FIT")

# EXTRACT MEDIOD CLUSTER BREAKS
point.clust$medoids

# JOIN CLUSTERS TO DATA    
shape@data <- data.frame(shape@data, k=point.clust$clustering) 

# WRITE RESULTS SHAPEFILE (maptools example)
writePointsShape(shape, "C:/ANALYSIS/cluster_results")
0 Kudos
GabriellaTurek
New Contributor
I have solved this problem by commenting out one line of code. The updated script is attached (with comments)
0 Kudos
steliostsompanoglou
New Contributor
i replace the script but i cant see the output file

thanks
0 Kudos