基于C#的ArcEngine二次开发31:addin开发时调用ArcMap的进度条

简介: 基于C#的ArcEngine二次开发31:addin开发时调用ArcMap的进度条

1 在ArcMap中添加进度条

调用此代码会弹出进度条

/// <summary>
/// Launch a Progress Dialog to display how long it is taking to complete some event.
/// </summary>
/// <param name="application">An IApplication interface.</param>
/// <param name="int32_Minimum">A System.Int32 that is the starting point for the progress display. Example: 0</param>
/// <param name="int32_Maximum">A System.Int32 that is the ending point for a progress display. Example: 10000</param>
/// <param name="string_Message">A System.String that is the message you want to user to see. Example: "Parsing Data, Please Wait.</param>
/// <remarks>
/// Calling this sub/method by itself is only half of the programming effort. Inside of the For loop you do something
/// that requires time to progress.
/// </remarks>
public void ShowProgressDialog(ESRI.ArcGIS.Framework.IApplication application, System.Int32 int32_Minimum, System.Int32 int32_Maximum, System.String string_Message)
{
    // Create a CancelTracker
    ESRI.ArcGIS.esriSystem.ITrackCancel trackCancel = new ESRI.ArcGIS.Display.CancelTrackerClass();
    ESRI.ArcGIS.Framework.IProgressDialogFactory progressDialogFactory = new ESRI.ArcGIS.Framework.ProgressDialogFactoryClass();
    // Set the properties of the Step Progressor
    System.Int32 int32_hWnd = application.hWnd;
    ESRI.ArcGIS.esriSystem.IStepProgressor stepProgressor = progressDialogFactory.Create(trackCancel, int32_hWnd);
    stepProgressor.MinRange = int32_Minimum;
    stepProgressor.MaxRange = int32_Maximum;
    stepProgressor.StepValue = 1;
    stepProgressor.Message = string_Message;
    // Create the ProgressDialog. This automatically displays the dialog
    ESRI.ArcGIS.Framework.IProgressDialog2 progressDialog2 = (ESRI.ArcGIS.Framework.IProgressDialog2)stepProgressor; // Explict Cast
    // Set the properties of the ProgressDialog
    progressDialog2.CancelEnabled = true;
    progressDialog2.Description = "Counting to " + int32_Maximum.ToString() + ".";
    progressDialog2.Title = "Counting...";
    progressDialog2.Animation = ESRI.ArcGIS.Framework.esriProgressAnimationTypes.esriDownloadFile;
    // Step. Do your big process here.
    System.Boolean boolean_Continue = false;
    boolean_Continue = true;
    System.Int32 i = 0;
    for (i = int32_Minimum; i <= int32_Maximum; i++)
    {
        ESRI.ArcGIS.esriSystem.IStatusBar statusBar = application.StatusBar;
        statusBar.set_Message(0, i.ToString());
        //TODO:
        //Ideally you would call another sub/function/method from here to do the
        //work. For example read all files of a specified types on disk, loop
        //through a recordset, etc.
        //...
        //Check if the cancel button was pressed. If so, stop process
        boolean_Continue = trackCancel.Continue();
        if (!boolean_Continue)
        {
            break;
        }
    }
    // Done
    trackCancel = null;
    stepProgressor = null;
    progressDialog2.HideDialog();
    progressDialog2 = null;
}

2 在状态栏显示默认默认动画

调用此代码,会在状态栏中显示不断转动的小地球

Play the default animation progressor on the status bar while messages are shown

/// <summary>
/// Play the default animation progressor on the status bar while messages are shown.
/// </summary>
/// <param name="application">An IApplication interface.</param>
/// <param name="stopLoop">An Int32 that is the ending counter in the loop to display in the animation progressor. Example: 30000</param>
/// <remarks>The status bar gives users an indication that the appplication is processing.</remarks>
public void AnimationProgressor(ESRI.ArcGIS.Framework.IApplication application, System.Int32 stopLoop)
{
    ESRI.ArcGIS.esriSystem.IStatusBar statusBar = application.StatusBar;
    ESRI.ArcGIS.esriSystem.IAnimationProgressor animationProgressor = statusBar.ProgressAnimation;
    animationProgressor.Show();
    animationProgressor.Play(0, -1, -1);
    System.Int32 iteration = 0;
    for (iteration = 0; iteration <= stopLoop; iteration++)
    {
        // TODO: Add your code here to do things like: read or copy files, draw point moving on the screen, etc.
        // ...
        statusBar.set_Message(0, "Counting..." + iteration.ToString());
    }
    animationProgressor.Stop();
    animationProgressor.Hide();
}

3 其他工具

3.1 加入Identify工具

///<summary>Performs an identify (via the Identify Dialog) on the layers in the Active View.</summary>
///
///<param name="activeView">An IActiveView interface</param>
///<param name="x">An System.Int32 in device (screen) coordinates. Example: 300</param>
///<param name="y">An System.Int32 in device (screen) coordinates. Example: 100</param>
/// 
///<remarks></remarks>
public void DoIdentify(ESRI.ArcGIS.Carto.IActiveView activeView, System.Int32 x, System.Int32 y)
{
  if(activeView == null)
  {
    return;
  }
  ESRI.ArcGIS.Carto.IMap map = activeView.FocusMap;
  ESRI.ArcGIS.CartoUI.IIdentifyDialog identifyDialog = new ESRI.ArcGIS.CartoUI.IdentifyDialogClass();
  identifyDialog.Map = map;
  //Clear the dialog on each mouse click
  identifyDialog.ClearLayers();
  ESRI.ArcGIS.Display.IScreenDisplay screenDisplay = activeView.ScreenDisplay;
  ESRI.ArcGIS.Display.IDisplay display = screenDisplay; // Implicit Cast
  identifyDialog.Display = display;
  ESRI.ArcGIS.CartoUI.IIdentifyDialogProps identifyDialogProps = (ESRI.ArcGIS.CartoUI.IIdentifyDialogProps)identifyDialog; // Explicit Cast
  ESRI.ArcGIS.Carto.IEnumLayer enumLayer = identifyDialogProps.Layers;
  enumLayer.Reset();
  ESRI.ArcGIS.Carto.ILayer layer = enumLayer.Next();
  //
  while (!(layer == null))
  {
    identifyDialog.AddLayerIdentifyPoint(layer, x, y);
    layer = enumLayer.Next();
  }
  identifyDialog.Show();
}

后期考虑实现自己动手实现ArcMap的Identify功能+附源码的功能,

aHR0cDovL3d3dy5naXNza3kubmV0L0FydGljbGUvVXBsb2FkRmlsZXMvMjAxMDAyLzIwMTAwMjAxMDkwNzE2MjMuYm1w.png

aHR0cDovL3d3dy5naXNza3kubmV0L0FydGljbGUvVXBsb2FkRmlsZXMvMjAxMDAyLzIwMTAwMjAxMDkwNzE2MjEuZ2lm.gif

aHR0cDovL3d3dy5naXNza3kubmV0L0FydGljbGUvVXBsb2FkRmlsZXMvMjAxMDAyLzIwMTAwMjAxMDkwNzE2MjEuZ2lm.gif

3.2 为选中特征建立缓冲区

///<summary>Draws graphic buffers around the selected features in the map using distance units specified.</summary>
///
///<param name="activeView">An IActiveView interface.</param>
///<param name="distance">A System.Double that is the distance in map units around the select features to draw a graphic buffer. Example: 10</param>
/// 
///<remarks></remarks>
public void CreateGraphicBuffersAroundSelectedFeatures(ESRI.ArcGIS.Carto.IActiveView activeView, System.Double distance)
{
  //parameter check
  if (activeView == null || distance < 0)
  {
    return;
  }
  ESRI.ArcGIS.Carto.IMap map = activeView.FocusMap;
  // Clear any previous buffers from the screen
  ESRI.ArcGIS.Carto.IGraphicsContainer graphicsContainer = (ESRI.ArcGIS.Carto.IGraphicsContainer)map; // Explicit Cast
  graphicsContainer.DeleteAllElements();
  // Verify there is a feature(s) selected
  if (map.SelectionCount == 0)
  {
    return;
  }
  // Reset to the first selected feature
  ESRI.ArcGIS.Geodatabase.IEnumFeature enumFeature = (ESRI.ArcGIS.Geodatabase.IEnumFeature)map.FeatureSelection; // Explicit Cast
  enumFeature.Reset();
  ESRI.ArcGIS.Geodatabase.IFeature feature = enumFeature.Next();
  // Buffer all the selected features by the buffer distance and create a new polygon element from each result
  ESRI.ArcGIS.Geometry.ITopologicalOperator topologicalOperator;
  ESRI.ArcGIS.Carto.IElement element;
  while (!(feature == null))
  {
    topologicalOperator = (ESRI.ArcGIS.Geometry.ITopologicalOperator)feature.Shape; // Explicit Cast
    element = new ESRI.ArcGIS.Carto.PolygonElementClass();
    element.Geometry = topologicalOperator.Buffer(distance);
    graphicsContainer.AddElement(element, 0);
    feature = enumFeature.Next();
  }
  activeView.PartialRefresh(ESRI.ArcGIS.Carto.esriViewDrawPhase.esriViewGraphics, null, null);
}

获取当前视图下选择的要素:

                    IEnumFeature feaSelection = ArcMap.Document.FocusMap.FeatureSelection as IEnumFeature;
                    IEnumFeatureSetup enumFeatureSetup = feaSelection as IEnumFeatureSetup;
                    enumFeatureSetup.AllFields = true; //返回的包含所有要素字段
                    IFeature feature = feaSelection.Next();
                    IFeature feature = feaSelection.Next();
                    while (feature != null)
                    {
                      //....
                        feature = feaSelection.Next();
                    }
                    feaSelection.Reset();
                    ArcMap.Document.FocusMap.ClearSelection();
相关文章
|
11月前
|
XML 测试技术 API
利用C#开发ONVIF客户端和集成RTSP播放功能
利用C#开发ONVIF客户端和集成RTSP播放功能
4976 123
|
物联网 数据处理 C#
C#实现上位机开发,串口通信,读写串口数据并处理16进制数据
C#实现上位机开发,串口通信,读写串口数据并处理16进制数据。在自动化、物联网以及工业控制行业中,上位机开发是一项重要的技能。本教程主要介绍使用C#进行上位机开发,重点在于串口通信和数据处理。
3029 82
|
前端开发 JavaScript 安全
C#一分钟浅谈:Blazor WebAssembly 开发
Blazor WebAssembly 是一个客户端框架,允许开发者使用C#和Razor语法构建Web应用。本文介绍了Blazor WebAssembly的基本概念、常见问题及解决方案,包括路由配置、数据绑定、异步操作、状态管理和性能优化等方面的内容,并分享了一些易错点及如何避免的方法。希望这些内容能帮助你在Blazor WebAssembly开发中少走弯路,提高开发效率。
590 51
|
SQL 小程序 API
如何运用C#.NET技术快速开发一套掌上医院系统?
本方案基于C#.NET技术快速构建掌上医院系统,结合模块化开发理念与医院信息化需求。核心功能涵盖用户端的预约挂号、在线问诊、报告查询等,以及管理端的排班管理和数据统计。采用.NET Core Web API与uni-app实现前后端分离,支持跨平台小程序开发。数据库选用SQL Server 2012,并通过读写分离与索引优化提升性能。部署方案包括Windows Server与负载均衡设计,确保高可用性。同时针对API差异、数据库老化及高并发等问题制定应对措施,保障系统稳定运行。推荐使用Postman、Redgate等工具辅助开发,提升效率与质量。
678 0
|
缓存 算法 安全
精选10款C#/.NET开发必备类库(含使用教程),工作效率提升利器!
精选10款C#/.NET开发必备类库(含使用教程),工作效率提升利器!
801 12
|
缓存 C# 开发者
C# 一分钟浅谈:Blazor Server 端开发
本文介绍了 Blazor Server,一种基于 .NET 的 Web 开发模型,允许使用 C# 和 Razor 语法构建交互式 Web 应用。文章从基础概念、创建应用、常见问题及解决方案、易错点及避免方法等方面详细讲解,帮助开发者快速上手并提高开发效率。
589 2
|
开发框架 缓存 .NET
C# 一分钟浅谈:Blazor Server 端开发
Blazor Server 是基于 ASP.NET Core 的框架,允许使用 C# 和 Razor 语法构建交互式 Web 应用。本文介绍 Blazor Server 的基本概念、快速入门、常见问题及解决方案,帮助开发者快速上手。涵盖创建应用、基本组件、数据绑定、状态管理、跨组件通信、错误处理和性能优化等内容。
1134 1
|
测试技术 Go C#
C#一分钟浅谈:ReSharper 插件增强开发效率
【10月更文挑战第25天】ReSharper 是 JetBrains 开发的一款 Visual Studio 插件,旨在提高 .NET 开发者的生产力。它通过代码分析、重构、导航等功能,帮助开发者避免常见错误,提升代码质量和开发效率。本文将通过具体代码案例,详细介绍 ReSharper 的常见功能及其应用。
1303 1
|
C# Python
使用wxpython开发跨平台桌面应用,对wxpython控件实现类似C#扩展函数处理的探究
【10月更文挑战第30天】使用 `wxPython` 开发跨平台桌面应用时,可以通过创建辅助类来模拟 C# 扩展函数的功能。具体步骤包括:1. 创建辅助类 `WxWidgetHelpers`;2. 在该类中定义静态方法,如 `set_button_color`;3. 在应用中调用这些方法。这种方法提高了代码的可读性和可维护性,无需修改 `wxPython` 库即可为控件添加自定义功能。但需要注意显式调用方法和避免命名冲突。
323 1
|
JSON C# 开发者
C#语言新特性深度剖析:提升你的.NET开发效率
【10月更文挑战第15天】C#语言凭借其强大的功能和易用性深受开发者喜爱。随着.NET平台的演进,C#不断引入新特性,如C# 7.0的模式匹配和C# 8.0的异步流,显著提升了开发效率和代码可维护性。本文将深入探讨这些新特性,助力开发者在.NET开发中更高效地利用它们。
335 1