问题描述
最近课程设计要实现Arcmap基本框架和分级渲染功能。基本框架只要在ArcgisEngineToolbarControl添加Arcgis已有的指令就可以了。别人帮写了打开文件代码,可以运行。自己在网上找了分级渲染的代码,但是看不懂,不知道怎样修改,恳请大神帮忙改一下,能够实现这个功能。用的是VS2005,C#。这是打开文件菜单的代码,包括打开、新建、保存、另存为、退出usingSystem;usingSystem.Drawing;usingSystem.Collections;usingSystem.ComponentModel;usingSystem.Windows.Forms;usingSystem.Data;usingSystem.IO;usingSystem.Runtime.InteropServices;usingESRI.ArcGIS.esriSystem;usingESRI.ArcGIS.Carto;usingESRI.ArcGIS.Controls;usingESRI.ArcGIS.ADF;usingESRI.ArcGIS.SystemUI;namespaceMapControlApplication1{publicsealedpartialclassMainForm:Form{#regionclassprivatemembersprivateIMapControl3m_mapControl=null;privatestringm_mapDocumentName=string.Empty;#endregion#regionclassconstructorpublicMainForm(){InitializeComponent();}#endregionprivatevoidMainForm_Load(objectsender,EventArgse){//gettheMapControlm_mapControl=(IMapControl3)axMapControl1.Object;//disabletheSavemenu(sincethereisnodocumentyet)menuSaveDoc.Enabled=false;}#regionMainMenueventhandlersprivatevoidmenuNewDoc_Click(objectsender,EventArgse){//executeNewDocumentcommandICommandcommand=newCreateNewDocument();command.OnCreate(m_mapControl.Object);command.OnClick();}privatevoidmenuOpenDoc_Click(objectsender,EventArgse){//executeOpenDocumentcommandICommandcommand=newControlsOpenDocCommandClass();command.OnCreate(m_mapControl.Object);command.OnClick();}privatevoidmenuSaveDoc_Click(objectsender,EventArgse){//executeSaveDocumentcommandif(m_mapControl.CheckMxFile(m_mapDocumentName)){//createanewinstanceofaMapDocumentIMapDocumentmapDoc=newMapDocumentClass();mapDoc.Open(m_mapDocumentName,string.Empty);//MakesurethattheMapDocumentisnotreadonlyif(mapDoc.get_IsReadOnly(m_mapDocumentName)){MessageBox.Show("Mapdocumentisreadonly!");mapDoc.Close();return;}//ReplaceitscontentswiththecurrentmapmapDoc.ReplaceContents((IMxdContents)m_mapControl.Map);//savetheMapDocumentinordertopersistitmapDoc.Save(mapDoc.UsesRelativePaths,false);//closetheMapDocumentmapDoc.Close();}}privatevoidmenuSaveAs_Click(objectsender,EventArgse){//executeSaveAsDocumentcommandICommandcommand=newControlsSaveAsDocCommandClass();command.OnCreate(m_mapControl.Object);command.OnClick();}privatevoidmenuExitApp_Click(objectsender,EventArgse){//exittheapplicationApplication.Exit();}#endregion//listentoMapReplacedevantinordertoupdatethestatusbarandtheSavemenuprivatevoidaxMapControl1_OnMapReplaced(objectsender,IMapControlEvents2_OnMapReplacedEvente){//getthecurrentdocumentnamefromtheMapControlm_mapDocumentName=m_mapControl.DocumentFilename;//ifthereisnoMapDocument,diabletheSavemenuandclearthestatusbarif(m_mapDocumentName==string.Empty){menuSaveDoc.Enabled=false;statusBarXY.Text=string.Empty;}else{//enabletheSavemanuandwritethedocnametothestatusbarmenuSaveDoc.Enabled=true;statusBarXY.Text=Path.GetFileName(m_mapDocumentName);}}privatevoidaxMapControl1_OnMouseMove(objectsender,IMapControlEvents2_OnMouseMoveEvente){statusBarXY.Text=string.Format("{0},{1}{2}",e.mapX.ToString("
解决方案二:
解决方案三:
#.##"),e.mapY.ToString("
解决方案四:
解决方案五:
#.##"),axMapControl1.MapUnits.ToString().Substring(4));}}}这是网上找的分级渲染代码///<summary>///不同颜色生成分级点符号图///</summary>///<paramname="mFeatureLayer">输入图层</param>///<paramname="mFieldName">点符号颜色字段</param>///<paramname="iBreakCount">点符号分级数</param>///<returns>点符号图层</returns>publicIFeatureLayerGisChart_ClassBreakColorMaker(IFeatureLayermFeatureLayer,IServerContextpSOC,stringmFieldName,refintiBreakCount){IGeoFeatureLayerpGeoFeatureLayer;IFillSymbolpFillSymbol;ISimpleMarkerSymbolpSimpleMarkerS;stdole.StdFontpFontDisp;ITablepTable;IQueryFilterpQueryFilter;ICursorpCursor;IDataStatisticspDataStatistics;IStatisticsResultspStatisticsResult;pGeoFeatureLayer=mFeatureLayerasIGeoFeatureLayer;//计算要素最大最小值pTable=(ITable)pGeoFeatureLayer;pQueryFilter=newQueryFilterClass();pQueryFilter.AddField("");pCursor=pTable.Search(pQueryFilter,true);pDataStatistics=newDataStatisticsClass();pDataStatistics.Cursor=pCursor;pDataStatistics.Field=mFieldName;pStatisticsResult=pDataStatistics.Statistics;//背景色pFillSymbol=pSOC.CreateObject("esriDisplay.SimpleFillSymbol")asISimpleFillSymbol;pFillSymbol.Color=GetColor(233,255,190,pSOC);//点符号样式pSimpleMarkerS=pSOC.CreateObject("esriDisplay.SimpleMarkerSymbol")asISimpleMarkerSymbol;pFontDisp=newstdole.StdFontClass();pFontDisp.Name="ESRIBusiness";pFontDisp.Size=10;pSimpleMarkerS.Outline=true;pSimpleMarkerS.OutlineColor=GetColor(0,0,0,pSOC);//分级符号图//获取统计数据及起频率ITableHistogrampTableHistogram=pSOC.CreateObject("esriCarto.BasicTableHistogram")asITableHistogram;pTableHistogram.Field=mFieldName;pTableHistogram.Table=pTable;objectdataValues,dataFrequency;IBasicHistogrampHistogram=(IBasicHistogram)pTableHistogram;pHistogram.GetHistogram(outdataValues,outdataFrequency);IClassifyGENpClassify=newNaturalBreaksClass();//产生种类pClassify.Classify(dataValues,dataFrequency,refiBreakCount);objectob=pClassify.ClassBreaks;double[]Classes=(double[])ob;intClassesCount=Classes.Length;//定义分类渲染IClassBreaksRendererpClassBreaksRenderer=(IClassBreaksRenderer)pSOC.CreateObject("esriCarto.ClassBreaksRenderer");pClassBreaksRenderer.Field=mFieldName;pClassBreaksRenderer.BreakCount=ClassesCount;pClassBreaksRenderer.SortClassesAscending=true;pClassBreaksRenderer.MinimumBreak=Classes[0];IColorpColor=GetRGBColor(124,143,0,pSOC);//设置要素的填充颜色for(inti=0;i<ClassesCount;i){ISimpleFillSymbolpFillSymbol1=newSimpleFillSymbolClass();pSimpleMarkerS.Color=pColor;pFillSymbol1.Style=esriSimpleFillStyle.esriSFSSolid;pSimpleMarkerS.Size=4*(i1);pClassBreaksRenderer.BackgroundSymbol=pFillSymbol;pClassBreaksRenderer.set_Symbol(i,(ISymbol)pSimpleMarkerS);pClassBreaksRenderer.set_Break(i,Classes[i]);}pGeoFeatureLayer.Renderer=(IFeatureRenderer)pClassBreaksRenderer;return(IFeatureLayer)pGeoFeatureLayer;}privatestaticIRgbColorGetRGBColor(intyourRed,intyourGreen,intyourBlue,IServerContextpSOC){IRgbColorpRGB=(IRgbColor)pSOC.CreateObject("esriDisplay.RgbColor");pRGB.Red=yourRed;pRGB.Green=yourGreen;pRGB.Blue=yourBlue;pRGB.UseWindowsDithering=true;returnpRGB;}///<summary>///颜色设置///</summary>///<paramname="red">R</param>///<paramname="green">G</param>///<paramname="blue">B</param>///<returns>GIS颜色对象</returns>privatestaticIColorGetColor(intred,intgreen,intblue,IServerContextpSOC){IRgbColorrgbColor=GetRGBColor(red,green,blue,pSOC);IColorcolor=rgbColorasIColor;returncolor;}
解决方案
本帖最后由 zhihuzheye123 于 2015-01-21 02:45:08 编辑
解决方案六:
嘿嘿,我也在做这个例子