Geographic Information Systems Stack Exchange is a question and answer site for cartographers, geographers and GIS professionals. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I need to compute the centroid position of an irregular polygon with lat and lon coordinates in Java. Which formula should I use to correctly compute a centroid?

share|improve this question
Are you looking for actual formulas or do you just need working code? – whuber Dec 9 '11 at 14:33

You could do a lot worse than use the JTS library for this, Look at for details. From the JavaDocs you can find the algorithm used at

share|improve this answer
whoops, cross post. Sorry – Stev_k Dec 9 '11 at 13:37

Have you looked at the Java Topology Suite ( If you're not worried about executable size, then this would seem to fit the bill with a minimum of additional code, and a fairly battle tested library. It's under LGPL licence, so hopefully that's suitable.

share|improve this answer
Ok thank you men, – adev Dec 9 '11 at 13:53
Ok thank you guys, but I would like to know what's the formula best fit the centroid coputing for geographics positioning. For example what's wrong if I use a simple mean like: lat = Sum(lat_1..lat_n)/n , lon=Sum(lon_1, lon_n)/n ? – adev Dec 9 '11 at 14:00
A very simple method for finding the centroid (centre of mass) for a Geometry is to find the average for the longitude and latitude, though if you require a point that is always inside the feature you'll have issues with concave features. In which case you'll need to look at label point algorithms. Label point algorithms are essentially a centroid algorithm with a shift of the resultant point into the bounds of the feature. – OptimizePrime Dec 12 '11 at 16:46

Your Answer


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.