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)外,这个类库 ...
随机推荐
- CentOs 设置静态IP 方法 dhcp的配置
0.自动获取配置 DEVICE=eth0 HWADDR=00:0C:39:AD:11:48 TYPE=Ethernet UUID=c230a1e5-a535-487a-aab5-2fad7cd5583 ...
- 读取Config文件工具类 PropertiesConfig.java
package com.util; import java.io.BufferedInputStream; import java.io.FileInputStream; import java.io ...
- ios系统下,html5拍照上传的压缩处理
http://gokercebeci.com/dev/canvasresize 通过canvas和base64的处理方式实现大尺寸照片的压缩和上传 介绍: https://github.com/zev ...
- 解决Centos6.5虚拟机上网问题
起初是为了能通过上网的方式简化g++的安装,故有此篇博文,希望能帮助到有需要的人. 虚拟机环境: 1.Linux系统:Centos6.5 64位 2.ifconfig查看虚拟机ip:竟然没有ip! 3 ...
- (转)如何在eclipse的配置文件里指定jdk路径
本文转载自:http://songguoliang.iteye.com/blog/1752519 运行eclipse时报如下错误: 在eclipse的配置文件里指定jdk路径,只需在eclipse的配 ...
- Installing IPython using pip on CentOS
1. First to install pip # wget https://bootstrap.pypa.io/get-pip.py # python get-pip.py 2. Install i ...
- 战胜忧虑<2>——忙碌可以消除忧虑
忙碌可以消除忧虑 当你的脑筋空出来时,也会有东西进去补充,是什么呢?通常都是你的感觉.为什么?因为忧虑.恐惧.憎恨.嫉妒.和羡慕等等情绪,都是由我们的思想所控制的,这种情绪都非常猛烈.会把我们思想中所 ...
- php没有开启Memcache扩展类时
模拟PHP Memcache 类.当服务器没有开启Memcache扩展的时候.可以采用本类使用方法class_exists('Memcache') or include './Memcache.cla ...
- C#中的 int?是什么意思
http://www.cnblogs.com/firstcsharp/archive/2011/12/11/2283797.html int?:表示可空类型,就是一种特殊的值类型,它的值可以为null ...
- 使用jackson进行json数据格式转换
private static final JsonFactory factory = new JsonFactory(); StringWriter jsonOut = new StringWrite ...