*/
Coordinate geometryCentroid(Geometry g) {
// TODO: should the collection case return the centroid of the
// multi point?
if (g instanceof GeometryCollection) {
GeometryCollection gc = (GeometryCollection) g;
// check for case of single geometry
if (gc.getNumGeometries() == 1) {
g = gc.getGeometryN(0);
} else {
double maxAreaSoFar = gc.getGeometryN(0).getArea();
Coordinate centroidToReturn =
gc.getGeometryN(0).getCentroid().getCoordinate();
for (int t = 0; t < gc.getNumGeometries(); t++) {
double area = gc.getGeometryN(t).getArea();
if (area > maxAreaSoFar) {
maxAreaSoFar = area;
centroidToReturn =
gc.getGeometryN(t).getCentroid().getCoordinate();
}
}
return centroidToReturn;
}