C#+Arcgis Engine 唯一值渲染

6 篇文章 0 订阅

        public static void Renderer(ILayer layer)
        {

            IFeatureLayer pFeatureLayer = layer as IFeatureLayer;
            IGeoFeatureLayer pGeoFeatureLayer = layer as IGeoFeatureLayer;
 
 
            //获取图层上的feature
            IFeatureClass pFeatureClass = pFeatureLayer.FeatureClass;
 
            IFeatureCursor pFeatureCursor = pFeatureClass.Search(null, false);
 
            //定义单值图渲染组件   
            IUniqueValueRenderer pUniqueValueRenderer = new UniqueValueRendererClass();
            //设置渲染字段对象        
            pUniqueValueRenderer.FieldCount = 1;
            pUniqueValueRenderer.set_Field(0, "classify");
            //创建填充符号
            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("classify");
            if (fieldNumber == -1)
            {
                MessageBox.Show("Can't find field called ", "Message", MessageBoxButtons.OK, MessageBoxIcon.Information);
 
            }
 
            //创建并设置随机色谱
            IRandomColorRamp pColorRamp = new RandomColorRampClass();
            pColorRamp.StartHue = 0;
            pColorRamp.MinValue = 99;
            pColorRamp.MinSaturation = 15;
            pColorRamp.EndHue = 360;
            pColorRamp.MaxValue = 100;
            pColorRamp.MaxSaturation = 30;
            pColorRamp.Size = 107;
            //pColorRamp.Size = pUniqueValueRenderer.ValueCount;
            bool ok = true;
            pColorRamp.CreateRamp(out ok);
            IEnumColors pEnumRamp;
            pEnumRamp = pColorRamp.Colors;
 
            //为每个值设置一个符号
            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 pFeatureValue = pFeature.get_Value(pFeature.Fields.FindField("classify")).ToString();
                pUniqueValueRenderer.AddValue(pFeatureValue, "classify", (ISymbol)pSimpleFillSymbol);
            }
            //为每个符号设置颜色
            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 = "classify";
            
        
        }
 

  • 0
    点赞
  • 6
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值