Skip to main content
Bumped by Community user
Bumped by Community user
deleted 23 characters in body
Source Link
PolyGeo
  • 65.4k
  • 29
  • 114
  • 345

What am I missing? Thank you in adavance.

What am I missing? Thank you in adavance.

What am I missing?

Source Link
user66338
user66338

Converting from GraphicsContainer to Polygon Feature

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 a 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.

This is code I have worked up so far:

public void FinalizeObject(IFeatureLayer layer, IGraphicsContainer graphicsContainer)
    {
        ISegmentCollection segmentCollection = new PolygonClass() as ISegmentCollection;
        IPolygon polygon = new PolygonClass();

        try
        {
            graphicsContainer.Reset();
            IElement element = graphicsContainer.Next();

            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];
                        segmentCollection.AddSegment(segment);
                        segmentCollection.SegmentsChanged();
                    }
                }
                element = graphicsContainer.Next();
            }

            IFeatureClass featureClass = layer.FeatureClass;
            IFeature feature = featureClass.CreateFeature();
            feature.Shape = (IPolygon)segmentCollection;
        }
        catch (NullReferenceException nre)
        {
            MessageBox.Show(nre.ToString());
        }
    }

What am I missing? Thank you in adavance.