Arcgis Engine开发 分级渲染

zhihuzheye123 2015-01-18 06:13:22
最近课程设计要实现Arcmap基本框架和分级渲染功能。基本框架只要在Arcgis Engine ToolbarControl添加
Arcgis已有的指令就可以了。别人帮写了打开文件代码,可以运行。自己在网上找了分级渲染的代码,但是看不懂,不知道怎样修改,恳请大神帮忙改一下,能够实现这个功能。用的是VS2005,C#。
这是打开文件菜单的代码,包括打开、新建、保存、另存为、退出
using System;
using System.Drawing;
using System.Collections;
using System.ComponentModel;
using System.Windows.Forms;
using System.Data;
using System.IO;
using 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 private members
private IMapControl3 m_mapControl = null;
private string m_mapDocumentName = string.Empty;
#endregion

#region class constructor
public MainForm()
{
InitializeComponent();
}
#endregion

private 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;
}

#region 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();
}

private void menuOpenDoc_Click(object sender, EventArgs e)
{
//execute Open Document command
ICommand command = new ControlsOpenDocCommandClass();
command.OnCreate(m_mapControl.Object);
command.OnClick();
}

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 MapDocumentClass();
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!");
mapDoc.Close();
return;
}

//Replace its contents with the current map
mapDoc.ReplaceContents((IMxdContents)m_mapControl.Map);

//save the MapDocument in order to persist it
mapDoc.Save(mapDoc.UsesRelativePaths, false);

//close the MapDocument
mapDoc.Close();
}
}

private void menuSaveAs_Click(object sender, EventArgs e)
{
//execute SaveAs Document command
ICommand command = new ControlsSaveAsDocCommandClass();
command.OnCreate(m_mapControl.Object);
command.OnClick();
}

private void menuExitApp_Click(object sender, EventArgs e)
{
//exit the application
Application.Exit();
}
#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
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.Empty;
}
else
{
//enable the Save manu and write the doc name to the statusbar
menuSaveDoc.Enabled = true;
statusBarXY.Text = Path.GetFileName(m_mapDocumentName);
}
}

private void 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));
}


}
}

这是网上找的分级渲染代码
/// <summary>
/// 不同颜色生成分级点符号图
/// </summary>
/// <param name="mFeatureLayer">输入图层</param>
/// <param name="mFieldName">点符号颜色字段</param>
/// <param name="iBreakCount">点符号分级数</param>
/// <returns>点符号图层</returns>
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;
}
/// <summary>
/// 颜色设置
/// </summary>
/// <param name="red">R</param>
/// <param name="green">G</param>
/// <param name="blue">B</param>
/// <returns>GIS颜色对象</returns>
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;
}
...全文
638 1 打赏 收藏 转发到动态 举报
写回复
用AI写文章
1 条回复
切换为时间正序
请发表友善的回复…
发表回复
qq_27112201 2015-04-16
  • 打赏
  • 举报
回复
嘿嘿,我也在做这个例子

111,131

社区成员

发帖
与我相关
我的任务
社区描述
.NET技术 C#
社区管理员
  • C#
  • Creator Browser
  • by_封爱
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告

让您成为最强悍的C#开发者

试试用AI创作助手写篇文章吧