* @param useLargestForMulti
* Set to true if you want to use only the largest feature for {@link MultiFeature}s.
* @return The location of the geometric center.
*/
public static Location getCentroid(Feature feature, boolean useLargestForMulti) {
Location location = null;
switch (feature.getType()) {
case POINT:
location = ((PointFeature) feature).getLocation();
break;
case LINES:
case POLYGON:
location = GeoUtils.getCentroid(((ShapeFeature) feature).getLocations());
break;
case MULTI:
MultiFeature multiFeature = ((MultiFeature) feature);
if (useLargestForMulti) {
// Return centroid of largest feature
Feature largestFeature = getLargestFeature(multiFeature);
location = getCentroid(largestFeature);
} else {
// Return centroid of all features
List<Location> locations = new ArrayList<Location>();
for (Feature f : multiFeature.getFeatures()) {
Location l = getCentroid(f);
locations.add(l);
}
location = GeoUtils.getCentroid(locations);
}
break;