ArcEngine面数据渐变渲染
说明,以下代码实现依据shp中的WQL和VOL字段的值对面进行渐变色渲染。
程序主要代码如下:
需要添加的引用
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;
}
效果如下