ArcGIS_Engine二次开发讲义
- 格式:pdf
- 大小:6.30 MB
- 文档页数:62


arcgisengine 圆弧处理ArcGIS Engine是一款功能强大的地理信息系统(GIS)开发平台,它提供了丰富的地理空间分析和处理工具,其中包括圆弧处理功能。
圆弧处理是GIS中常用的一种空间分析方法,用于处理和分析曲线形状的空间数据。
本文将详细介绍ArcGIS Engine中的圆弧处理功能及其应用。
我们需要了解什么是圆弧。
在地理空间分析中,圆弧是由一系列点组成的曲线,它可以用来表示地球上的道路、河流、边界等。
而圆弧处理则是对这些曲线进行各种操作和分析的过程。
ArcGIS Engine提供了丰富的圆弧处理功能,包括圆弧生成、圆弧拟合、圆弧插值等。
其中最常用的是圆弧生成功能,它可以根据给定的点集生成圆弧。
例如,我们可以通过给定的三个点来生成一个圆弧,这个圆弧可以用来表示一条道路或河流的曲线形状。
除了圆弧生成,ArcGIS Engine还提供了圆弧拟合功能。
当我们有一条曲线,但不确定它是由多个圆弧组成的时候,可以使用圆弧拟合功能来估计曲线的圆弧参数。
这样可以更好地描述曲线的形状,方便后续的分析和处理。
ArcGIS Engine还提供了圆弧插值功能。
在某些情况下,我们可能需要在已有的圆弧之间插入新的点,使得整条曲线更加平滑。
圆弧插值功能可以根据已有的圆弧和插入点的位置,生成一条新的圆弧,从而实现曲线的平滑化。
除了这些基本的圆弧处理功能,ArcGIS Engine还提供了许多其他的圆弧分析工具,如圆弧长度计算、圆弧与直线的交点计算等。
这些工具可以帮助我们更好地理解和分析曲线形状的空间数据。
在实际应用中,圆弧处理在许多领域都有广泛的应用。
例如,在交通规划中,我们可以使用圆弧处理来生成道路的曲线形状,从而更好地模拟车辆行驶的轨迹。
在地图绘制中,我们可以使用圆弧插值功能来平滑地图上的道路、河流等曲线要素,使得地图更加美观。
在地理空间分析中,我们可以使用圆弧拟合功能来估计曲线的圆弧参数,从而更好地理解和分析曲线的形状。
专题:认识ArcGIS EngineArcGIS Engine环境介绍ArcGIS Engine示例与开发帮助用ArcGIS Engine定制ArcMap【实现ArcMap中的Command;通过ArcGIS Engine访问ArcMap接口;透过对象、接口了解ArcMap的结构】ArcGIS Engine开发帮助的使用实验:通过ArcGIS Engine开发帮助的使用,学习完成ArcGIS命令、工具的定制●参考实例:Creating a custom tool●主要内容:⏹ArcGIS Engine中的ICommand, ITool接口⏹ArcGIS Engine中的工程向导:建立类工程,添加继承ICommand, ITool接口的类⏹实现接口中的属性、方法⏹编译,把工具添加到工具栏或菜单中⏹实验:完成Creating a custom tool实例Creating a custom toolCreating custom commands and tools to work with the MapControl and PageLayoutControl is very much like creating commands for the ESRI ArcMap application that you may have done previously. You will create a custom tool that adds a text element containing today's date to the PageLayoutControl at the location of a mouse click. You will, however, create the command to work with the MapControl and ToolbarControl as well as the PageLayoutControl.1.Click on the File menu and click Add New Project.2.Click the Class Library template from the ArcGIS Engine category. Name the project'Commands' and click OK.3.In the ArcGIS Project Wizard double click ESRI.ArcGIS.Carto, ESRI.ArcGIS.Displayand ESRI.ArcGIS.Geometry to select them. Click Finish.4.Delete Class1 from the Commands project.5.Click on the Project menu and click Add New Item to add a new item to the Commandsproject.6.Click the 'Base Tool' template from the ArcGIS Engine category in the Add New Itemdialog box. the tool 'AddDateTool' and click Add to add it to the project.8.Click the 'ArcMap, MapControl or PageLayoutControl Tool' from the ArcGIS New ItemWizard Options dialog box and click OK.The AddDateTool class inherits from the ESRI BaseTool abstract class. Abstract classes are classes that cannot be instantiated and frequently contain only partial implementation code or no implementation at all. They are closely related to interfaces; however, they differ significantly from interfaces in that a class may implement any number of interfaces, but it can inherit from only one abstract class. Inheriting the ESRI BaseCommand and BaseTool abstract classes will allow you to create commands and tools more quickly and simply than directly implementing the esriSystemUI ICommand and ITool interfaces.The sealed class modifier in C# and the NotInheritable modifier in states that a class cannot be inherited from. As this class is not designed for this purpose, it is prudent to add this modifier to prevent other classes from inheriting this class.9.Add the following additional "using" directives or "import statements" to the class:[C#]using ESRI.ArcGIS.Carto;using ESRI.ArcGIS.Display;using ESRI.ArcGIS.Geometry;[]Imports ESRI.ArcGIS.CartoImports ESRI.ArcGIS.DisplayImports ESRI.ArcGIS.Geometry10.Updated the code in the AddDateTool class constructor as follows:The class constructor is a method that is called when the class is created. It can be used to set up members of the class. In C# the constructor method has the same name as the class. It differs from other methods in that it has no return type.Instead of implementing the Bitmap, Caption, Category, Name, Message, and ToolTip methods individually, you can set the values that should be returned from these methods and rely on the BaseTool class to provide the implementation for these methods. The other members will be left to return the default values as implemented by the BaseTool class.[C#]public AddDateTool(){base.m_category = "CustomMapViewer";base.m_caption = "Add Date";base.m_message = "Adds a date element to the active view";base.m_toolTip = "Add Date";base.m_name = "CustomMapViewer_AddDateTool";try{string bitmapResourceName = GetType().Name + ".bmp";base.m_bitmap = new Bitmap(GetType(), bitmapResourceName);base.m_cursor = new Cursor(GetType(), GetType().Name + ".cur");}catch (Exception ex){System.Diagnostics.Trace.WriteLine(ex.Message, "Invalid Bitmap");}}[]Public Sub New()MyBase.New()MyBase.m_category = "CustomMapViewer"MyBase.m_caption = "Add Date"MyBase.m_message = "Adds a date element to the active view"MyBase.m_toolTip = "Add Date"MyBase.m_name = "CustomMapViewer_AddDateTool"TryDim bitmapResourceName As String = Me.GetType().Name + ".bmp"MyBase.m_bitmap = New Bitmap(Me.GetType(), bitmapResourceName)MyBase.m_cursor = New Cursor(Me.GetType(), Me.GetType().Name + ".cur") Catch ex As ExceptionSystem.Diagnostics.Trace.WriteLine(ex.Message, "Invalid Bitmap") End TryEnd Sub11.Navigate to the overridden OnCreate method and look at the code.The ICommand_OnCreate method is passed a handle or hook to the application that the command will work with. In this case it can be a MapControl, PageLayoutControl, ToolbarControl, or the ArcMap application. Rather than adding code into the OnCreate method to determine the type of hook that is being passed to the command, the HookHelper is used to handle this. A command or tool needs to know how to handle the hook it gets passed, so a check is needed to determine the type of ArcGIS Engine Control that has been passed. The HookHelper is used to hold the hook and return the ActiveView regardless of the type of hook (in this case a MapControl, PageLayoutControl, ToolbarControl or ArcMap).12.Navigate to the overridden OnMouseDown event and add the following code:[C#]public override void OnMouseDown(int Button, int Shift, int X, int Y){//Get the active viewIActiveView activeView = m_hookHelper.ActiveView;//Create a new text elementITextElement textElement = new TextElementClass();//Create a text symbolITextSymbol textSymbol = new TextSymbolClass();textSymbol.Size = 25;//Set the text element propertiestextElement.Symbol = textSymbol;textElement.Text = DateTime.Now.ToShortDateString();//QI for IElementIElement element = (IElement) textElement;//Create a pointIPoint point = new PointClass();point = activeView.ScreenDisplay.DisplayTransformation.ToMapPoint(X,Y);//Set the elements geometryelement.Geometry = point;//Add the element to the graphics containeractiveView.GraphicsContainer.AddElement(element, 0);//Refresh the graphicsactiveView.PartialRefresh(esriViewDrawPhase.esriViewGraphics, null, null);}[]Public Overrides Sub OnMouseDown(ByVal Button As Integer, ByVal Shift As Integer, ByVal X As Integer, ByVal Y As Integer)'Get the active viewDim pActiveView As IActiveView = m_hookHelper.ActiveView'Create a new text elementDim pTextElement As ITextElement = New TextElementClass'Create a text symbolDim pTextSymbol As ITextSymbol = New TextSymbolClasspTextSymbol.Size = 25'Set the text element propertiespTextElement.Symbol = pTextSymbolpTextElement.Text = Date.Now.ToShortDateString'QI for IElementDim pElement As IElementpElement = pTextElement'Create a pointDim pPoint As IPointpPoint = pActiveView.ScreenDisplay.DisplayTransformation.ToMapPoint(X, Y) 'Set the elements geometrypElement.Geometry = pPoint'Add the element to the graphics containerpActiveView.GraphicsContainer.AddElement(pTextElement, 0)'Refresh the graphicspActiveView.PartialRefresh(esriViewDrawPhase.esriViewGraphics, Nothing, Nothing)End SubThe ArcGIS Engine expects a custom command or tool to be a COM class; therefore the .NET class you have created must be exposed as a COM class by creating a COM callable wrapper for it. The BaseTool has already provided the attributes and GUIDs required by COM in the class.The Commands project properties have also been automatically amended to set 'Register for COM Interop' to True. Setting the Register for COM Interop property to True will invoke the Assembly Registration Tool (Regasm.exe). This will add the information about the class to the registry that a COM client would expect to find.Visual Studio .NET provides the ability to specify functions that execute when an assembly exposed for COM interop is registered and unregistered on a system. This allows you to register your class in a component category that the Customize Dialog box will look for. The BaseTool has already provided these COM Registration Functions in the class and will register the tool with the 'ESRI Controls Commands' and 'ESRI Mx Commands' component categories. Note, the ComVisible attribute is set to false to ensure that this method cannot be called directly by a COM client. It does not affect the method being called when the assembly is registered with COM.13.Build the Commands project.14.In the Controls Windows Application project that you created at the beginning of thisscenario, add the following code before the ToolbarPalette code.[C#]private void MapViewer_Load(object sender, EventArgs e){//Add map inquiry commands//Add custom AddDateToolaxToolbarControl1.AddItem("Commands.AddDateTool", -1, -1, false, 0, esriCommandStyles.esriCommandStyleIconAndText);//Create a new ToolbarPalette}[]Private Sub MapViewer_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load'Add map inquiry commands'Add custom AddDateToolAxToolbarControl1.AddItem("Commands.AddDateTool", -1, -1, False, 0, esriCommandStyles.esriCommandStyleIconAndText)'Create a new ToolbarPaletteEnd Sub15.Build and run the Controls project.。