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

本文介绍了如何在ArcGIS中获取图层要素的制图表达,并提供了更新制图表达属性的具体实现方法,包括颜色等属性的修改。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

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
            { 
            }
        }



评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值