kev84

How to add a new polygon to a new layer?

Discussion created by kev84 on Sep 30, 2010
Latest reply on Oct 27, 2010 by smilesars
hi guys,

I am about to start a project using ArcEngine 10. I'm just playing around with samples and snippets provided right now.

One of the things i'm trying to achieve is to let the user draw polygons on the map and add the polygon to an existing/newly created layer.

I followed this snippet

     ///<summary>Draws a polygon on the screen in the ActiveView where the mouse is clicked.</summary>
        ///
        ///<param name="activeView">An IActiveView interface</param>
        /// 
        ///<remarks>Ideally, this function would be called from within the OnMouseDown event that was created with the ArcGIS base tool template.</remarks>
        public void DrawPolygon(ESRI.ArcGIS.Carto.IActiveView activeView)
        {

            if (activeView == null)
            {
                return;
            }

            ESRI.ArcGIS.Display.IScreenDisplay screenDisplay = activeView.ScreenDisplay;

            // Constant
            screenDisplay.StartDrawing(screenDisplay.hDC, (System.Int16)ESRI.ArcGIS.Display.esriScreenCache.esriNoScreenCache); // Explicit Cast
            ESRI.ArcGIS.Display.IRgbColor rgbColor = new ESRI.ArcGIS.Display.RgbColorClass();
            rgbColor.Red = 255;

            ESRI.ArcGIS.Display.IColor color = rgbColor; // Implicit Cast
            ESRI.ArcGIS.Display.ISimpleFillSymbol simpleFillSymbol = new ESRI.ArcGIS.Display.SimpleFillSymbolClass();
            simpleFillSymbol.Color = color;

            ESRI.ArcGIS.Display.ISymbol symbol = simpleFillSymbol as ESRI.ArcGIS.Display.ISymbol; // Dynamic Cast
            ESRI.ArcGIS.Display.IRubberBand rubberBand = new ESRI.ArcGIS.Display.RubberPolygonClass();
            ESRI.ArcGIS.Geometry.IGeometry geometry = rubberBand.TrackNew(screenDisplay, symbol);
            screenDisplay.SetSymbol(symbol);
            screenDisplay.DrawPolygon(geometry);
            screenDisplay.FinishDrawing();
        }


I tried looking for classes that inherits from ILayer interface. However, I can't seem to find a class that allows me to CREATE a new layer and ADD an IGeometry object into it.

I guess I also want to be able to choose a Feature layer and add polygons into them. Is there a way I can programmatically create the feature layer and add a polygon to it? or do I have to choose the layer first then try to add the polygon to it?

Any help would be much appreciated.

Thanks and Regards,
Kev

Outcomes