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 ...
随机推荐
- Java第八周学习总结
20145113第八周学习总结 第十五章学习内容 第15章比较琐碎,相对于之前章节也比较枯燥无味看了一部分,也动手敲了些 Logger logger = Logger.getLogger(" ...
- HttpClientUtil简介
使用HttpClient发送请求.接收响应. http协议可以说是现在Internet上面最重要,使用最多的协议之一了,越来越多的java应用需要使用http协议来访问网络资源,HttpClient ...
- 【jQuery plug-in】DataTables
1. DOM Position dataTableOption.dom = '<"top"<"pull-left"l><"pu ...
- Servlet中The requested resource is not available错误
自己为了测试servlet,用MyEclipse2015写了一个简单的登录程序. 1.登录页面index.jsp. <%@ page language="java" impo ...
- CSS中的class与id区别及用法
转自http://www.divcss5.com/rumen/r3.shtml及http://www.jb51.net/css/35927.html 我们平常在用DIV CSS制作Xhtml网页页面时 ...
- servlet有关概念
关于servlet的概念 URL.URN与URi HTTP GET请求,POST请求(区别.适用) 编码 动态网页(GCI.PHP.ASP.JSP等)与静态网页 Model2 静态网页:指的是请求服务 ...
- PHP foreach使用
<?php $arr = array("1"=>"100","2"=>"200","3&qu ...
- javascript——Array
# js数组分为属性和方法 ## 属性 1.constructor返回对创建此对象的数组函数的引用. 这个其实在javascript中的对象都有 var a = [] console.log(a.co ...
- About SSDT BI
Welcome to Microsoft Marketing Speak hell. With the 2012 release of SQL Server, the BIDS, Business I ...
- 前端 动态表单提交(post、put)
第一步:form表单定义统一属性 <input type="text" class="form-value" /> 第二步:获取所有值 var fo ...