ArcEngine面数据渐变渲染

该博客介绍如何使用ArcEngine根据shapefile中的WQL和VOL字段值对面进行渐变色渲染。主要代码展示了创建UniqueValueRenderer,设置颜色渐变,以及应用透明度的过程,最终达到渲染结果。

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

ArcEngine面数据渐变渲染

 

说明,以下代码实现依据shp中的WQLVOL字段的值对面进行渐变色渲染。

程序主要代码如下:

 

需要添加的引用

using ESRI.ArcGIS.Display;

using ESRI.ArcGIS.Carto;

using ESRI.ArcGIS.Geodatabase;

using ESRI.ArcGIS.DataSourcesFile;

 

程序主要代码

public bool RendInterResult(string ShpPath)

        {

            FilePath pShpPath = new FilePath(ShpPath);

            IWorkspaceFactory pWSF = new ShapefileWorkspaceFactoryClass();

            IFeatureWorkspace pRWS = (IFeatureWorkspace)pWSF.OpenFromFile(pShpPath.GetDir(), 0);

            IFeatureLayer pMapNewLayer = new FeatureLayerClass();

            IFeatureClass pClass;

            pClass = pRWS.OpenFeatureClass(pShpPath.GetFileName());

            pMapNewLayer.FeatureClass = pClass;

            IGeoFeatureLayer pGeoLayer = (IGeoFeatureLayer)pMapNewLayer;

            //构造一个UniqueValueRenderer

            IUniqueValueRenderer renderer = new UniqueValueRendererClass();

            renderer.FieldCount = 1;

            renderer.set_Field(0, "FID");

 

            ILineSymbol pLineSym = new SimpleLineSymbolClass();

            IRgbColor LineRGBColor = new RgbColorClass();

            LineRGBColor.Transparency = 0;

            pLineSym.Color = LineRGBColor;

            for (int m = 0; m < pClass.FeatureCount(null); m++)

            {

                IFeature pFeature = pClass.GetFeature(m);

                int fromColor = pFeature.Fields.FindField("WQL");

                int ToColor = pFeature.Fields.FindField("VOL");

                if (ToColor < 0 || fromColor < 0) break;

                int colorVale1 = Convert.ToInt32(pFeature.get_Value(fromColor));

                int colorVale2 = Convert.ToInt32(pFeature.get_Value(ToColor));

                IRgbColor fromRGBColor = pColorset.GetValueRgb(colorVale1);

                IRgbColor ToRGBColor = pColorset.GetValueRgb(colorVale2);

                IGradientFillSymbol pGradientFillSymbol = CreateGradientFillSymbol(fromRGBColor, ToRGBColor, 100);

                pGradientFillSymbol.Outline = pLineSym;

                renderer.DefaultSymbol = (ISymbol)pGradientFillSymbol;

                renderer.AddValue(Convert.ToString(m), "级别", (ISymbol)pGradientFillSymbol);

                renderer.set_Label(Convert.ToString(m), Convert.ToString(colorVale1) + "--" + Convert.ToString(colorVale2));

                //添加值

            }

            ILayerEffects pLayerEff;

            pLayerEff = pMapNewLayer as ILayerEffects;

            pLayerEff.Transparency = 40;

            pGeoLayer.Renderer = (IFeatureRenderer)renderer;

            pMapNewLayer = (IFeatureLayer)pGeoLayer;

            pMapNewLayer.Name = "渲染结果";

            axMapControl1.AddLayer(pMapNewLayer);

            return true;

        }

        public ESRI.ArcGIS.Display.IGradientFillSymbol CreateGradientFillSymbol(ESRI.ArcGIS.Display.IRgbColor startRgbColor, ESRI.ArcGIS.Display.IRgbColor endRgbColor, System.Int32 numberOfIntervals)

        {

 

            if (startRgbColor == null || endRgbColor == null || numberOfIntervals < 0)

            {

                return null;

            }

            // Create the Ramp for the Gradient Fill

            ESRI.ArcGIS.Display.IAlgorithmicColorRamp algorithmicColorRamp = new ESRI.ArcGIS.Display.AlgorithmicColorRampClass();

            algorithmicColorRamp.FromColor = startRgbColor;

            algorithmicColorRamp.ToColor = endRgbColor;

            algorithmicColorRamp.Algorithm = ESRI.ArcGIS.Display.esriColorRampAlgorithm.esriHSVAlgorithm;

 

            // Create the Gradient Fill

            ESRI.ArcGIS.Display.IGradientFillSymbol gradientFillSymbol = new ESRI.ArcGIS.Display.GradientFillSymbolClass();

            gradientFillSymbol.ColorRamp = algorithmicColorRamp;

            gradientFillSymbol.GradientAngle = 0;

            gradientFillSymbol.GradientPercentage = 0.9;

            gradientFillSymbol.IntervalCount = numberOfIntervals;

            gradientFillSymbol.Style = ESRI.ArcGIS.Display.esriGradientFillStyle.esriGFSLinear;

 

            return gradientFillSymbol;

        }

 

 

效果如下

 

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值