Hi,
I'm trying to loop over the features in a feature class and split each mulit-part polygon into single-part polygons. I don't want to use any geoprocessing tools. The problem is that the code below gives me each polygon part, but without the holes. I want to split the multi-part polygons but keep any polygon holes. Any ideas?
IFeatureClass inFc = // Input feature class
IFeatureClass outFc = // Ouput feature class
IFeature ftr;
IFeatureCursor cur = inFc.Search(null, true);
while ((ftr = cur.NextFeature()) != null)
{
// Get spatial reference from orginal feature
ISpatialReference spRef = ftr.ShapeCopy.SpatialReference;
object obj = Type.Missing;
IGeometryBag geomBag = ((IPolygon4)ftr.ShapeCopy).ExteriorRingBag;
IGeometryCollection coll = geomBag as IGeometryCollection;
for (int i = 0; i < coll.GeometryCount; i++)
{
IFeature newFtr = outFc.CreateFeature();
IGeometryCollection geomColl = new PolygonClass();
IGeometry geom = coll.get_Geometry(i);
geom.SpatialReference = spRef;
geomColl.AddGeometry(geom, ref obj, ref obj);
geomColl.GeometriesChanged();
IGeometry geom2 = (IPolygon)geomColl;
newFtr.Shape = geom2;
newFtr.Store();
}
}
Best regards,
Mikael