///
/// 不同颜色生成分级点符号图
///
/// 输入图层
/// 点符号颜色字段
/// 点符号分级数
///
public IFeatureLayer GisChart_ClassBreakColorMaker(IFeatureLayer mFeatureLayer, IServerContext pSOC, string mFieldName, ref int iBreakCount)
{
IGeoFeatureLayer pGeoFeatureLayer;
IFillSymbol pFillSymbol;
ISimpleMarkerSymbol pSimpleMarkerS;
stdole.StdFont pFontDisp;
ITable pTable;
IQueryFilter pQueryFilter;
ICursor pCursor;
IDataStatistics pDataStatistics;
IStatisticsResults pStatisticsResult;
pGeoFeatureLayer = mFeatureLayer as IGeoFeatureLayer;
//计算要素最大最小值
pTable = (ITable)pGeoFeatureLayer;
pQueryFilter = new QueryFilterClass();
pQueryFilter.AddField("");
pCursor = pTable.Search(pQueryFilter, true);
pDataStatistics = new DataStatisticsClass();
pDataStatistics.Cursor = pCursor;
pDataStatistics.Field = mFieldName;
pStatisticsResult = pDataStatistics.Statistics;
//背景色
pFillSymbol = pSOC.CreateObject("esriDisplay.SimpleFillSymbol") as ISimpleFillSymbol;
pFillSymbol.Color = GetColor(233, 255, 190,pSOC);
//点符号样式
pSimpleMarkerS = pSOC.CreateObject("esriDisplay.SimpleMarkerSymbol") as ISimpleMarkerSymbol;
pFontDisp = new stdole.StdFontClass();
pFontDisp.Name = "ESRI Business";
pFontDisp.Size = 10;
pSimpleMarkerS.Outline = true;
pSimpleMarkerS.OutlineColor = GetColor(0, 0, 0, pSOC);
//分级符号图
//获取统计数据及起频率
ITableHistogram pTableHistogram = pSOC.CreateObject("esriCarto.BasicTableHistogram") as ITableHistogram;
pTableHistogram.Field = mFieldName;
pTableHistogram.Table = pTable;
object dataValues, dataFrequency;
IBasicHistogram pHistogram = (IBasicHistogram)pTableHistogram;
pHistogram.GetHistogram(out dataValues, out dataFrequency);
IClassifyGEN pClassify = new NaturalBreaksClass();
//产生种类
pClassify.Classify(dataValues, dataFrequency, ref iBreakCount);
object ob = pClassify.ClassBreaks;
double[] Classes = (double[])ob;
int ClassesCount = Classes.Length;
//定义分类渲染
IClassBreaksRenderer pClassBreaksRenderer = (IClassBreaksRenderer)pSOC.CreateObject("esriCarto.ClassBreaksRenderer");
pClassBreaksRenderer.Field = mFieldName;
pClassBreaksRenderer.BreakCount = ClassesCount;
pClassBreaksRenderer.SortClassesAscending = true;
pClassBreaksRenderer.MinimumBreak = Classes[0];
IColor pColor = GetRGBColor(124, 143, 0, pSOC);
//设置要素的填充颜色
for (int i = 0; i < ClassesCount; i++)
{
ISimpleFillSymbol pFillSymbol1 = new SimpleFillSymbolClass();
pSimpleMarkerS.Color = pColor;
pFillSymbol1.Style = esriSimpleFillStyle.esriSFSSolid;
pSimpleMarkerS.Size = 4*(i+1);
pClassBreaksRenderer.BackgroundSymbol = pFillSymbol;
pClassBreaksRenderer.set_Symbol(i, (ISymbol)pSimpleMarkerS);
pClassBreaksRenderer.set_Break(i, Classes[i]);
}
pGeoFeatureLayer.Renderer = (IFeatureRenderer)pClassBreaksRenderer;
return (IFeatureLayer)pGeoFeatureLayer;
}
private static IRgbColor GetRGBColor(int yourRed, int yourGreen, int yourBlue, IServerContext pSOC)
{
IRgbColor pRGB = (IRgbColor)pSOC.CreateObject("esriDisplay.RgbColor");
pRGB.Red = yourRed;
pRGB.Green = yourGreen;
pRGB.Blue = yourBlue;
pRGB.UseWindowsDithering = true;
return pRGB;
}
///
/// 颜色设置
///
/// R
/// G
/// B
///
private static IColor GetColor(int red, int green, int blue, IServerContext pSOC)
{
IRgbColor rgbColor = GetRGBColor(red, green, blue, pSOC);
IColor color = rgbColor as IColor;
return color;
}