AE开发示例之GPBufferLayer
using System;
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
{
public partial class BufferDlg : Form
{
//in order to scroll the messages textbox to the bottom we must import this Win32 call
[DllImport("user32.dll")]
private static extern int PostMessage(IntPtr wnd,
uint Msg,
IntPtr wParam,
IntPtr lParam);
private IHookHelper m_hookHelper = null;
private const uint WM_VSCROLL = 0x0115;
private const uint SB_BOTTOM = 7;
public BufferDlg(IHookHelper hookHelper)
{
InitializeComponent();
m_hookHelper = hookHelper;
}
private void 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 layer
if (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 buffer
int units = Convert.ToInt32(m_hookHelper.FocusMap.MapUnits);
cboUnits.SelectedIndex = units;
}
private void 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;
}
private void btnBuffer_Click(object sender, EventArgs e)
{
//make sure that all parameters are okay
double 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();
}
private string 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;
}
return null;
}
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;
}
private void ScrollToBottom()
{
PostMessage((IntPtr)txtMessages.Handle, WM_VSCROLL, (IntPtr)SB_BOTTOM, (IntPtr)IntPtr.Zero);
}
private void btnCancel_Click(object sender, EventArgs e)
{
this.Close();
}
}
}
AE开发示例之GPBufferLayer的更多相关文章
- AE开发示例之RunGPAsync
using System; using System.Collections.Generic;using System.ComponentModel;using System.Data;using S ...
- Github团队开发示例(二)
Github团队开发示例(二) 作者:Grey 原文地址:http://www.cnblogs.com/greyzeng/p/6063765.html 接之前讲的Github团队开发示例(一),本文主 ...
- Github团队开发示例(一)
Github团队开发示例(二) 作者:Grey 原文地址:http://www.cnblogs.com/greyzeng/p/6044837.html 我们可以在Github上管理自己的团队项目.团队 ...
- AE开发使用内存图层
AE开发中,有时需要从磁盘中读取一些文件信息如坐标点转为图层并进行分析,此过程并不需要坐标点入库之类的操作,就可以创建一个内存图层解决问题.创建内存图层需要用到InMemoryWorkspaceFac ...
- AE开发能否实现TOC Control里添加多个Data Frame
问题: 在ArcMap中,菜单Insert下Data Frame,可以在TOC中增加Data Frame,在MapControl或者PageLayoutControl下都可以正常显示多个Data Fr ...
- DevExpress .NET界面开发示例大全
说到做.net界面开发,很多人应该都会想到DevExpress. 它的 .net界面开发系列一共有7个版本:WinForms.ASP.NET.MVC.WPF.Silverlight.Windows 8 ...
- Padrino 博客开发示例
英文版出处:http://www.padrinorb.com/guides/blog-tutorial 楼主按 拿作者自己的话说:Padrino(谐音:派骓诺)是一款基于Sinatra的优雅的Web应 ...
- TWaver Flex开发示例及license下载
做电信项目的朋友一定知道TWaver,而Flex版具有很好的跨平台性,很适合做B/S模式的应用. Flex版的在线DEMO:http://twaver.servasoft.com/demo/twave ...
- NPAPI火狐插件VS2013开发示例
NPAPI火狐插件VS2013开发示例 下面是我根据网上开发示例自己做的一个demo,并提供代码下载. 开发环境 Windows 8.1 x64 Visual studio 2013 准备工作 首先需 ...
随机推荐
- springMVC 返回json 忽略类中属性的注解
该注解使用在 类名,接口头上 @JsonIgnoreProperties(value={"comid"}) //希望动态过滤掉的属性 该注解使用在get方法头上 @JsonIgno ...
- CentOS上yum安装JDK
转: http://blog.csdn.net/onepiecehuiyu/article/details/17189571
- IT励志与指导文章合集(链接)
乔布斯在斯坦福大学的演讲 http://www.cnblogs.com/tryingx/p/3715886.html 程序员的8个级别 http://www.cnblogs.com/tryingx/p ...
- visual studio 的Error List 显示乱码
复制到右键菜单如下: Severity Code Description Project File LineError 閿欒: 绋嬪簭鍖卌om.baidu.lbsapi.auth涓嶅瓨鍦? com. ...
- Unity 脚本生命周期流程图
渲染 OnPreCull: 在相机剔除场景之前调用此函数.相机可见的对象取决于剔除.OnPreCull 函数调用发生在剔除之前. OnBecameVisible/OnBecameInvisible: ...
- 如何在 IDEA 中使用Maven 及 相应插件
1,Maven 面板 Root ,相当于 VS 中的 sln ? ,大概可以这样理解吧. clean --> install 这样操作, 所有的项目都会被执行. 手工操作有点麻烦.换另一种方 ...
- 简单配置和使用Maven
1,下载Maven 从:https://maven.apache.org/download.cgi 其实两个都一样, 2,安装过程 解压你下载的包,随意放哪里都可以 ,假设 我放在了 D:\JavaT ...
- nginx 反向代理TCP mysql
stream {upstream mysql { hash $remote_addr consistent; server 10.26.112.12:3306 max_fails=3 fail_tim ...
- 在Linux操作系统下备份恢复技术的应用 转自https://yq.aliyun.com/articles/50205?spm=5176.100239.blogcont24250.9.CfBYE9
摘要: 安全防护:在Linux操作系统下备份恢复技术的应用 原文参见:http://linux.chinaunix.net/techdoc/system/2005/12/19/925898.shtm ...
- cuda-convnet windows8下编译
编译环境: windows8.1 Anaconda python2.7 Visual studio 2012 CUDA6.0 Pthread for windows Intel Math Kernel ...