分级渲染classbreakrenderer位于carto类库中,进行分级渲染时,首先要将相应图层按照某一Field分级。可使用esrisystem类库中的iclassifyGEN类的classify进行分类
private ISymbol GetSymbol(IColor pColor)
{
ISymbol pSymbol;
ISimpleFillSymbol pSymbolFillSymbol = new SimpleFillSymbolClass();
pSymbolFillSymbol.Color = pColor;
pSymbol = pSymbolFillSymbol as ISymbol;
return pSymbol;
} private void classBreakRendererToolStripMenuItem_Click(object sender, EventArgs e)
{
double[] classes;
IGeoFeatureLayer pGeoFeatureLayer = this.axMapControl1.get_Layer() as IGeoFeatureLayer;
ITable pTable = pGeoFeatureLayer.FeatureClass as ITable;//Itable接口位于Geodabase类库中
ITableHistogram pTableHistogram = new BasicTableHistogramClass();
IBasicHistogram pBasicHistogram = pTableHistogram as IBasicHistogram;
pTableHistogram.Field = "PERIMETER";
pTableHistogram.Table = pTable;
object dataValues;
object dataFrequent; pBasicHistogram.GetHistogram(out dataValues, out dataFrequent);//获取FeatureClass中的dataValues和datafrequent IClassifyGEN pClassifyGEN = new EqualIntervalClass(); int classCount = ;
pClassifyGEN.Classify(dataValues, dataFrequent, ref classCount);//根据上面的dataValues和datafrequent进行分级,分级数为classcout classes = (double[])pClassifyGEN.ClassBreaks;//获取分段点 IClassBreaksRenderer pClassBreakRenderer = new ClassBreaksRenderer();
pClassBreakRenderer.BreakCount = ;//断点数
pClassBreakRenderer.Field = "PERIMETER";
pClassBreakRenderer.SortClassesAscending = true;//按顺序排列 IAlgorithmicColorRamp pColorRamp = new AlgorithmicColorRampClass();
IRgbColor pRgbColor1 = new RgbColorClass();
IRgbColor pRgbColor2 = new RgbColorClass();
pRgbColor1.Red = ;
pRgbColor1.Green = ;
pRgbColor1.Blue = ;
pRgbColor2.Red = ;
pRgbColor2.Green = ;
pRgbColor2.Blue = ;
pColorRamp.FromColor = pRgbColor2;
pColorRamp.ToColor = pRgbColor1;
pColorRamp.Size = ;//颜色带范围
bool ok=true;
pColorRamp.CreateRamp(out ok);
IEnumColors pEnumColors = pColorRamp.Colors;
for (int i = ; i < classCount; i++)
{
IColor pColor = pEnumColors.Next();
ISymbol pSymbol = GetSymbol(pColor); pClassBreakRenderer.set_Symbol(i, pSymbol);
pClassBreakRenderer.set_Label(i, classes[i].ToString() + "-" + classes[i + ].ToString());
pClassBreakRenderer.set_Break(i, classes[i+]); }
pGeoFeatureLayer.Renderer = pClassBreakRenderer as IFeatureRenderer;
this.axMapControl1.ActiveView.PartialRefresh(esriViewDrawPhase.esriViewGeography, null, null);
axTOCControl1.Update(); }
过程中需要注意的:1、分级和渲染的具体字段需指明,本例以PERIMETER字段分级和渲染 2、颜色带的size需具体指定