Create a geoprocessing tool to buffer a layer and retrieve messages____sync
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using System.Runtime.InteropServices;
using ESRI.ArcGIS.ADF.BaseClasses;
using ESRI.ArcGIS.ADF.CATIDs;
using ESRI.ArcGIS.Controls;
using ESRI.ArcGIS.Carto;
using ESRI.ArcGIS.esriSystem;
using ESRI.ArcGIS.Geoprocessor;
using ESRI.ArcGIS.Geoprocessing;
using ESRI.ArcGIS.AnalysisTools; namespace GpBufferLayer
{
publicpartialclass BufferDlg : Form
{
//in order to scroll the messages textbox to the bottom we must import this Win32 call
[DllImport("user32.dll")]
privatestaticexternint PostMessage(IntPtr wnd,
uint Msg,
IntPtr wParam,
IntPtr lParam); private IHookHelper m_hookHelper = null;
privateconstuint WM_VSCROLL = 0x0115;
privateconstuint SB_BOTTOM = 7; public BufferDlg(IHookHelper hookHelper)
{
InitializeComponent(); m_hookHelper = hookHelper;
} privatevoid bufferDlg_Load(object sender, EventArgs e)
{
if (null == m_hookHelper || null == m_hookHelper.Hook || 0 == m_hookHelper.FocusMap.LayerCount)
return; //load all the feature layers in the map to the layers combo
IEnumLayer layers = GetLayers();
layers.Reset();
ILayer layer = null;
while ((layer = layers.Next()) != null)
{
cboLayers.Items.Add(layer.Name);
}
//select the first layerif (cboLayers.Items.Count > 0)
cboLayers.SelectedIndex = 0; string tempDir = System.IO.Path.GetTempPath();
txtOutputPath.Text = System.IO.Path.Combine(tempDir,((string)cboLayers.SelectedItem + "_buffer.shp")); //set the default units of the bufferint units = Convert.ToInt32(m_hookHelper.FocusMap.MapUnits);
cboUnits.SelectedIndex = units;
} privatevoid btnOutputLayer_Click(object sender, EventArgs e)
{
//set the output layer
SaveFileDialog saveDlg = new SaveFileDialog();
saveDlg.CheckPathExists = true;
saveDlg.Filter = "Shapefile (*.shp)|*.shp";
saveDlg.OverwritePrompt = true;
saveDlg.Title = "Output Layer";
saveDlg.RestoreDirectory = true;
saveDlg.FileName = (string)cboLayers.SelectedItem + "_buffer.shp"; DialogResult dr = saveDlg.ShowDialog();
if (dr == DialogResult.OK)
txtOutputPath.Text = saveDlg.FileName;
} privatevoid btnBuffer_Click(object sender, EventArgs e)
{
//make sure that all parameters are okaydouble bufferDistance;
double.TryParse(txtBufferDistance.Text, out bufferDistance);
if (0.0 == bufferDistance)
{
MessageBox.Show("Bad buffer distance!");
return;
} if (!System.IO.Directory.Exists(System.IO.Path.GetDirectoryName(txtOutputPath.Text)) ||
".shp" != System.IO.Path.GetExtension(txtOutputPath.Text))
{
MessageBox.Show("Bad output filename!");
return;
} if (m_hookHelper.FocusMap.LayerCount == 0)
return; //get the layer from the map
IFeatureLayer layer = GetFeatureLayer((string)cboLayers.SelectedItem);
if (null == layer)
{
txtMessages.Text += "Layer " + (string)cboLayers.SelectedItem + "cannot be found!\r\n";
return;
} //scroll the textbox to the bottom
ScrollToBottom();
//add message to the messages box
txtMessages.Text += "Buffering layer: " + layer.Name + "\r\n"; txtMessages.Text += "\r\nGet the geoprocessor. This might take a few seconds...\r\n";
txtMessages.Update();
//get an instance of the geoprocessor
Geoprocessor gp = new Geoprocessor();
gp.OverwriteOutput = true;
txtMessages.Text += "Buffering...\r\n";
txtMessages.Update(); //create a new instance of a buffer tool
ESRI.ArcGIS.AnalysisTools.Buffer buffer = new ESRI.ArcGIS.AnalysisTools.Buffer(layer, txtOutputPath.Text, Convert.ToString(bufferDistance) + " " + (string)cboUnits.SelectedItem); //execute the buffer tool (very easy :-))
IGeoProcessorResult results = (IGeoProcessorResult)gp.Execute(buffer, null);
if (results.Status != esriJobStatus.esriJobSucceeded)
{
txtMessages.Text += "Failed to buffer layer: " + layer.Name + "\r\n";
}
txtMessages.Text += ReturnMessages(gp);
//scroll the textbox to the bottom
ScrollToBottom(); txtMessages.Text += "\r\nDone.\r\n";
txtMessages.Text += "-----------------------------------------------------------------------------------------\r\n";
//scroll the textbox to the bottom
ScrollToBottom(); } privatestring ReturnMessages(Geoprocessor gp)
{
StringBuilder sb = new StringBuilder();
if (gp.MessageCount > 0)
{
for (int Count = 0; Count <= gp.MessageCount - 1; Count++)
{
System.Diagnostics.Trace.WriteLine(gp.GetMessage(Count));
sb.AppendFormat("{0}\n", gp.GetMessage(Count));
}
}
return sb.ToString();
} private IFeatureLayer GetFeatureLayer(string layerName)
{
//get the layers from the maps
IEnumLayer layers = GetLayers();
layers.Reset(); ILayer layer = null;
while ((layer = layers.Next()) != null)
{
if (layer.Name == layerName)
return layer as IFeatureLayer;
} returnnull;
} private IEnumLayer GetLayers()
{
UID uid = new UIDClass();
uid.Value = "{40A9E885-5533-11d0-98BE-00805F7CED21}";
IEnumLayer layers = m_hookHelper.FocusMap.get_Layers(uid, true); return layers;
} privatevoid ScrollToBottom()
{
PostMessage((IntPtr)txtMessages.Handle, WM_VSCROLL, (IntPtr)SB_BOTTOM, (IntPtr)IntPtr.Zero);
}
privatevoid btnCancel_Click(object sender, EventArgs e)
{
this.Close();
}
}
}
Create a geoprocessing tool to buffer a layer and retrieve messages____sync的更多相关文章
- How to run a geoprocessing tool
		How to run a geoprocessing tool In this topic Running a geoprocessing tool Toolbox names and namespa ... 
- How to create a freehand tool
		http://forums.esri.com/Thread.asp?c=159&f=1707&t=283694&mc=1 http://blog.sina.com.cn/s/b ... 
- GP(Geoprocessing)服务的发布与调用
		转自:http://www.cnblogs.com/gisangela/archive/2011/01/06/1927702.html 1.什么是GP服务 GP服务是Geoprocessing服务的简 ... 
- ArcGIS Engine环境下创建自定义的ArcToolbox Geoprocessing工具
		在上一篇日志中介绍了自己通过几何的方法合并断开的线要素的ArcGIS插件式的应用程序.但是后来考虑到插件式的程序的配置和使用比较繁琐,也没有比较好的错误处理机制,于是我就把之前的程序封装成一个类似于A ... 
- The Topo to Raster tool returns errors 010235 and 010067转
		Problem: The Topo to Raster tool returns errors 010235 and 010067 Description The Topo to Raster geo ... 
- Caffe源码-Layer类
		Layer类简介 Layer是caffe中搭建网络的基本单元,caffe代码中包含大量Layer基类派生出来的各种各样的层,各自通过虚函数 Forward() 和 Backward() 实现自己的功能 ... 
- 【caffe Layer】代码中文注释
		src/caffe/proto/caffe.proto 中LayerParameter部分 // NOTE // Update the next available ID when you add a ... 
- Sprite(精灵)&& 三个特殊的层Layer
		用来作为以后复习使用. 1 #include "ScenceScend.h" CCScene* ScenceScend::scene() { CCScene* s = CCScen ... 
- Cocos2d-x 3.2 学习笔记(六)Layer
		Layer 游戏中的背景容器,Layer类是Node类的一个子类,它实现了触屏事件代理(TouchEventsDelegate)协议. LayerColor是Layer的一个子类,它实现了RGBAPr ... 
随机推荐
- css background-size
			先来看下语法:background-size: length|percentage|cover|contain;具体的值,百分比都ok,w3c上面说的很清楚,当时具体的值或者百分比的时候,第一个表示宽 ... 
- java的三大框架(二)---Struts2
			Strtu2框架 1.控制器:ActionServlet充当控制层 2.模型层:由ActionForm及业务JavaBean实现 3.视图:用户的看到并与之交互的界面 由struts标签库和jsp ... 
- jQuery 简介
			jQuery 简介 jQuery 库可以通过一行简单的标记被添加到网页中. jQuery 库 - 特性 jQuery 是一个 JavaScript 函数库. jQuery 库包含以下特性: HTML ... 
- System.DateUtils 1. DateOf、TimeOf 简单修饰功能
			编译版本:Delphi XE7 { Simple trimming functions } // 简单修饰功能 function DateOf(const AValue: TDateTime): TD ... 
- HDU-3247 Resource Archiver(AC自动机+BFS)
			Description Great! Your new software is almost finished! The only thing left to do is archiving all ... 
- 【HDU1960】Taxi Cab Scheme(最小路径覆盖)
			Taxi Cab Scheme Time Limit: 5000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)T ... 
- Request.UrlReferrer
			1:Request.UrlReferrer可以获取客户端上次请求的url,这样就可以实现类似“上一页”的功能等 2:刷新当前页面,不会改变Request.UrlReferrer的值 3:如果有A,B两 ... 
- solr6.0.0 + tomcat8 配置问题
			中间件需求: apache-tomcat-8.0.32.tar.gz jdk-8u74-linux-x64.rpm solr-6.0.0.zip 0.安装java JDK rpm -ivh jdk-8 ... 
- ubuntu12.04+Elasticsearch2.3.3伪分布式配置,集群状态分片调整
			目录 [TOC] 1.什么是Elashticsearch 1.1 Elashticsearch介绍 Elasticsearch是一个基于Apache Lucene(TM)的开源搜索引擎.能够快速搜索数 ... 
- IIS性能相关的配置、命令
			IIS性能相关的配置.命令 应用程序池回收 不要使用缺省的“固定时间间隔(分钟)”:1740(即29小时),建议改为0 可以根据实际情况设置特定时间回收,比如凌晨4点 最大工作进程数 可以根据实际情况 ... 
