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 准备工作 首先需 ...
随机推荐
- python3 filter用法(举例求0~n之间的素数)
在用python3求0~n之间的素数时,关于filter用法的有点模糊,于是上网查了一下filter用法. 求0~n之间素数的脚本prime.py: def f(x): plist = [0,0] + ...
- 第六章第一个linux个程序:统计单词个数
第六章第一个linux个程序:统计单词个数 从本章就开始激动人心的时刻——实战,去慢慢揭开linux神秘的面纱.本章的实例是统计一片文章或者一段文字中的单词个数. 第 1 步:建立 Linu x 驱 ...
- JUnit报错需导入两个jar包
<dependency> <groupId>org.hamcrest</groupId> <artifactId>hamcrest-core</a ...
- CE取系统时间值
取时间值: void GetTime() { //取时间值 SYSTEMTIME st = {}; // 时间结构体 GetLocalTime(&st); // 把获取的系统时间信息存储到SY ...
- PCB的过孔
在走多层板时,经常需要打过孔,那么过孔是怎么分类的呢?且往下看. (1)通孔:这种孔穿过整个线路板,可以用于内部互连或者作为元件的安装定位孔(用于连接层:生成钻孔文件,在PCB上打孔并在孔内电镀:通常 ...
- linux修改mysql密码
以root为列. 查看文件安装路径whereis mysql 查询运行文件所在路径(文件夹地址) which mysql /usr/bin/mysqld_safe: line 178: 5930 ...
- tomcat从 http转成https,并且去掉端口号
将 <Connector port=" URIEncoding="UTF-8"/> 改成 <Connector port=" URIEncod ...
- [2016.08.09]文本替换专家 v5.2
软件名称:文本替换专家最新版本:v5.2软件授权:共享软件发布日期:2016.01.18文件大小:650KB操作系统:XP/2003/Win7/Win2008开发人员:胡洪祥版权所有:胡洪祥
- APP跳到系统设置
//定位服务设置界面 NSURL *url = [NSURL URLWithString:@"prefs:root=LOCATION_SERVICES"]; if ([[UIApp ...
- SSIS 文件系统任务无法使用变量配置目标路径
SSIS 文件系统任务无法使用变量配置目标路径 需求: 在SSIS2012中,某个从平面文件导入数据的包中,需要把处理出错的文件拷贝到一个专门的文件夹,便于管理人员及时处理. 问题描述: 1. 在包参 ...