I have a problem with ArcObjects trying to convert a graphics container filled with segments into a polygon to insert into a feature class. In order to make the jump from a graphics element to a polygon, I believe I have to go from an element to a segment collection that can be inserted into a feature class.
My routine can insert the segments, but the feature class creates a polygon that is missing segments from the beginning or end of the object chain.
public void FinalizeObject(IFeatureLayer layer, IGraphicsContainer graphicsContainer)
ISegmentCollection segmentCollection = new PolygonClass() as ISegmentCollection;
IElement element = graphicsContainer.Next();
ISegmentCollection tmp = new PolygonClass();
while (element != null)
IGeometry geometry = element.Geometry;
ISegmentCollection tempClass = new PolygonClass() as ISegmentCollection;
tempClass = geometry as ISegmentCollection;
if (tempClass != null && tempClass.SegmentCount > 0)
for (int x = 0; x < tempClass.SegmentCount; x++)
ISegment segment = tempClass.Segment[x];
element = graphicsContainer.Next();
IFeatureClass featureClass = layer.FeatureClass;
IFeature feature = featureClass.CreateFeature();
feature.Shape = (IPolygon)segmentCollection;
catch (NullReferenceException nre)
I am breaking it down and piecing it back together because I don't know if there is a way to take the entirety of a graphics container as a single usable object, hence having to loop through the container and piecing it into a segment collection.
What am I missing? Thank you for any help.