许可优化
许可优化
产品
产品
解决方案
解决方案
服务支持
服务支持
关于
关于
软件库
当前位置:服务支持 >  软件文章 >  单个要素制图表达的获取及修改方法

单个要素制图表达的获取及修改方法

阅读数 1
点赞 0
article_banner

1.获取制图表达


    /// <summary>        /// 获取图层中某个要素的制图表达        /// </summary>        /// <param name="pLyr">图层</param>        /// <param name="pActiveView">视图</param>        /// <param name="pFea">单个要素</param>        /// <returns></returns>        public static IRepresentation getRepresentation(ILayer pLyr, IActiveView pActiveView, IFeature pFea)        {            try            {                IMapContext pMapContext = new MapContextClass();                pMapContext.InitFromDisplay(pActiveView.ScreenDisplay.DisplayTransformation);                 IFeatureLayer pFeaLyr = pLyr as IFeatureLayer;                IRepresentationRenderer pRepRenderer = (pFeaLyr as IGeoFeatureLayer).Renderer as IRepresentationRenderer;                IRepresentation pRepresentation = pRepRenderer.RepresentationClass.GetRepresentation(pFea, pMapContext);                 return pRepresentation;            }            catch (Exception ex)            {                return null;            }        }


2.获取MapControl中指定名称的图层
 


  /// <summary>        /// 获取地图上要素类图层        /// </summary>        /// <param name="pMap"></param>        /// <param name="sUID"></param>        /// <param name="sLayerName"></param>        /// <returns></returns>        public static ILayer GetLayer(IMap pMap, string sLayerName)        {            ILayer pLyr = null;             UID uid = new UIDClass();            uid.Value = "{40A9E885-5533-11d0-98BE-00805F7CED21}";             IEnumLayer pEnumLayer = pMap.get_Layers(uid, true);            try            {                pEnumLayer.Reset();                ILayer pLayer = null;                while ((pLayer = pEnumLayer.Next()) != null)                {                    if (!pLayer.Visible)                    {                        continue;                    }                     if (!string.IsNullOrEmpty(sLayerName) && sLayerName == ((pLayer as IFeatureLayer).FeatureClass as IDataset).Name)                    {                        pLyr = pLayer;                    }                }                return pLyr;            }            catch (Exception ex)            {                return null;            }            finally            {                Marshal.ReleaseComObject(pEnumLayer);            }        }

   3.获取制图表达属性信息并进行更改的操作 
  



 private void UpdateRepColor(ILayer pLyr, string JBConde, List<ConvertMappingInfo> plistMappingInfo, ConvertToType convertToType)        {            IWorkspaceEdit2 pWsEdit = pWs as IWorkspaceEdit2;             try            {                IFeatureCursor pFeaCursor = (pLyr as IFeatureLayer).FeatureClass.Update(null, false);                IFeature pFea = null;                 //开启编辑会话                WorkspaceAPI.StartWorkspaceEdit(pWs);                pWsEdit.StartEditOperation();                while ((pFea = pFeaCursor.NextFeature()) != null)                {                    IRepresentation pRepresentation = CommonAPI.getRepresentation(pLyr, ArcMap.Document.ActivatedView, pFea);                    IRepresentationRule pRepRule = pRepresentation.RepresentationClass.RepresentationRules.get_Rule(pRepresentation.RuleID);                    string strRuleName = pRepresentation.RepresentationClass.RepresentationRules.get_Name(pRepresentation.RuleID);                     if (strRuleName != JBConde)                    {                        continue;                    }                     for (int i = 0; i < pRepRule.LayerCount; i++)                    {                        IBasicSymbol pBasicSymbol = pRepRule.get_Layer(i);                        IGraphicAttributes pGraphicAttributes = null;                        //IGeometry pRepGeometry = null;                        if (pBasicSymbol is IBasicMarkerSymbol)                        {                            IBasicMarkerSymbol pBasicMarkerSymbol = pBasicSymbol as IBasicMarkerSymbol;                            //pRepGeometry = pRepresentation.Shape;                            pGraphicAttributes = pBasicMarkerSymbol as IGraphicAttributes;                         }                        if (pBasicSymbol is IBasicLineSymbol)                        {                            IBasicLineSymbol pBasicLineSymbol = pBasicSymbol as IBasicLineSymbol;                            ILineStroke pLineStroke = pBasicLineSymbol.Stroke;                            //IDrawingOutline pDrawingOutline = pLineStroke as IDrawingOutline;                            //IGeometry geo = pDrawingOutline.GetAllOutlineParts(feature.Shape, esriOutlineType.esriOutlineExact, esriOutlineOption.esriOutlineConvex, 3.14, null);                             //pRepGeometry = pRepresentation.Shape;                            pGraphicAttributes = pLineStroke as IGraphicAttributes;                        }                        if (pBasicSymbol is IBasicFillSymbol)                        {                            IBasicFillSymbol pBasicFillSymbol = pBasicSymbol as IBasicFillSymbol;                            IFillPattern pFillPattern = pBasicFillSymbol.FillPattern;                            //pRepGeometry = pRepresentation.Shape;                            pGraphicAttributes = pFillPattern as IGraphicAttributes;                        }                        for (int N = 0; N < pGraphicAttributes.GraphicAttributeCount; N++)                        {                            int iId = pGraphicAttributes.get_ID(N);                            string name = pGraphicAttributes.get_Name(iId);                            IGraphicAttributeType pGraphicAttributeType = pGraphicAttributes.get_Type(iId);                            if (pGraphicAttributeType.Type == esriGraphicAttributeType.esriAttributeTypeColor)                            {                                IColor pColor = pRepresentation.get_Value(pGraphicAttributes, iId) as IColor;                                ICmykColor pCMYKColor = pColor as ICmykColor;                                if (pCMYKColor==null)                                {                                    continue;                                }                                if (convertToType == ConvertToType.ChuBan)                                {                                    ConvertMappingInfo pConvertInfo = new ConvertMappingInfo();                                    pConvertInfo.PC = pCMYKColor.Cyan;                                    pConvertInfo.PM = pCMYKColor.Magenta;                                    pConvertInfo.PY = pCMYKColor.Yellow;                                    pConvertInfo.PK = pCMYKColor.Black;                                     foreach (ConvertMappingInfo c in plistMappingInfo)                                    {                                        if (pConvertInfo.CompareColorValue(c, convertToType))                                        {                                            pCMYKColor.Cyan = c.CC;                                            pCMYKColor.Magenta = c.CM;                                            pCMYKColor.Yellow = c.CY;                                            pCMYKColor.Black = c.CK;                                             pRepresentation.set_Value(pGraphicAttributes, iId, pCMYKColor);                                        }                                    }                                }                                if (convertToType == ConvertToType.PenHui)                                {                                    ConvertMappingInfo pConvertInfo = new ConvertMappingInfo();                                    pConvertInfo.CC = pCMYKColor.Cyan;                                    pConvertInfo.CM = pCMYKColor.Magenta;                                    pConvertInfo.CY = pCMYKColor.Yellow;                                    pConvertInfo.CK = pCMYKColor.Black;                                     foreach (ConvertMappingInfo c in plistMappingInfo)                                    {                                        if (pConvertInfo.CompareColorValue(c, convertToType))                                        {                                            pCMYKColor.Cyan = c.PC;                                            pCMYKColor.Magenta = c.PM;                                            pCMYKColor.Yellow = c.PY;                                            pCMYKColor.Black = c.PK;                                        }                                    }                                }                            }                        }                    }                     pRepresentation.UpdateFeature();                    pFeaCursor.UpdateFeature(pFea);                     //关闭编辑会话                    pWsEdit.StopEditOperation();                    pWsEdit.StopEditing(true);                }            }            catch (Exception ex)            {                WorkspaceAPI.RollbackWorkspaceEdit(pWsEdit);            }            finally            {             }        }



免责声明:本文系网络转载或改编,未找到原创作者,版权归原作者所有。如涉及版权,请联系删


相关文章
技术文档
QR Code
微信扫一扫,欢迎咨询~
customer

online

联系我们
武汉格发信息技术有限公司
湖北省武汉市经开区科技园西路6号103孵化器
电话:155-2731-8020 座机:027-59821821
邮件:tanzw@gofarlic.com
Copyright © 2023 Gofarsoft Co.,Ltd. 保留所有权利
遇到许可问题?该如何解决!?
评估许可证实际采购量? 
不清楚软件许可证使用数据? 
收到软件厂商律师函!?  
想要少购买点许可证,节省费用? 
收到软件厂商侵权通告!?  
有正版license,但许可证不够用,需要新购? 
联系方式 board-phone 155-2731-8020
close1
预留信息,一起解决您的问题
* 姓名:
* 手机:

* 公司名称:

姓名不为空

姓名不为空

姓名不为空
手机不正确

手机不正确

手机不正确
公司不为空

公司不为空

公司不为空