* Execute the operation! When the geometry is not a Polygon, null is returned. When the polygon does not have any
* interior rings, null is returned.
*/
public Geometry execute(Geometry geometry) {
if (geometry instanceof Polygon) {
Polygon polygon = (Polygon) geometry;
// No rings? return null:
if (polygon.getNumInteriorRing() == 0) {
return null;
}
// Correct the index if necessary:
if (ringIndex < 0) {
ringIndex = 0;
} else if (ringIndex >= polygon.getNumInteriorRing()) {
ringIndex = polygon.getNumInteriorRing() - 1;
}
// Create the new array of interior rings:
LinearRing[] interiorRings = new LinearRing[polygon.getNumInteriorRing() - 1];
int count = 0;
for (int n = 0; n < polygon.getNumInteriorRing(); n++) {
if (n != ringIndex) {
interiorRings[count++] = polygon.getInteriorRingN(n);
}
}
return geometry.getGeometryFactory().createPolygon(polygon.getExteriorRing(), interiorRings);
}
return null;
}