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(); }
أكثر...
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(); }
أكثر...