标签:
public void fenjiZS() { IMap pMap; IGeoFeatureLayer pGeoFeatureL; IFeatureClass pFeatureClass; IFeatureCursor pFeatureCursor; IQueryFilter pQueryFilter; IClassBreaksRenderer pClassBreaksRenderer; IEnumColors pEnumColors; IColor pColor; ISimpleMarkerSymbol pMarkerFillS; int lbreakIndex; //定义要渲染的字段 const string strField = "AQIType"; //定义分类的数目为6 const int numDesiredClasses = 6; pMap = axMapControl1.Map; //选定要渲染的图层 pGeoFeatureL = pMap.get_Layer(0) as IGeoFeatureLayer; pFeatureClass = pGeoFeatureL.FeatureClass; pQueryFilter = new QueryFilterClass(); pFeatureCursor = pFeatureClass.Search(pQueryFilter, true); IDataStatistics pDataStatistics; IStatisticsResults pStatisticsResult; pDataStatistics = new DataStatisticsClass(); pDataStatistics.Cursor = pFeatureCursor as ICursor; pDataStatistics.Field = strField; pStatisticsResult = pDataStatistics.Statistics; if (pStatisticsResult == null) { MessageBox.Show("Failed to gather stats on the feature class"); } pClassBreaksRenderer = new ClassBreaksRendererClass(); pClassBreaksRenderer.Field = strField; pClassBreaksRenderer.BreakCount = numDesiredClasses; //获得颜色 pEnumColors = CreateColor(); string[] LabelAQI = {"优","良","轻度污染","中度污染","严重污染","重度污染"}; for (lbreakIndex = 0; lbreakIndex < numDesiredClasses; lbreakIndex++) { pColor = pEnumColors.Next(); pMarkerFillS = new SimpleMarkerSymbolClass ();//渲染点图层 pMarkerFillS.Color = pColor; pMarkerFillS.Style = esriSimpleMarkerStyle .esriSMSCircle; //不同的类别设置不同的填充样式 pClassBreaksRenderer.set_Symbol(lbreakIndex, pMarkerFillS as ISymbol); //分类渲染对象的断点 pClassBreaksRenderer.set_Break(lbreakIndex, lbreakIndex + 1); pClassBreaksRenderer.set_Label(lbreakIndex, LabelAQI[lbreakIndex]); } //设置Renderer pGeoFeatureL.Renderer = pClassBreaksRenderer as IFeatureRenderer; axMapControl1.ActiveView.PartialRefresh(esriViewDrawPhase.esriViewGeography, null, null); }
public IEnumColors CreateColor()//生成颜色带方法 { IRgbColor fromColor = new RgbColor(); fromColor.Red = 0; fromColor.Green = 255; fromColor.Blue = 0; IRgbColor toColor = new RgbColor(); toColor.Red = 255; toColor.Green = 0; toColor.Blue = 0; IAlgorithmicColorRamp pRampColor; pRampColor = new AlgorithmicColorRampClass(); pRampColor.FromColor = fromColor; pRampColor.ToColor = toColor; pRampColor.Size = 6;//设置颜色带数量 bool ok = true; pRampColor.CreateRamp(out ok);//创建颜色带 return pRampColor.Colors; }
标签:
原文地址:http://www.cnblogs.com/MansonsBlog/p/5738870.html