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

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. win10 phpStudy 80端口被占用

    原因是win8下系统默认占用80端口,导致apache无法打开.解决方法: 1.以管理员权限运行c:windowssystem32cmd.exe :2.C:WINDOWSsystem32>net ...

  2. commonJS规范基本机构

    commonJS规范:使用 module.exports 和 require ,基本结构如下: // foo.js 输出模块 module.exports = function(x) { consol ...

  3. 国外HTML网站模版(卖成品模版)

    有非常多的模版,遗憾的是都要钱 http://themeforest.net/search?utf8=%E2%9C%93&term=&view=list&sort=sales& ...

  4. Pop Sequence

    题目来源:PTA02-线性结构3 Pop Sequence   (25分) Question:Given a stack which can keep M numbers at most. Push ...

  5. 给Jquery动态添加的元素添加事件2

    $('div').on('click', 'button', function(e){console.log($(e.target).is(':button'))}); $('<button&g ...

  6. phonegap_android配置文档

    百度文库 http://wenku.baidu.com/link?url=C9l51orfpSrjMEK69-Yjh9hmmaqQj0DicfnYs5FSRhkdy8S62x1aBBwstFH-tJ9 ...

  7. 【linux】rpm常见命令

    查看包依赖模块:http://www.rpmfind.net/ rpm  -ivh [包名] :安装rpm包 rpm  -e [包名] :删除rpm包 rpm  -aq [包名] :查询rpm包 rp ...

  8. 【原创】VNC-view配置

    *.hl_mark_KMSmartTagPinkImg{background-color:#ffaaff;}*.hl_mark_KMSmartTagBlueImg{background-color:# ...

  9. Python 通过print_lol将数据保存到文件中

    1. 定义一个print_lol函数来控制列表的缩进和写入位置 import sys """this is a new fuction, which work for a ...

  10. Linux下高并发socket最大连接数所受的各种限制

    http://blog.csdn.net/guowake/article/details/6615728 1.修改用户进程可打开文件数限制 在Linux平台上,无论编写客户端程序还是服务端程序,在进行 ...