方法一, 图层对图层裁剪,输出图层

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的实现方法的更多相关文章

  1. ae arcgis engine 关于面转线的方法和注意事项

    代码很简单,如下 private void barButtonItem1_ItemClick(object sender, DevExpress.XtraBars.ItemClickEventArgs ...

  2. ArcGIS Engine开发之地图基本操作(3)

    地图数据的加载 一.加载Shapefile数据 Shapefile文件是目前主流的一种空间数据的文件存储方式,也是不同GIS软件进行数据格式转换常用的中间格式.加载Shapefile数据的方式有两种: ...

  3. Arcgis engine 指定图层对要素进行创建、删除等操作

    Arcgis engine 指定图层创建点要素 在指定的图层上创建一个点要素,点要素的位置是通过X,Y坐标指定的,下面是具体的注释 .其中 和IFeatureClassWrite接口有关的代码不要好像 ...

  4. [转] arcgis Engine创建shp图层

    小生 原文 arcgis Engine创建shp图层 以创建点图层为例.首先要得到保存文件的地址. SaveFileDialog saveFileDialog = new SaveFileDialog ...

  5. 《ArcGIS Engine+C#实例开发教程》第七讲 图层符号选择器的实现2

    原文:<ArcGIS Engine+C#实例开发教程>第七讲 图层符号选择器的实现2 摘要:在第七讲 图层符号选择器的实现的第一阶段中,我们完成了符号选择器窗体的创建与调用.在第二阶段中, ...

  6. ArcGIS Engine中删除要素的几种方法总结

    转自原文 ArcGIS Engine中删除要素的几种方法总结 /// <summary> /// 通过IFeature.Delete方法删除要素 /// </summary> ...

  7. vs.net调试ArcGIS Engine代码查看变量时,提示“要检查本机对象,请启用本机代码调试。” 的解决方法

    用vs2017 调试 查看ArcGIS Engine 的变量时 会提示如下图所示的错误: 解决方法: 工具->选项->调试->常规->使用托管的兼容模式 如下图所示: 2.设置 ...

  8. ArcGIS engine中Display类库——Display

    转自原文  ArcGIS engine中Display类库——Display Display类库包括了用于显示GIS数据的对象.除了负责实际输出图像的主要显示对象(display object)外,这 ...

  9. ArcGIS engine中Display类库 (局部刷新)

    转自原文 ArcGIS engine中Display类库 (局部刷新) Display类库包括了用于显示GIS数据的对象.除了负责实际输出图像的主要显示对象(display object)外,这个类库 ...

随机推荐

  1. [转]js中获取时间的函数集

    $(function(){ var mydate = new Date(); var t=mydate.toLocaleString(); $("#time").text(t); ...

  2. Genymotion出现Unable to load VirtualBox engine问题--100%解决

    首先强调一个事情,作为程序员,一定要养成一个习惯:安装软件时尤其像VirtualBox这类,首先设置其"兼容模式"以及"特权等级" . 环境:win7 64bi ...

  3. php自动转换pfx到pem和cer(dem格式)到pem

    经常做银行的支付接口,私钥一般都是pfx格式(私钥用来加密生成签名发送报文),公钥是cer格式(公钥用来验证返回报文里的签名).但是php里openssl只能用pem格式,每次转换都要用openssl ...

  4. 并行计算之OpenMP中的任务调度

    本文参考<OpenMP中的任务调度>博文,主要讲的是OpenMP中的schedule子句用法. 一.应用需求 在OpenMP并行计算中,任务调度主要用于并行的for循环.当for循环中每次 ...

  5. 使用 OWIN 作为 ASP.NET Web API 的宿主

    使用 OWIN 作为 ASP.NET Web API 的宿主 ASP.NET Web API 是一种框架,用于轻松构建可以访问多种客户端(包括浏览器和移动 设备)的 HTTP 服务. ASP.NET ...

  6. 【Java安装】Centos6.8 安装Java1.6

    安装java 1.6 Centos6.8安装完成后,一般都安装了java,为了安装java1.6,需要卸载系统自带的java,主要步骤: 先安装java1.6,目的:为了防止先卸载系统自带java时, ...

  7. Python 共享和上传函数模块到PyPI

    1. register account by brower on https://pypi.python.org/pypi/ 2. register your moudle "nester& ...

  8. 恢复ext4文件系统superblock

    恢复ext4文件系统superblock 1. Create ext4 文件系统. [root@localhost ~]# mkfs.ext4 /dev/vdb1 [root@localhost ~] ...

  9. android学习笔记14——GridView、ImageSwitcher

    GridView--网格视图.ImageSwitcher--图像切换器 ==> GridView,用于在界面上按行.列的分布形式显示多个组件:GridView和ListView父类相同——Abs ...

  10. golang的连接池例子

    github.com/jolestar/go-commons-pool 测试代码 package main import ( "github.com/jolestar/go-commons- ...