/** * This will return the centroid of a given polygon. It can handle complex polygons including * multiple polygons. This will not necessarily return a location that is contained within the * original polygon. For example if you have two concentric circles forming a donut shape, one * smaller one contained within the bigger one. The centroid of that polygon will be at the * center technically outside of the polygon. This is a very different concept to a * representative point. * * @return a Location object that is the centroid of the polygon */ public Location center() { final Point point = JTS_POLYGON_CONVERTER.convert(this).getCentroid(); return new JtsLocationConverter().backwardConvert(point.getCoordinate()); }
/** * Returns a location that is the closest point within the polygon to the centroid. The function * delegates to the Geometry class which delegates to the InteriorPointPoint class. You can see * the javadocs in the link below. <a href= * "http://www.vividsolutions.com/jts/javadoc/com/vividsolutions/jts/algorithm/InteriorPointPoint"> * http://www.vividsolutions.com/jts/javadoc/com/vividsolutions/jts/algorithm/InteriorPointPoint * </a> .html * * @return location that is the closest point within the polygon to the centroid */ public Location interiorCenter() { final Point point = JTS_POLYGON_CONVERTER.convert(this).getInteriorPoint(); return new JtsLocationConverter().backwardConvert(point.getCoordinate()); }