概述
对于叠置分析,想必用过ArcGIS的同志应该都很了解。ArcGIS的工具箱提供了各种叠置分析的工具,如下图所示:
那么在ArcEngine中该如何实现叠置分析呢?其实ArcEngine已经给我们提供了IBasicGeoprocessor
接口来实现叠置分析,下面就以求两个图层的相交部分来进行说明。
测试数据
叠置分析
代码如下:
using System;
using System.Collections;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Diagnostics;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using ESRI.ArcGIS.Carto;
using ESRI.ArcGIS.Controls;
using ESRI.ArcGIS.DataSourcesFile;
using ESRI.ArcGIS.DataSourcesGDB;
using ESRI.ArcGIS.Display;
using ESRI.ArcGIS.esriSystem;
using ESRI.ArcGIS.Geodatabase;
using ESRI.ArcGIS.Geometry;
using ESRI.ArcGIS.Output;
using ESRI.ArcGIS.SystemUI;
namespace WindowsFormsApplication1
{
public partial class MainForm : Form
{
public MainForm()
{
InitializeComponent();
axMapControl1.LoadMxFile(@"E:UsersdsfDesktop无标题.mxd");
}
private void btn_Click(object sender, EventArgs e)
{
IFeatureClass pSourceFeatureClass = (axMapControl1.get_Layer(0) as IFeatureLayer).FeatureClass;
IFeatureClass pTargetFeatureClass = (axMapControl1.get_Layer(1) as IFeatureLayer).FeatureClass;
IFeatureClass pFeatureClass = Intersect(pSourceFeatureClass, pTargetFeatureClass, @"E:UsersdsfDesktoptest相交.shp");
IFeatureLayer pFeatureLayer = new FeatureLayer();
pFeatureLayer.FeatureClass = pFeatureClass;
pFeatureLayer.Name = pFeatureClass.AliasName;
axMapControl1.AddLayer(pFeatureLayer, 0);
axMapControl1.Refresh();
}
private IFeatureClass Intersect(IFeatureClass pSourceFeatureClass, IFeatureClass pTargetFeatureClass, string filePath)
{
ITable pSourceTable = pSourceFeatureClass as ITable;
ITable pTargetTable = pTargetFeatureClass as ITable;
// IWorkspaceName
IWorkspaceName pWorkspaceName = new WorkspaceName() as IWorkspaceName;
pWorkspaceName.WorkspaceFactoryProgID = "esriDataSourcesGDB.ShapefileWorkspaceFactory";
pWorkspaceName.PathName = System.IO.Path.GetDirectoryName(filePath);
// IFeatureClassName
IFeatureClassName pFeatureClassName = new FeatureClassName() as IFeatureClassName;
pFeatureClassName.ShapeFieldName = "Shape";
pFeatureClassName.ShapeType = esriGeometryType.esriGeometryPolygon;
pFeatureClassName.FeatureType = esriFeatureType.esriFTSimple;
// IDatasetName
IDatasetName pDatasetName = pFeatureClassName as IDatasetName;
pDatasetName.WorkspaceName = pWorkspaceName;
pDatasetName.Name = System.IO.Path.GetFileNameWithoutExtension(filePath);
// 计算相交部分
IBasicGeoprocessor pBasicGeoprocessor = new BasicGeoprocessor();
IFeatureClass pFeatureClass = pBasicGeoprocessor.Intersect(pSourceTable, false, pTargetTable, false, 0.001, pFeatureClassName);
return pFeatureClass;
}
}
}
运行结果如下图所示,黄色区域就是两个图层的相交区域。
最后
以上就是阔达灰狼为你收集整理的ArcEngine中的叠置分析的全部内容,希望文章能够帮你解决ArcEngine中的叠置分析所遇到的程序开发问题。
如果觉得靠谱客网站的内容还不错,欢迎将靠谱客网站推荐给程序员好友。
本图文内容来源于网友提供,作为学习参考使用,或来自网络收集整理,版权属于原作者所有。
发表评论 取消回复