arcengine 如何只ps导出选中的图层图片一个图层的选中要素

ArcEngine c# 创建shp图层,并将要素写入图层保存
ArcEngine c# 创建shp图层,并将要素写入图层保存
发布时间: 13:07:38
编辑:www.fx114.net
本篇文章主要介绍了"ArcEngine c# 创建shp图层,并将要素写入图层保存",主要涉及到ArcEngine c# 创建shp图层,并将要素写入图层保存方面的内容,对于ArcEngine c# 创建shp图层,并将要素写入图层保存感兴趣的同学可以参考一下。
之前看了一位大侠的帖子,写的是跟这个差不多的,所以,我就直接copy下来再vs中做了一个类。大家可以直接拿过去用。
using System.Collections.G
using System.T
using ESRI.ArcGIS.G
using System.Windows.F
using ESRI.ArcGIS.DataSourcesF
& & /// &summary&
& & /// 导出缓冲分析之后出现JointCount&1的点位图层
& & /// &/summary&
& & public &class ExportToShp
& & & & public string shpP
& & & & /// &summary&
& & & & /// 保存输出JointCount&1的点位图层
& & & & /// &/summary&
& & & & /// &param name=&apFeatureClass&&&/param&
& & & & public void ExportFeatureClassToShp(IFeatureClass apFeatureClass)
& & & & & & if (apFeatureClass == null)
& & & & & & {
& & & & & & & & MessageBox.Show(&请选择&, &系统提示&);
& & & & & & & &
& & & & & & }
& & & & & & //调用保存文件函数
& & & & & & SaveFileDialog sa = new SaveFileDialog();
& & & & & & sa.Filter = &SHP文件(.shp)|*.shp&;
& & & & & & sa.ShowDialog();
& & & & & & sa.CreatePrompt =
& & & & & & string ExportShapeFileName = sa.FileN
& & & & & & // string StrFilter = &SHP文件(.shp)|*.shp&;
& & & & & & // string ExportShapeFileName = SaveFileDialog(StrFilter);
& & & & & & if (ExportShapeFileName == &&)
& & & & & & & &
& & & & & & string ExportFileShortName = System.IO.Path.GetFileNameWithoutExtension(ExportShapeFileName);
& & & & & &
& & & & & & string ExportFilePath = System.IO.Path.GetDirectoryName(ExportShapeFileName);
& & & & & & shpPath = ExportFilePath + &\\& + ExportFileShortName + &\\& + ExportFileShortName + &.shp&;
& & & & & & //设置导出要素类的参数 & & & & &
& & & & & & IFeatureClassName pOutFeatureClassName = new FeatureClassNameClass();
& & & & & &
& & & & & & IDataset pOutDataset = (IDataset)apFeatureC
& & & & & &
& & & & & & pOutFeatureClassName = (IFeatureClassName)pOutDataset.FullN
& & & & & &&
& & & & & & //创建一个输出shp文件的工作空间
& & & & & & IWorkspaceFactory pShpWorkspaceFactory = new ShapefileWorkspaceFactoryClass();
& & & & & &
& & & & & & IWorkspaceName pInWorkspaceName = new WorkspaceNameClass();
& & & & & &
& & & & & & pInWorkspaceName = pShpWorkspaceFactory.Create(ExportFilePath, ExportFileShortName, null, 0);
& & & & & & //创建一个要素集合
& & & & & & IFeatureDatasetName pInFeatureDatasetName =
& & & & & &
& & & & & & //创建一个要素类
& & & & & & IFeatureClassName pInFeatureClassName = new FeatureClassNameClass();
& & & & & &&
& & & & & & IDatasetName pInDatasetClassN
& & & & & &
& & & & & & pInDatasetClassName = (IDatasetName)pInFeatureClassN
& & & & & &
& & & & & & pInDatasetClassName.Name = ExportFileShortN//作为输出参数
& & & & & &
& & & & & & pInDatasetClassName.WorkspaceName = pInWorkspaceN
& & & & & & //通过FIELDCHECKER检查字段的合法性,为输出SHP获得字段集合
& & & & & &
& & & & & & long iC
& & & & &&
& & & & & & IFields pOutFields, pInF
& & & & & &
& & & & & & IFieldChecker pFieldC
& & & & &&
& & & & & & IField pGeoF
& & & & & &
& & & & & & IEnumFieldError pEnumFieldError =
& & & & &&
& & & & & & pInFields = apFeatureClass.F
& & & & &&
& & & & & & pFieldChecker = new FieldChecker();
& & & & & &
& & & & & & pFieldChecker.Validate(pInFields, out pEnumFieldError, out pOutFields);
& & & & & &
& & & & & & //通过循环查找几何字段
& & & & &&
& & & & & & pGeoField =
& & & & &&
& & & & & & for (iCounter = 0; iCounter & pOutFields.FieldC iCounter++)
& & & & & & {
& & & & & & & & if (pOutFields.get_Field((int)iCounter).Type == esriFieldType.esriFieldTypeGeometry)
& & & & & & & & {
& & & & & & & & & & pGeoField = pOutFields.get_Field((int)iCounter);
& & & & & & & & & &
& & & & & & & & }
& & & & & & }
& & & & & & //得到几何字段的几何定义 & & & & &&
& & & & & & IGeometryDef pOutGeometryD
& & & & & &
& & & & & & IGeometryDefEdit pOutGeometryDefE
& & & & & &
& & & & & & pOutGeometryDef = pGeoField.GeometryD
& & & & & &
& & & & & & //设置几何字段的空间参考和网格
& & & & & & pOutGeometryDefEdit = (IGeometryDefEdit)pOutGeometryD
& & & & & &
& & & & & & pOutGeometryDefEdit.GridCount_2 = 1;
& & & & & &
& & & & & & pOutGeometryDefEdit.set_GridSize(0, 1500000);
& & & & & & try
& & & & & & {
& & & & & & & & //开始导入 & & & & & & & &
& & & & & & & & IFeatureDataConverter pShpToClsConverter = new FeatureDataConverterClass();
& & & & & & & &
& & & & & & & & pShpToClsConverter.ConvertFeatureClass(pOutFeatureClassName, null, pInFeatureDatasetName, pInFeatureClassName, pOutGeometryDef, pOutFields, &&, 1000, 0);
& & & & & & & &
& & & & & & & & MessageBox.Show(&导出成功&, &系统提示&);
& & & & & & }
& & & & & & catch (Exception ex)
& & & & & & {
& & & & & & & & MessageBox.Show(&the following exception occurred:& + ex.ToString());
& & & & & & }
本文标题:
本页链接:6916人阅读
.net(115)
Arc Engine(65)
选择一个要素或者一个要素集(FeatureSelection)的方法很多,如IMap::SelectByShape、ILayer::search、IFeatureSection::SelectFeature等方法
主要用到的方法:
IMap接口的SelectFeature(Layer, Feature) (方法,从一个Layer中选择一个Feature);
IMap接口SelectByShape(Shape, env, justOne) (方法,从Layer中依靠一个图形的范围shape和一个选择的环境env来选择要素,而在所有图层中只从IFeatureLayer的图层中进行选择)
IFeatureSelection接口SelectFeatures (Filter, Method, justOne ) (方法,根据指定的标准过滤器filter和方法,选择要素,第一个参数为QueryFilter类型的变量,第二个参数为esriSelectionResultEnum类型的变量,第三个参数为布尔型变量,通常为false)
IFeatureLayer接口Search (IqueryFilter, book ) (方法,创建一个游标去查询相应设置的过滤器的查询)
1 点选法获取要素
&&&废话少说先看代码:
private double ConvertPixelsToMapUnits(IActiveView pActiveView, double pixelUnits)
// Uses the ratio of the size of the map in pixels to map units to do the conversion
IPoint p1 = pActiveView.ScreenDisplay.DisplayTransformation.VisibleBounds.UpperL
IPoint p2 = pActiveView.ScreenDisplay.DisplayTransformation.VisibleBounds.UpperR
int x1, x2, y1, y2;
pActiveView.ScreenDisplay.DisplayTransformation.FromMapPoint(p1, out x1, out y1);
pActiveView.ScreenDisplay.DisplayTransformation.FromMapPoint(p2, out x2, out y2);
double pixelExtent = x2 - x1;
double realWorldDisplayExtent = pActiveView.ScreenDisplay.DisplayTransformation.VisibleBounds.W
double sizeOfOnePixel = realWorldDisplayExtent / pixelE
return pixelUnits * sizeOfOneP
IMap pMap = axMapControl1.M
IActiveView pActiveView = pMap as IActiveV
IFeatureLayer pFeatureLayer = pMap.get_Layer(0) as IFeatureL
IFeatureClass pFeatureClass = pFeatureLayer.FeatureC
//设置点击点的位置
IPoint point = pActiveView.ScreenDisplay.DisplayTransformation.ToMapPoint(e.x, e.y);
ITopologicalOperator pTOpo = point as ITopologicalO
length = ConvertPixelsToMapUnits(pActiveView, 4);
IGeometry pBuffer = pTOpo.Buffer(length);
IGeometry pGeomentry = pBuffer.E
//空间滤过器
ISpatialFilter pSpatialFilter = new SpatialFilterClass();
pSpatialFilter.Geometry = pG
//根据被选择要素的不同,设置不同的空间滤过关系
switch (pFeatureClass.ShapeType)
case esriGeometryType.esriGeometryPoint:
pSpatialFilter.SpatialRel=esriSpatialRelEnum.esriSpatialRelC
case esriGeometryType.esriGeometryPolyline:
pSpatialFilter.SpatialRel=esriSpatialRelEnum.esriSpatialRelC
case esriGeometryType.esriGeometryPolygon :
pSpatialFilter.SpatialRel=esriSpatialRelEnum.esriSpatialRelI
IFeatureSelection pFSelection=pFeatureLayer as IFeatureS
pFSelection.SelectFeatures(pSpatialFilter,esriSelectionResultEnum.esriSelectionResultNew,false);
ISelectionSet pSelectionset=pFSelection.SelectionS
ICursor pC
pSelectionset.Search(null,true,out pCursor);
IFeatureCursor pFeatCursor=pCursor as IFeatureC
IFeature pFeature=pFeatCursor.NextFeature();
while(pFeature!=null)
pMap.SelectFeature(pFeatureLayer,pFeature);
pFeature=pFeatCursor.NextFeature();
pActiveView.PartialRefresh(esriViewDrawPhase.esriViewGraphicSelection,null,null);
//另外的改写:
pSpatialFilter.GeometryField = pFeatureClass.ShapeFieldN
IQueryFilter pFilter = pSpatialF
IFeatureCursor pFeatCursor = pFeatureLayer.Search(pFilter,false);
IFeature pFeature=pFeatCursor.NextFeature();
while(pFeature!=null)
pMap.SelectFeature(pFeatureLayer,pFeature);
pFeature=pFeatCursor.NextFeature();
pActiveView.PartialRefresh(esriViewDrawPhase.esriViewGraphicSelection,null,null);
另外还有一种比较简单的点选方法:
IGeometry g =
IEnvelope pE
IActiveView pActiveView = axMapControl1.ActiveV
IMap pMap = axMapControl1.M
pEnv = axMapControl1.TrackRectangle();
if (pEnv.IsEmpty == true)
ESRI.ArcGIS.Display.tagRECT
r.bottom = e.y + 5;
r.top = e.y - 5;
r.left = e.x - 5;
r.right = e.x + 5;
pActiveView.ScreenDisplay.DisplayTransformation.TransformRect(pEnv, ref r, 4);
pEnv.SpatialReference = pActiveView.FocusMap.SpatialR
g = pEnv as IG
axMapControl1.Map.SelectByShape(g, null, false);
axMapControl1.Refresh(esriViewDrawPhase.esriViewGeoSelection, null, null);
2 拉框选择
IMap pMap = axMapControl1.M
IActiveView pActiveView = pMap as IActiveV
IEnvelope pEnv = axMapControl1.TrackRectangle();
pMap.SelectByShape(pEnv, null, false);
pActiveView.PartialRefresh(esriViewDrawPhase.esriViewGeoSelection,null, null);
参考知识库
* 以上用户言论只代表其个人观点,不代表CSDN网站的观点或立场
(2)(2)(1)(1)(1)(3)(1)(2)(6)(3)(1)(8)(7)(2)(5)(8)(7)(2)(8)(15)(18)(19)(23)(5)(7)(2)(1)(1)(7)(3)
访问:270170次
积分:3132
积分:3132
排名:第8709名
原创:23篇
转载:147篇
评论:41条& ArcEngine c# 创建shp图层,并将要素写入图层保存
ArcEngine c# 创建shp图层,并将要素写入图层保存
之前看了一位大侠的帖子,写的是跟这个差不多的,所以,我就直接copy下来再vs中做了一个类。大家可以直接拿过去用。
using System.Collections.G
using System.T
using ESRI.ArcGIS.G
using System.Windows.F
using ESRI.ArcGIS.DataSourcesF
/// &summary&
/// 导出缓冲分析之后出现JointCount&1的点位图层
/// &/summary&
class ExportToShp
public string shpP
/// &summary&
/// 保存输出JointCount&1的点位图层
/// &/summary&
/// &param name="apFeatureClass"&&/param&
public void ExportFeatureClassToShp(IFeatureClass apFeatureClass)
if (apFeatureClass == null)
MessageBox.Show("请选择", "系统提示");
//调用保存文件函数
SaveFileDialog sa = new SaveFileDialog();
sa.Filter = "SHP文件(.shp)|*.shp";
sa.ShowDialog();
sa.CreatePrompt =
string ExportShapeFileName = sa.FileN
// string StrFilter = "SHP文件(.shp)|*.shp";
// string ExportShapeFileName = SaveFileDialog(StrFilter);
if (ExportShapeFileName == "")
string ExportFileShortName = System.IO.Path.GetFileNameWithoutExtension(ExportShapeFileName);
string ExportFilePath = System.IO.Path.GetDirectoryName(ExportShapeFileName);
shpPath = ExportFilePath + "\\" + ExportFileShortName + "\\" + ExportFileShortName + ".shp";
//设置导出要素类的参数
IFeatureClassName pOutFeatureClassName = new FeatureClassNameClass();
IDataset pOutDataset = (IDataset)apFeatureC
pOutFeatureClassName = (IFeatureClassName)pOutDataset.FullN
//创建一个输出shp文件的工作空间
IWorkspaceFactory pShpWorkspaceFactory = new ShapefileWorkspaceFactoryClass();
IWorkspaceName pInWorkspaceName = new WorkspaceNameClass();
pInWorkspaceName = pShpWorkspaceFactory.Create(ExportFilePath, ExportFileShortName, null, 0);
//创建一个要素集合
IFeatureDatasetName pInFeatureDatasetName =
//创建一个要素类
IFeatureClassName pInFeatureClassName = new FeatureClassNameClass();
IDatasetName pInDatasetClassN
pInDatasetClassName = (IDatasetName)pInFeatureClassN
pInDatasetClassName.Name = ExportFileShortN//作为输出参数
pInDatasetClassName.WorkspaceName = pInWorkspaceN
//通过FIELDCHECKER检查字段的合法性,为输出SHP获得字段集合
IFields pOutFields, pInF
IFieldChecker pFieldC
IField pGeoF
IEnumFieldError pEnumFieldError =
pInFields = apFeatureClass.F
pFieldChecker = new FieldChecker();
pFieldChecker.Validate(pInFields, out pEnumFieldError, out pOutFields);
//通过循环查找几何字段
pGeoField =
for (iCounter = 0; iCounter & pOutFields.FieldC iCounter++)
if (pOutFields.get_Field((int)iCounter).Type == esriFieldType.esriFieldTypeGeometry)
pGeoField = pOutFields.get_Field((int)iCounter);
//得到几何字段的几何定义
IGeometryDef pOutGeometryD
IGeometryDefEdit pOutGeometryDefE
pOutGeometryDef = pGeoField.GeometryD
//设置几何字段的空间参考和网格
pOutGeometryDefEdit = (IGeometryDefEdit)pOutGeometryD
pOutGeometryDefEdit.GridCount_2 = 1;
pOutGeometryDefEdit.set_GridSize(0, 1500000);
//开始导入
IFeatureDataConverter pShpToClsConverter = new FeatureDataConverterClass();
pShpToClsConverter.ConvertFeatureClass(pOutFeatureClassName, null, pInFeatureDatasetName, pInFeatureClassName, pOutGeometryDef, pOutFields, "", 1000, 0);
MessageBox.Show("导出成功", "系统提示");
catch (Exception ex)
MessageBox.Show("the following exception occurred:" + ex.ToString());
本文固定链接:
[上一篇][下一篇]
最新文章随机精彩热门排行
精彩内容获取超时,请稍候...
日志总数:3903 篇
评论总数:146 评
标签数量:4475 个
链接总数:4 条
建站日期:
运行天数:1360 天本帖子已过去太久远了,不再提供回复功能。Arcengine开发(3)
public&void&getSelectedFeature()&&&&
&&&&&&&&{&&
&&&&&&&&&&&try&&&&
&&&&&&&&&&&{&&&&
&&&&&&&&&&&&IMap&map&=&axMapControl1.M&&
&&&&&&&&&&&&ISelection&selection&=&map.FeatureS&&
&&&&&&&&&&&&IEnumFeatureSetup&iEnumFeatureSetup&=&(IEnumFeatureSetup)&&
&&&&&&&&&&&&iEnumFeatureSetup.AllFields&=&true;&&
&&&&&&&&&&&&IEnumFeature&enumFeature&=&(IEnumFeature)iEnumFeatureS&&
&&&&&&&&&&&&enumFeature.Reset();&&&&
&&&&&&&&&&&&IFeature&feature&=&enumFeature.Next();&&&&
&&&&&&&&&&&&while&(feature&!=&null)&&&&
&&&&&&&&&&&&&{&&
&&&&&&&&&&&&&&&&&string&hehe&=&feature.get_Value(5).ToString();&&
&&&&&&&&&&&&&&&&&MessageBox.Show(hehe);&&
&&&&&&&&&&&&&&&feature&=&enumFeature.Next();&&&&
&&&&&&&&&&&&&}&&&&
&&&&&&&&&&&}&&&&
&&&&&&&&&&&catch&(Exception&e)&&&&
&&&&&&&&&&&{&&
&&&&&&&&&&&}&&
&&&&&&&&}&&
Feature和FeatureClass关系:
1、FeaturLayer是加载在地图文档中的数据层,只是要素类的表现形式;FeatureClass是一组空间实体的集合,在数据表中存储了统一的属性和行为,每一个FeatureClass都有一个Geometry类型,如shp文件;
2、IFeatureLayer继承自ILayer,IFeatureClass继承自IClass;
3、FeatureLayer可以创建自己的对象,而FeatureClass不行:
IFeatureClass=IFeatureLayer.FeatureClass 或者
IFeatureClass=IFeatureWorkspace.openFeatureClass(&xx&)
Feature是实现了Ifeature接口的实体类.它指要素类中的一个要素.
FeatureClass指要素类,FeatureLayer指要素图层,真正代表图层的还是FeatureClass,FeatureFLayer只是一个表层的东西,举个简单的例子,当某个图层的数据源丢失的时候,你就要去判断FeatureLayer.FeatureClass!=null&,
通过IfeatureClass.CreateFeature可以在要素类中创建一个要素,然后通过Store方法保存.
Feature和FeatureClass转换:IFeature pFeature = o as IF IFeatureClass pFeatureClass = pFeature.Class
as IFeatureC
参考知识库
* 以上用户言论只代表其个人观点,不代表CSDN网站的观点或立场
访问:7019次
排名:千里之外
原创:17篇
转载:12篇
(3)(1)(5)(12)(1)(1)(1)(5)

我要回帖

更多关于 arcengine 复制要素 的文章

 

随机推荐