# How to programmatically remove a donut hole from Polygon in arcobjects

I have a polygon `IPolygon4` with a hole in it, as you can see. How can I get rid of the donut hole, and have the whole thing be one simple polygon with 5 vertices.

Here are the constructed WKT points, I projected to GCS_WGS_1984 so it would be more readable.

MULTIPOLYGON (((-93.948870475981934 46.388792874272333, -94.07064721379696 46.3298500944495, -94.292075670722767 46.511771884217374, -94.285856486919386 46.334338634913607, -94.043790864983947 46.2678965446348, -93.96530675201366 46.327504695188082, -93.948870475981934 46.388792874272333)), ((-93.948870475981934 46.388792874272333, -93.914198248635017 46.517621156043539, -94.292075670722767 46.511771884217374, -93.948870475981934 46.388792874272333)))

• That's not really a donut hole, it's a non-simple polygon. If you simplify it, I suspect that "hole" will go away. Aug 9, 2013 at 22:42
• @blah238 I called simplify on it, and that didn't fix it. Aug 9, 2013 at 23:00
• Could you post its WKT? Aug 9, 2013 at 23:11
• @blah238 I posted the points. Aug 12, 2013 at 18:30
• Have you seen this post, forums.esri.com/Thread.asp?c=93&f=992&t=131776? Aug 13, 2013 at 2:28

Given that the polygon is simple, and the hole is an interior ring, you can create a new polygon using the `IPolygon4.ExteriorRingBag` property, and replace the current geometry with the exterior ring (or rings in case of `MultiPolygon`).

Otherwise, if the polygon is a "spaghetti-polygon", where the holes is caused by exterior ring is messed up (no interior ring), you probably have to do a manual edit (e.g. using sketch properties).

EDIT: (After you updated your question with WKT) The problem is that the geometry is NOT a donut polygon, it is a multipolygon. Therefore, you get two exterior rings in ExteriorRingBag instead of one. If the user wants to construct a polygon with a hole in ArcGis, the "Cut Polygon" tool must be used.

Here is a screenshot showing both polygon rings in your geometry:

Assuming that you are using ArcGis, here is the way to construct a donut properly: http://help.arcgis.com/en/arcgisdesktop/10.0/help/index.html#//001t0000003q000000.htm

• ExteriorRingBag gives me a top polygon and a bottom polygon. I can't do it manually because the use case is that the user will construct the polygon. Aug 12, 2013 at 18:32
• Your WKT shows the problem, see updated answer. Aug 13, 2013 at 7:58
``````    IPolygon ppolygon = pFeature.ShapeCopy as IPolygon;
IGeometryCollection pgeomColl = ppolygon as IGeometryCollection;
int x = pgeomColl.GeometryCount;
for (int i = 0; i < x; i++)
{
IGeometry pNewGeom = pgeomColl.get_Geometry(i);
IFeatureBuffer featureBuffer = pFeatureClass.CreateFeatureBuffer();
for (int k = 0; k <= pFeatureClass.Fields.FieldCount - 1; k++)
{
if (pFeatureClass.Fields.get_Field(k).Editable &&   pFeatureClass.Fields.get_Field(k).Type != esriFieldType.esriFieldTypeGeometry)
{
featureBuffer.set_Value(k, pFeature.get_Value(k));
}
}

IGeometryCollection icollection = null;
if (pFeature.Shape.GeometryType == esriGeometryType.esriGeometryPolyline)
icollection = new PolylineClass();
else if (pFeature.Shape.GeometryType == esriGeometryType.esriGeometryPolygon)
icollection = new PolygonClass();

IGeometry pgeomNew = (IGeometry)icollection;
IZAware pZ1 = pFeature.Shape as IZAware;
if (pZ1.ZAware)
{
pZ1 = pgeomNew as IZAware;
pZ1.ZAware = true;
}
else
{
pZ1 = pgeomNew as IZAware;
pZ1.ZAware = false;
}
featureBuffer.Shape = pgeomNew;
insertFeatureCursor.InsertFeature(featureBuffer);
marshal_object(featureBuffer);
marshal_object(pgeomNew);
marshal_object(pNewGeom);
marshal_object(icollection);
insertFeatureCursor.Flush();
}
pFeature.Delete();
marshal_object(ppolygon);
``````
• I think this Answer could do with you using the edit button to apply more formatting and also some descriptive text about how your code answers the Question.
– PolyGeo
Dec 12, 2013 at 7:36