目录
目录
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功能+附源码的功能,
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();
欢迎关注个人公众号: