您好,欢迎访问三七文档
《地理系统设计》课程实验报告学生姓名:蒋鹏钦班级:0644131学号:23实验名称:最短路径分析实验数据数据文件:National.mdb.Qingdao.mxd实验工具开发环境:VS2013开发工具:ArcEngine10.2编程语言:C#语言实验步骤(1)新建工程,选择C#项中的窗体;添加相应的控件,并且修改各自的属性,最终得到的效果如下双击“打开地图”添加事件事件框中的代码如下:mapDocument=newMapDocumentClass();try{System.Windows.Forms.OpenFileDialogopenFileDialog;openFileDialog=newOpenFileDialog();openFileDialog.Title=打开图层文件;openFileDialog.Filter=mapdocuments(*.mxd)|*.mxd;openFileDialog.ShowDialog();stringfilePath=openFileDialog.FileName;mapDocument.Open(filePath,);for(inti=0;imapDocument.MapCount;i++){mainMapControl.Map=mapDocument.get_Map(i);}mainMapControl.Refresh();}catch(Exceptionex){MessageBox.Show(加载失败+ex.ToString());}同理,双击“添加站点”给其添加事件如图:事件的代码如下:namespace最短路径分析{///summary///SummarydescriptionforAddNetBarriesTool.////summary[Guid(de7152cb-76df-4a8c-93d9-d01b9bda0672)][ClassInterface(ClassInterfaceType.None)][ProgId(最短路径分析.AddNetBarriesTool)]publicsealedclassAddNetBarriesTool:BaseTool{#regionCOMRegistrationFunction(s)[ComRegisterFunction()][ComVisible(false)]staticvoidRegisterFunction(TyperegisterType){//RequiredforArcGISComponentCategoryRegistrarsupportArcGISCategoryRegistration(registerType);////TODO:AddanyCOMregistrationcodehere//}[ComUnregisterFunction()][ComVisible(false)]staticvoidUnregisterFunction(TyperegisterType){//RequiredforArcGISComponentCategoryRegistrarsupportArcGISCategoryUnregistration(registerType);////TODO:AddanyCOMunregistrationcodehere//}#regionArcGISComponentCategoryRegistrargeneratedcode///summary///RequiredmethodforArcGISComponentCategoryregistration-///Donotmodifythecontentsofthismethodwiththecodeeditor.////summaryprivatestaticvoidArcGISCategoryRegistration(TyperegisterType){stringregKey=string.Format(HKEY_CLASSES_ROOT\\CLSID\\{{{0}}},registerType.GUID);MxCommands.Register(regKey);ControlsCommands.Register(regKey);}///summary///RequiredmethodforArcGISComponentCategoryunregistration-///Donotmodifythecontentsofthismethodwiththecodeeditor.////summaryprivatestaticvoidArcGISCategoryUnregistration(TyperegisterType){stringregKey=string.Format(HKEY_CLASSES_ROOT\\CLSID\\{{{0}}},registerType.GUID);MxCommands.Unregister(regKey);ControlsCommands.Unregister(regKey);}#endregion#endregionprivateIHookHelperm_hookHelper=null;privateIFeatureWorkspacepFWorkspace;privateIFeatureClassbarriesFClass;stringpath=System.AppDomain.CurrentDomain.SetupInformation.ApplicationBase;publicAddNetBarriesTool(){////TODO:Definevaluesforthepublicproperties//base.m_category=NetWorkAnalysClass;//localizabletextbase.m_caption=添加障碍;//localizabletextbase.m_message=鼠标在地图上单击即可;//localizabletextbase.m_toolTip=添加障碍;//localizabletextbase.m_name=AddBarriesTool;//uniqueid,non-localizable(e.g.MyCategory_MyTool)try{////TODO:changeresourcenameifnecessary//stringbitmapResourceName=GetType().Name+.bmp;base.m_bitmap=newBitmap(GetType(),bitmapResourceName);base.m_cursor=newSystem.Windows.Forms.Cursor(GetType(),GetType().Name+.cur);}catch(Exceptionex){System.Diagnostics.Trace.WriteLine(ex.Message,InvalidBitmap);}}#regionOverriddenClassMethods///summary///Occurswhenthistooliscreated////summary///paramname=hookInstanceoftheapplication/parampublicoverridevoidOnCreate(objecthook){try{m_hookHelper=newHookHelperClass();m_hookHelper.Hook=hook;if(m_hookHelper.ActiveView==null){m_hookHelper=null;}}catch{m_hookHelper=null;}if(m_hookHelper==null)base.m_enabled=false;elsebase.m_enabled=true;//TODO:Addotherinitializationcode}///summary///Occurswhenthistoolisclicked////summarypublicoverridevoidOnClick(){//TODO:AddAddNetBarriesTool.OnClickimplementationstringname=NetWorkAnalysClass.getPath(path)+\\data\\HuanbaoGeodatabase.gdb;pFWorkspace=NetWorkAnalysClass.OpenWorkspace(name)asIFeatureWorkspace;barriesFClass=pFWorkspace.OpenFeatureClass(Barries);if(barriesFClass.FeatureCount(null)0){ITablepTable=barriesFClassasITable;pTable.DeleteSearchedRows(null);}}publicoverridevoidOnMouseDown(intButton,intShift,intX,intY){//TODO:AddAddNetBarriesTool.OnMouseDownimplementationtry{IPointpStopsPoint=newPointClass();pStopsPoint=m_hookHelper.ActiveView.ScreenDisplay.DisplayTransformation.ToMapPoint(X,Y);IFeaturenewPointFeature=barriesFClass.CreateFeature();try{newPointFeature.Shape=pStopsPoint;}catch{IGeometrypGeo=pStopsPoint;IZAwarepZAware=pGeoasIZAware;pZAware.ZAware=false;newPointFeature.Shape=pGeo;}newPointFeature.Store();IGraphicsContainerpGrap=m_hookHelper.ActiveViewasIGraphicsContainer;IColorpColor;IRgbColorpRgbColor=newRgbColorClass();pRgbColor.Red=255;pRgbColor.Green=255;pRgbColor.Blue=255;pColor=pRgbColorasIColor;IPictureMarkerSymbolpms=newPictureMarkerSymbolClass();pms.BitmapTransparencyColor=pColor;//添加自定义障碍点图片pms.CreateMarkerSymbolFromFile(esriIPictureType.esriIPictureBitmap,NetWorkAnalysClass.getPath(path)+\\data\\Img\\barries.bmp);pms.Size=18;IMarkerElementpMarkerEle=newMarkerElementClass();pMarkerEle.Symbol=pmsasIMarkerSymbol;pStopsPoint.SpatialReference=m_hookHelper.ActiveView.FocusMap.SpatialReference;IElementpEle=pMarkerEleasIElement;pEle.Geometry=pStopsPoint;pGrap.AddElement(pEle,1);m_hookHelper.ActiveVie
本文标题:最短路径分析下
链接地址:https://www.777doc.com/doc-2319021 .html