Take the 2-minute tour ×
Geographic Information Systems Stack Exchange is a question and answer site for cartographers, geographers and GIS professionals. It's 100% free, no registration required.

While searching the web, solutions for finding centroids of polygons come up rather often. What I'm interested in is finding a centroid of a cluster of points. A weighted mean of sorts. I would appreciate it if someone could provide some pointers, pseudo code (or even better, an R package that has already solved this) or links of how this issue can be tackled.

EDIT

Convergence has been afoot (again). iant has suggested a method to average coordinates and use that for the centroid. This is exactly what crossed my mind when I saw the right picture on this web page.

Here is some simple R code to draw the following figure that demonstrates this (× is the centroid):

xcor <- rchisq(10, 3, 2)
ycor <- runif(10, min = 1, max = 100)
mx <- mean(xcor)
my <- mean(ycor)

plot(xcor, ycor, pch = 1)
points(mx, my, pch = 3)

enter image description here

EDIT 2

cluster::pam()$medoids returns a medoid of a set of cluster. This is an example shamelessly stolen from @Joris Meys:

library(cluster)
df <- data.frame(X = rnorm(100, 0), Y = rpois(100, 2))
plot(df$X, df$Y)
points(pam(df, 1)$medoids, pch = 16, col = "red")
share|improve this question
1  
Is there a reason the mean center or center of minimum distance of the points won't suffice? –  Andy W Feb 10 '11 at 15:58
1  
@Roman: The graphic is incorrect: you need to use the mean, not the median. For 2D spatial point clouds there are analogs of a median center, but this is not one of them (because it is coordinate-dependent): see stats.stackexchange.com/q/1927/919 for a discussion. –  whuber Feb 10 '11 at 17:34
1  
I would also suggest checking out chapter 4 of the crimestat workbook, icpsr.umich.edu/CrimeStat/files/CrimeStatChapter.4.pdf. It is a pretty gentle intro, describes and graphically displays why the median for higher dimensions does not have a unique solution, and describes other measures of central tendency and variance of spatial point patterns. –  Andy W Feb 10 '11 at 17:53
    
This is getting more and more interesting. Thank you for your answers. I'm looking into the matter. –  Roman Luštrik Feb 10 '11 at 18:50
1  
"suggested a method to average coordinates and use that for the centroid." This is, in fact, the definition of the centroid, not simply something which makes a good approximation. –  Colin K Feb 10 '11 at 21:06
show 3 more comments

1 Answer

up vote 17 down vote accepted

just average the X and Y coordinates (multiply by a weight if you want) and there is your centroid.

share|improve this answer
2  
+1 Great solution. It extends to centroids on the spheroid, too (which is essential for avoiding projection-related distortions when the points are spread over a large portion of the globe): first convert (lat, lon) to 3D (x,y,z) (geocentric) coordinates, average them, then convert the result back to (lat, lon) (ignoring the almost inevitable fact that the 3D average will be deep below the surface). –  whuber Feb 10 '11 at 16:33
    
I've updated my question to reflect your answer. –  Roman Luštrik Feb 10 '11 at 16:51
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.