ArcEngine 专题图关键代码

该博客详细介绍了如何使用ArcEngine进行唯一值专题图的制作。通过获取图层上的要素,定义唯一值渲染器,设置渲染字段,创建并应用填充符号,以及对字段值进行排序和颜色分配,最终实现图层的渲染更新。

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

一、类别

唯一值:

/// <summary>
        /// 应用唯一值渲染面要素层
        /// </summary>
        /// <param name="pGeoFeaturelayer"></param>
        private void ApplyUniqueValueRenderer2Polygon(IGeoFeatureLayer pGeoFeatureLayer)
        {
            IFeatureLayer pFeatureLayer = pGeoFeatureLayer as IFeatureLayer;


            //获取图层上的feature
            IFeatureClass pFeatureClass = pFeatureLayer.FeatureClass;


            IFeatureCursor pFeatureCursor = pFeatureClass.Search(null, false);


            //定义单值图渲染组件    
            IUniqueValueRenderer pUniqueValueRenderer = new UniqueValueRendererClass();


            sRendererField = lbResultYearField.Items[0].ToString();
            int fieldIndex = pFeatureClass.Fields.FindFieldByAliasName(sRendererField);
            IField pField = pFeatureClass.Fields.get_Field(fieldIndex);


            //设置渲染字段对象         
            pUniqueValueRenderer.FieldCount = 1;
            pUniqueValueRenderer.set_Field(0, pField.Name);


            //创建填充符号
            ISimpleFillSymbol PFillSymbol = new SimpleFillSymbolClass();
            pUniqueValueRenderer.DefaultSymbol = (ISymbol)PFillSymbol;
            pUniqueValueRenderer.UseDefaultSymbol = false;


            //QI the table from the geoFeatureLayer and get the field number of
            //ITable pTable;
            //int fieldNumber;
            //pTable = pGeoFeatureLayer as ITable;
            //fieldNumber = pTable.FindField("ID");
            //if (fieldNumber == -1)
            //{
            //    MessageBox.Show("Can't find field called ", "Message", MessageBoxButtons.OK, MessageBoxIcon.Information);
            //}


            //为每个值设置一个符号
            //int n = pFeatureClass.FeatureCount(null);
            //for (int i = 0; i < n; i++)
            //{
            //    IFeature pFeature = pFeatureCursor.NextFeature();
            //    IClone pSourceClone = PFillSymbol as IClone;
            //    ISimpleFillSymbol pSimpleFillSymbol = pSourceClone.Clone() as ISimpleFillSymbol;
            //    //string sFeatureValue = pFeature.get_Value(pFeature.Fields.FindField("ID")).ToString();
            //    string sFeatureValue = pFeature.get_Value(fieldIndex).ToString();
            //    pUniqueValueRenderer.AddValue(sFeatureValue, pField.AliasName, (ISymbol)pSimpleFillSymbol);
            //}


            //字段值排序(升序)
            ITable pTable = pFeatureClass as ITable;
            ITableSort pTableSort = new TableSortClass();
            IQueryFilter pQueryFilter = new QueryFilterClass();
            pQueryFilter.WhereClause = "";
            pTableSort.Table = pTable;
            pTableSort.QueryFilter = pQueryFilter;
            pTableSort.Fields = pField.Name;
            //pTableSort.set_SortCharacters(pField.Name);
            pTableSort.set_Ascending(pField.Name, true);
            pTableSort.Sort(null);


            //为每个值设置一个符号
            ICursor pCursor = pTableSort.Rows;
            IRow pRow = pCursor.NextRow();
            while (pRow != null)
            {
                IClone pSourceClone = PFillSymbol as IClone;
                ISimpleFillSymbol pSimpleFillSymbol = pSourceClone.Clone() as ISimpleFillSymbol;
                string sFeatureValue = pRow.get_Value(fieldIndex).ToString();
                pUniqueValueRenderer.AddValue(sFeatureValue, pField.AliasName, (ISymbol)pSimpleFillSymbol);
                pRow = pCursor.NextRow();
            }


            //创建并设置随机色谱
            //IRandomColorRamp pColorRamp = new RandomColorRampClass();
            //pColorRamp.StartHue = 0;
            //pColorRamp.MinValue = 99;
            //pColorRamp.MinSaturation = 15;
            //pColorRamp.EndHue = 360;
            //pColorRamp.MaxValue = 100;
            //pColorRamp.MaxSaturation = 30;
            //pColorRamp.Size = 100;


            //Get the color ramp
            IColorRamp pColorRamp = (IColorRamp)_pStyleGalleryItem.Item;
            pColorRamp.Size = pUniqueValueRenderer.ValueCount;
            bool ok = true;
            pColorRamp.CreateRamp(out ok);
            IEnumColors pEnumRamp;
            pEnumRamp = pColorRamp.Colors;


            //为每个符号设置颜色
            for (int i = 0; i <= pUniqueValueRenderer.ValueCount - 1; i++)
            {
                string xv = pUniqueValueRenderer.get_Value(i);
                if (xv != "")
                {
                    ISimpleFillSymbol pNextSymbol = (ISimpleFillSymbol)pUniqueValueRenderer.get_Symbol(xv);
                    pNextSymbol.Color = pEnumRamp.Next();
                    pUniqueValueRenderer.set_Symbol(xv, (ISymbol)pNextSymbol);
                }
            }
            //将单值图渲染对象与渲染图层挂钩
            pGeoFeatureLayer.Renderer = (IFeatureRenderer)pUniqueValueRenderer;
            //pGeoFeatureLayer.DisplayField = "ID";
            pGeoFeatureLayer.DisplayField = pField.Name;
            //刷新地图和TOOCotrol
            _pMapControl.ActiveView.ContentsChanged();
            _pMapControl.ActiveView.PartialRefresh(esriViewDrawPhase.esriViewGeography, pGeoFeatureLayer, null);
            _pMapControl.Refresh();
        }

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值