Take the 2-minute tour ×
Geographic Information Systems Stack Exchange is a question and answer site for cartographers, geographers and GIS professionals. It's 100% free, no registration required.

I want to convert a Map or FeatureLayer to graphics on Arcobjects 10.1, Any help or code examples

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();
            }




      }

            pActiveView.Refresh();


    }
share|improve this question
add comment

1 Answer 1

up vote 1 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
add comment

Your Answer

 
discard

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.