Skip to content
Prev 1010 / 29559 Next

[ESRI-L] outline polygons of point clumps

On Fri, 12 May 2006, Xiaohua Dai wrote:

            
A more specific follow-up after my reply directly to R-help.

I'm assuming you have a running R, and that convex hulls are what you 
want.

Take a random data set:

set.seed(1)
xy <- matrix(runif(500, 0, 10), ncol=2)
xy_clusts <- hclust(dist(xy), method="complete")
# complete linkage hierarchical clustering
plot(xy_clusts)
# shows the clustering tree
cl_10 <- cutree(xy_clusts, 10)
cl_20 <- cutree(xy_clusts, 20)
cl_30 <- cutree(xy_clusts, 30)
# cut the tree - the objects contain the memberships
which_cl_10 <- tapply(1:nrow(xy), cl_10, function(i) xy[i,])
chulls_cl_10 <- lapply(which_cl_10, function(x) x[chull(x),])
# construct convex hull polygons for each cluster
plot(xy)
res <- lapply(chulls_cl_10, polygon)
# and repeat for cl_20 and cl_30
which_cl_20 <- tapply(1:nrow(xy), cl_20, function(i) xy[i,])
chulls_cl_20 <- lapply(which_cl_20, function(x) x[chull(x),])
plot(xy)
res <- lapply(chulls_cl_20, polygon)
which_cl_30 <- tapply(1:nrow(xy), cl_30, function(i) xy[i,])
chulls_cl_30 <- lapply(which_cl_30, function(x) x[chull(x),])
plot(xy)
res <- lapply(chulls_cl_30, polygon)

If you need the list of convex hulls out as a shapefile, we can do that, 
if you need a raster, I'd suggest using kernel density with different 
bandwidths for a start, and NA out the densities below a chosen threshold.

Hope this helps,

Roger Bivand

PS. Use package maptools, function readShapePoints() to read your 
shapefile, and coordinates() of the input object to extract the 
coordinates. If need be, project from geographical coordinates using 
transform methods in package rgdal.