Arcgis Engine开发分级渲染

更新时间:2024-03-09 16:21:01 阅读量: 综合文库 文档下载

说明:文章内容仅供预览,部分内容可能不全。下载后的文档,内容与下面显示的完全一致。下载之前请确认下面内容是否您想要的,是否完整无缺。

这是网上找的分级渲染代码 ///

/// 不同颜色生成分级点符号图 ///

///

/// /// /// 点符号图层

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(\ISimpleFillSymbol;

pFillSymbol.Color = GetColor(233, 255, 190,pSOC); //点符号样式

pSimpleMarkerS = pSOC.CreateObject(\ISimpleMarkerSymbol;

pFontDisp = new stdole.StdFontClass(); pFontDisp.Name = \ pFontDisp.Size = 10;

pSimpleMarkerS.Outline = true;

pSimpleMarkerS.OutlineColor = GetColor(0, 0, 0, pSOC); //分级符号图

//获取统计数据及起频率

as as ITableHistogram pTableHistogram = pSOC.CreateObject(\ 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(\ 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(\ pRGB.Red = yourRed; pRGB.Green = yourGreen; pRGB.Blue = yourBlue;

pRGB.UseWindowsDithering = true;

return pRGB; }

///

/// 颜色设置 ///

/// GIS颜色对象

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

这是打开文件菜单的代码,包括打开、新建、保存、另存为、退出

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(\); 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(\, e.mapX.ToString(\), e.mapY.ToString(\), axMapControl1.MapUnits.ToString().Substring(4)); } } }

//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(\, e.mapX.ToString(\), e.mapY.ToString(\), axMapControl1.MapUnits.ToString().Substring(4)); } } }

本文来源:https://www.bwwdw.com/article/1fua.html

Top