Geographic Information Systems Stack Exchange is a question and answer site for cartographers, geographers and GIS professionals. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

How do I convert a Map or FeatureLayer to graphics on ArcObjects 10.1?

Problem Solved

this is the working code:

    private void Convert_to_graphics( IMapDocument doc)

        IMap pmap;
        IFeature pFeature;
        IElement pElement = null;
        IMarkerElement pp = new MarkerElementClass();
        IGraphicsContainer pGraphicsContainer;
        IActiveView pActiveView;

        pmap = doc.get_Map(0);
        pActiveView = doc.ActiveView; 
        //pGraphicsContainer = doc.ActiveView.GraphicsContainer;

        int[] array = {8 , 7 , 6 , 5 , 1}; //layers indexes , 

        pGraphicsContainer = (IGraphicsContainer)pmap; 
        foreach (var i in array)

            IGeoFeatureLayer fl = (IGeoFeatureLayer)pmap.get_Layer(i);
            IFeatureClass fc = fl.FeatureClass;

            IFeatureCursor fcur =   fc.Search(null, false);

            IFeatureRenderer fr = fl.Renderer;

            pFeature = fcur.NextFeature()  ; 

            while (pFeature  != null)

                if (pFeature.Shape.GeometryType == ESRI.ArcGIS.Geometry.esriGeometryType.esriGeometryPoint)
                    IMarkerElement pmkElement = new MarkerElementClass();

                        ISymbol sym = fr.get_SymbolByFeature(pFeature);

                        pmkElement.Symbol = (IMarkerSymbol)sym;

                        pElement = (IElement)pmkElement;

                if (pFeature.Shape.GeometryType == ESRI.ArcGIS.Geometry.esriGeometryType.esriGeometryPolyline)
                    ILineElement pmkElement = new LineElementClass();
                    pmkElement.Symbol = (ILineSymbol)fr.get_SymbolByFeature(pFeature);
                    pElement = (IElement)pmkElement;
                if (pFeature.Shape.GeometryType == ESRI.ArcGIS.Geometry.esriGeometryType.esriGeometryPolygon)
                    IFillShapeElement pmkElement = new PolygonElementClass();
                    pmkElement.Symbol = (IFillSymbol)fr.get_SymbolByFeature(pFeature);
                    pElement = (IElement)pmkElement;

                if (pElement != null)
                    pElement.Geometry = pFeature.Shape;

                    pGraphicsContainer.AddElement(pElement, 0);

                pFeature = fcur.NextFeature();



share|improve this question
This is a very old question but I think it would still benefit from having the "answer in question" extracted out to be a true answer. Note that the question body left as a result would be too brief by today's GIS SE standards so maybe that could be expanded a little too. – PolyGeo Jul 26 '15 at 21:32
up vote 2 down vote accepted

Here's a Convert Features to Graphic Elements VBA code sample. I would modify it so that the element's symbol gets set to whatever is returned by IFeatureRenderer.SymbolByFeature. The interface used to set the symbol will depend on the underlying coclass (for PolygonElement use IFillShapeElement).

share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.