1、这是网上找的分级渲染代码
///
2、olorMaker(IFeatureLayer mFeatureLayer, IServerContext pSOC, string mFieldName, ref int iBreakCount) { IGeoFeatureLayer pGeoFeatureLayer; IFillSymbol pFillSymbol; ISimpleMarkerSymbol pSimpleMarkerS; stdole.StdFont pFontDisp; ITable pTable; IQ
3、ueryFilter pQueryFilter; ICursor pCursor; IDataStatistics pDataStatistics; IStatisticsResults pStatisticsResult; pGeoFeatureLayer = mFeatureLayer as IGeoFeatureLayer; //计算要素最大最小值 pTable = (ITable)pGeoFeatureLayer; pQueryFilter = new Qu
4、eryFilterClass(); pQueryFilter.AddField(""); pCursor = pTable.Search(pQueryFilter, true); pDataStatistics = new DataStatisticsClass(); pDataStatistics.Cursor = pCursor; pDataStatistics.Field = mFieldName; pStatisticsResult = pDataStatistics.Stat
5、istics; //背景色 pFillSymbol = pSOC.CreateObject("esriDisplay.SimpleFillSymbol") as ISimpleFillSymbol; pFillSymbol.Color = GetColor(233, 255, 190,pSOC); //点符号样式 pSimpleMarkerS = pSOC.CreateObject("esriDisplay.SimpleMarkerSymbol") as ISimpleMarkerSymbol;
6、 pFontDisp = new stdole.StdFontClass(); pFontDisp.Name = "ESRI Business"; pFontDisp.Size = 10; pSimpleMarkerS.Outline = true; pSimpleMarkerS.OutlineColor = GetColor(0, 0, 0, pSOC); //分级符号图 //获取统计数据及起频率 ITableHistogram pTableHistogram
7、 = pSOC.CreateObject("esriCarto.BasicTableHistogram") as ITableHistogram; pTableHistogram.Field = mFieldName; pTableHistogram.Table = pTable; object dataValues, dataFrequency; IBasicHistogram pHistogram = (IBasicHistogram)pTableHistogram; pHistogram.GetHi
8、stogram(out dataValues, out dataFrequency); IClassifyGEN pClassify = new NaturalBreaksClass(); //产生种类 pClassify.Classify(dataValues, dataFrequency, ref iBreakCount); object ob = pClassify.ClassBreaks; double[] Classes = (double[])ob; int Classe
9、sCount = Classes.Length; //定义分类渲染 IClassBreaksRenderer pClassBreaksRenderer = (IClassBreaksRenderer)pSOC.CreateObject("esriCarto.ClassBreaksRenderer"); pClassBreaksRenderer.Field = mFieldName; pClassBreaksRenderer.BreakCount = ClassesCount; pClassBreaksRe
10、nderer.SortClassesAscending = true; pClassBreaksRenderer.MinimumBreak = Classes[0]; IColor pColor = GetRGBColor(124, 143, 0, pSOC); //设置要素的填充颜色 for (int i = 0; i < ClassesCount; i ) { ISimpleFillSymbol pFillSymbol1 = new SimpleFillSymbolCla
11、ss(); pSimpleMarkerS. Color = pColor; pFillSymbol1.Style = esriSimpleFillStyle.esriSFSSolid; pSimpleMarkerS.Size = 4*(i 1); pClassBreaksRenderer.BackgroundSymbol = pFillSymbol; pClassBreaksRenderer.set_Symbol(i, (ISymbol)pSimpleMarker
12、S); pClassBreaksRenderer.set_Break(i, Classes[i]); } pGeoFeatureLayer.Renderer = (IFeatureRenderer)pClassBreaksRenderer; return (IFeatureLayer)pGeoFeatureLayer; } private static IRgbColor GetRGBColor(int yourRed, int yourGreen, int yourBlue, IServer
13、Context pSOC)
{
IRgbColor pRGB = (IRgbColor)pSOC.CreateObject("esriDisplay.RgbColor");
pRGB.Red = yourRed;
pRGB.Green = yourGreen;
pRGB.Blue = yourBlue;
pRGB.UseWindowsDithering = true;
return pRGB;
}
///
14、 ///
/// R
/// G
/// B
///
15、lor(red, green, blue, pSOC); IColor color = rgbColor as IColor; return color; } 这是打开文件菜单的代码,包括打开、新建、保存、另存为、退出 using System; using System.Drawing; using System.Collections; using System.ComponentModel; using System.Windows.Forms; using System.Data; using System.IO; u
16、sing System.Runtime.InteropServices; using ESRI.ArcGIS.esriSystem; using ESRI.ArcGIS.Carto; using ESRI.ArcGIS.Controls; using ESRI.ArcGIS.ADF; using ESRI.ArcGIS.SystemUI; namespace MapControlApplication1 { public sealed partial class MainForm : Form { #region class priv
17、ate members private IMapControl3 m_mapControl = null; private string m_mapDocumentName = string.Empty; #endregion #region class constructor public MainForm() { InitializeComponent(); } #endregion privat
18、e void MainForm_Load(object sender, EventArgs e) { //get the MapControl m_mapControl = (IMapControl3)axMapControl1.Object; //disable the Save menu (since there is no document yet) menuSaveDoc.Enabled = false; } #regio
19、n Main Menu event handlers private void menuNewDoc_Click(object sender, EventArgs e) { //execute New Document command ICommand command = new CreateNewDocument(); command.OnCreate(m_mapControl.Object); command.OnClick(); }
20、 private void menuOpenDoc_Click(object sender, EventArgs e) { //execute Open Document command ICommand command = new ControlsOpenDocCommandClass(); command.OnCreate(m_mapControl.Object); command.OnClick(); }
21、private void menuSaveDoc_Click(object sender, EventArgs e) { //execute Save Document command if (m_mapControl.CheckMxFile(m_mapDocumentName)) { //create a new instance of a MapDocument IMapDocument mapDoc = new MapDocu
22、mentClass(); mapDoc.Open(m_mapDocumentName, string.Empty); //Make sure that the MapDocument is not readonly if (mapDoc.get_IsReadOnly(m_mapDocumentName)) { MessageBox.Show("Map document is read only!");
23、 mapDoc.Close(); return; } //Replace its contents with the current map mapDoc.ReplaceContents((IMxdContents)m_mapControl.Map); //save the MapDocument in order to persist it map
24、Doc.Save(mapDoc.UsesRelativePaths, false); //close the MapDocument mapDoc.Close(); } } private void menuSaveAs_Click(object sender, EventArgs e) { //execute SaveAs Document command ICommand comman
25、d = new ControlsSaveAsDocCommandClass(); command.OnCreate(m_mapControl.Object); command.OnClick(); } private void menuExitApp_Click(object sender, EventArgs e) { //exit the application Application.Exit(); }
26、 #endregion //listen to MapReplaced evant in order to update the statusbar and the Save menu private void axMapControl1_OnMapReplaced(object sender, IMapControlEvents2_OnMapReplacedEvent e) { //get the current document name from the MapControl
27、 m_mapDocumentName = m_mapControl.DocumentFilename; //if there is no MapDocument, diable the Save menu and clear the statusbar if (m_mapDocumentName == string.Empty) { menuSaveDoc.Enabled = false; statusBarXY.Text = string
28、Empty; } else { //enable the Save manu and write the doc name to the statusbar menuSaveDoc.Enabled = true; statusBarXY.Text = Path.GetFileName(m_mapDocumentName); } } private v
29、oid axMapControl1_OnMouseMove(object sender, IMapControlEvents2_OnMouseMoveEvent e) { statusBarXY.Text = string.Format("{0}, {1} {2}", e.mapX.ToString("#######.##"), e.mapY.ToString("#######.##"), axMapControl1.MapUnits.ToString().Substring(4)); } } }






