ArcGIS Engine 图层裁剪 Clip的实现方法
方法一, 图层对图层裁剪,输出图层
ILayer pLayer;
IFeatureLayer pFeatureLayer;
IFeatureClass pFeatureClass;
IWorkspaceName pNewWSName;
IBasicGeoprocessor pBasicGeop;
IFeatureClassName pFeatureClassName;
IDatasetName pDatasetName;
IFeatureClass pOutputFeatureClass;
IFeatureLayer pOutputFeatureLayer;
ITable pinputTable, pclipTable;
//定义输出图层的FIELD表
pLayer = this.axMapControl1.get_Layer(0);
pinputTable = (ITable)pLayer;
pFeatureLayer = (IFeatureLayer)pLayer;
pFeatureClass = pFeatureLayer.FeatureClass;
IGeoFeatureLayer pGeoFeatureLayer = pLayer as IGeoFeatureLayer;
IFeatureRenderer pFeatureRenderer = pGeoFeatureLayer.Renderer;
//定义相交图层(面)
pLayer = this.axMapControl1.get_Layer(1);
pclipTable = (ITable)pLayer;
//输出文件类型
pFeatureClassName = new FeatureClassNameClass();
pFeatureClassName.FeatureType = esriFeatureType.esriFTSimple;
pFeatureClassName.ShapeFieldName = "Shape";
pFeatureClassName.ShapeType = pFeatureClass.ShapeType;
//输出图层的名称和位置
saveFileDialog1.Filter = "shapefile文件(*.shp)|*.shp";
saveFileDialog1.InitialDirectory = @"C:\";
DialogResult pDialogRuselt = saveFileDialog1.ShowDialog();
if (pDialogRuselt != DialogResult.OK)
return;
string pPath = saveFileDialog1.FileName;
string pFolder = System.IO.Path.GetDirectoryName(pPath);
string pFileName = System.IO.Path.GetFileName(pPath);
pNewWSName = new WorkspaceNameClass();
pNewWSName.WorkspaceFactoryProgID = "esriDataSourcesFile.ShapefileWorkspaceFactory";
pNewWSName.PathName = pFolder;
pDatasetName = (IDatasetName)pFeatureClassName;
pDatasetName.Name = pFileName;
pDatasetName.WorkspaceName = pNewWSName;
pBasicGeop = new BasicGeoprocessorClass();
pOutputFeatureClass = pBasicGeop.Clip(pinputTable, false, pclipTable, false, 0.0001, pFeatureClassName);
pOutputFeatureLayer = new FeatureLayerClass();
pOutputFeatureLayer.FeatureClass = pOutputFeatureClass;
pOutputFeatureLayer.Name = pOutputFeatureClass.AliasName;
IGeoFeatureLayer pGeoFeatureLayer2 = pOutputFeatureLayer as IGeoFeatureLayer;
pGeoFeatureLayer.Renderer = pFeatureRenderer;
IFeatureCursor pFeatureCursor=pGeoFeatureLayer.Search(null,false);
if (pFeatureRenderer.CanRender(pOutputFeatureClass,new SimpleDisplayClass()))
{
pFeatureRenderer.Draw(pFeatureCursor, esriDrawPhase.esriDPGeography, new SimpleDisplayClass(), new TrackCancelClass());
}
this.axMapControl1.AddLayer(pOutputFeatureLayer as ILayer, 0);
方法二,图层对图层裁剪,输出图层:
IFeatureLayer pFeatureLayer;
IFeatureClass inputfeatureclass;
IFeatureClass cliplayerClass;
//定义输出图层
pFeatureLayer = this.axMapControl1.get_Layer(0) as IFeatureLayer ;
inputfeatureclass = pFeatureLayer.FeatureClass;
//定义相交图层(面)
pFeatureLayer = this.axMapControl1.get_Layer(1 ) as IFeatureLayer ;
cliplayerClass = pFeatureLayer.FeatureClass;
//输出图层的名称和位置
saveFileDialog1.Filter = "shapefile文件(*.shp)|*.shp";
saveFileDialog1.InitialDirectory = @"C:\";
DialogResult pDialogRuselt = saveFileDialog1.ShowDialog();
if (pDialogRuselt != DialogResult.OK)
return;
string pPath = saveFileDialog1.FileName;
string pFolder = System.IO.Path.GetDirectoryName(pPath);
string pFileName = System.IO.Path.GetFileName(pPath);
IFeatureWorkspace pFWS;
IWorkspaceFactory pWorkspaceFactor = new ShapefileWorkspaceFactoryClass();
pFWS = pWorkspaceFactor.OpenFromFile(pFolder, 0) as IFeatureWorkspace;
IFeatureClass outfeatureclass = pFWS.CreateFeatureClass(pFileName,
inputfeatureclass.Fields , null, null, esriFeatureType.esriFTSimple, "Shape", "");
Clip clipTool =new Clip(inputfeatureclass, cliplayerClass, outfeatureclass);
Geoprocessor gp = new Geoprocessor();
gp.OverwriteOutput = true;
gp.Execute(clipTool, null);
IFeatureLayer outlayer = new FeatureLayerClass();
outlayer.FeatureClass = outfeatureclass;
outlayer.Name = outfeatureclass.AliasName;
//将裁剪输出的加载到当前Mapcontrol上
axMapControl1.AddLayer((ILayer)outlayer);
方法三,在地图上拉框裁剪
ILayer pLayer;
IFeatureLayer pFeatureLayer;
IFeatureClass pFeatureClass;
IWorkspaceName pNewWSName;
IBasicGeoprocessor pBasicGeop;
IFeatureClassName pFeatureClassName;
IDatasetName pDatasetName;
IFeatureClass pOutputFeatureClass;
IFeatureLayer pOutputFeatureLayer;
ITable pinputTable, pclipTable;
//定义输出图层的FIELD表
pLayer = this.axMapControl1.get_Layer(0);
pinputTable = (ITable)pLayer;
pFeatureLayer = (IFeatureLayer)pLayer;
pFeatureClass = pFeatureLayer.FeatureClass;
//输出文件类型
pFeatureClassName = new FeatureClassNameClass();
pFeatureClassName.FeatureType = esriFeatureType.esriFTSimple;
pFeatureClassName.ShapeFieldName = "Shape";
pFeatureClassName.ShapeType = pFeatureClass.ShapeType;
//输出图层的名称和位置
saveFileDialog1.Filter = "shapefile文件(*.shp)|*.shp";
saveFileDialog1.InitialDirectory = @"C:\";
DialogResult pDialogRuselt = saveFileDialog1.ShowDialog();
if (pDialogRuselt != DialogResult.OK)
return;
string pPath = saveFileDialog1.FileName;
string pFolder = System.IO.Path.GetDirectoryName(pPath);
string pFileName = System.IO.Path.GetFileName(pPath);
pNewWSName = new WorkspaceNameClass();
pNewWSName.WorkspaceFactoryProgID = "esriDataSourcesFile.ShapefileWorkspaceFactory";
pNewWSName.PathName = pFolder;
pDatasetName = (IDatasetName)pFeatureClassName;
pDatasetName.Name = pFileName;
pDatasetName.WorkspaceName = pNewWSName;
//定义相交图层(面)
IGeometry polygon = axMapControl1.TrackPolygon();
IFeatureClass pFeatureClass2 = ToFeatureClass(pinputTable.Fields, polygon);
pclipTable = (ITable)pFeatureClass2;
pBasicGeop = new BasicGeoprocessorClass();
pOutputFeatureClass = pBasicGeop.Clip(pinputTable, false, pclipTable, false, 0.0001, pFeatureClassName);
pOutputFeatureLayer = new FeatureLayerClass();
pOutputFeatureLayer.FeatureClass = pOutputFeatureClass;
pOutputFeatureLayer.Name = pOutputFeatureClass.AliasName;
this.axMapControl1.AddLayer(pOutputFeatureLayer as ILayer, 0);
private IFeatureClass ToFeatureClass(IFields _fields, IGeometry pGeometry)
{
IClone pClone = _fields as IClone;
IFields fields = pClone.Clone() as IFields;
IFieldEdit pFieldEdit = fields.get_Field(fields.FindField("shape")) as IFieldEdit ;
IGeometryDefEdit pGeometryDefEdit = pFieldEdit.GeometryDef as IGeometryDefEdit;
pGeometryDefEdit.GeometryType_2 = esriGeometryType.esriGeometryPolygon;
IWorkspaceFactory2 pWorkspaceFactory = new InMemoryWorkspaceFactoryClass();
IWorkspaceName pWorkspaceName = pWorkspaceFactory.Create("", "temp", null, 0);
IFeatureWorkspace pFeatureWorkspace = (IFeatureWorkspace)(((IName)pWorkspaceName).Open());
IFeatureClass pFeatureClass = pFeatureWorkspace.CreateFeatureClass("tempShp",
fields, null, null, esriFeatureType.esriFTSimple, "shape", "");
IFeature pFeature = pFeatureClass.CreateFeature();
pFeature.Shape = pGeometry;//类型应该相同
pFeature.Store();
return pFeatureClass;
}
ArcGIS Engine 图层裁剪 Clip的实现方法的更多相关文章
- ae arcgis engine 关于面转线的方法和注意事项
代码很简单,如下 private void barButtonItem1_ItemClick(object sender, DevExpress.XtraBars.ItemClickEventArgs ...
- ArcGIS Engine开发之地图基本操作(3)
地图数据的加载 一.加载Shapefile数据 Shapefile文件是目前主流的一种空间数据的文件存储方式,也是不同GIS软件进行数据格式转换常用的中间格式.加载Shapefile数据的方式有两种: ...
- Arcgis engine 指定图层对要素进行创建、删除等操作
Arcgis engine 指定图层创建点要素 在指定的图层上创建一个点要素,点要素的位置是通过X,Y坐标指定的,下面是具体的注释 .其中 和IFeatureClassWrite接口有关的代码不要好像 ...
- [转] arcgis Engine创建shp图层
小生 原文 arcgis Engine创建shp图层 以创建点图层为例.首先要得到保存文件的地址. SaveFileDialog saveFileDialog = new SaveFileDialog ...
- 《ArcGIS Engine+C#实例开发教程》第七讲 图层符号选择器的实现2
原文:<ArcGIS Engine+C#实例开发教程>第七讲 图层符号选择器的实现2 摘要:在第七讲 图层符号选择器的实现的第一阶段中,我们完成了符号选择器窗体的创建与调用.在第二阶段中, ...
- ArcGIS Engine中删除要素的几种方法总结
转自原文 ArcGIS Engine中删除要素的几种方法总结 /// <summary> /// 通过IFeature.Delete方法删除要素 /// </summary> ...
- vs.net调试ArcGIS Engine代码查看变量时,提示“要检查本机对象,请启用本机代码调试。” 的解决方法
用vs2017 调试 查看ArcGIS Engine 的变量时 会提示如下图所示的错误: 解决方法: 工具->选项->调试->常规->使用托管的兼容模式 如下图所示: 2.设置 ...
- ArcGIS engine中Display类库——Display
转自原文 ArcGIS engine中Display类库——Display Display类库包括了用于显示GIS数据的对象.除了负责实际输出图像的主要显示对象(display object)外,这 ...
- ArcGIS engine中Display类库 (局部刷新)
转自原文 ArcGIS engine中Display类库 (局部刷新) Display类库包括了用于显示GIS数据的对象.除了负责实际输出图像的主要显示对象(display object)外,这个类库 ...
随机推荐
- OpenJudge计算概论-单词排序
/*===================================== 单词排序 总时间限制:1000ms 内存限制: 65536kB 描述 输入一行单词序列,相邻单词之间由1个或多个空格间隔 ...
- 用NativeScript创建JavaScript原生移动应用
Telerik公开了用于创建安卓.iOS和Windows Universal跨平台原生应用的框架,NativeScript的公共访问权限. NativeScript既不是一种新型的JavaScript ...
- [转]何为C10K问题
我在学习网络编程的时候经常看到C10K问题,那么究竟什么是C10K问题呢?我看到了一篇好文章就转了过来,原文地址为:c10k问题 所谓c10k问题,指的是服务器同时支持成千上万个客户端的问题,也就是c ...
- jsoncpp用法通俗易懂之解析
刚工作不久,最近遇到一个要解析一个web服务器发过来的json格式的文件,文件如下: { "global": { "renew": "true&quo ...
- 【Andorid开发框架学习】之Mina开发之服务器开发
下午那篇博客我们讲到了Mina的客户端的开发,如果还有没看过的同学可以看一下,我是传送门.现在,我们来学习一下,Mina的服务器的开发. 一.首先看一下,我的服务器的代码图片: 服务器代码我是在My ...
- nand flash,nor flash,spi flash,片上RAM,片外RAM
Flash有掉电数据保存的特点,RAM掉电则数据丢失,但是RAM的速度更高,擦写次数理论上没有限制,而Flash则不行. Nand Flash相比其余的几种flash优势在于可擦写次数多,擦写速度快, ...
- 最全的Android源码目录结构详解
Android 2.1|-- Makefile|-- bionic (bionic C库)|-- bootable (启动引 ...
- PLSQL_Oracle临时表Temporary Table基本概念和用法(概念)
2014-06-08 Created By BaoXinjian
- IREP_SOA Integration WSDL概述(概念)
20150827 Created By BaoXinjian
- 2016 Multi-University Training Contest 4 Bubble Sort(树状数组模板)
Bubble Sort 题意: 给你一个1~n的排列,问冒泡排序过程中,数字i(1<=i<=n)所到达的最左位置与最右位置的差值的绝对值是多少 题解: 数字i多能到达的最左位置为min(s ...