Arcengine 实现要素选取的方法(转载)
选择一个要素或者一个要素集(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.UpperLeft;
IPoint p2 = pActiveView.ScreenDisplay.DisplayTransformation.VisibleBounds.UpperRight;
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.Width;
double sizeOfOnePixel = realWorldDisplayExtent / pixelExtent;
return pixelUnits * sizeOfOnePixel;
}
IMap pMap = axMapControl1.Map;
IActiveView pActiveView = pMap as IActiveView;
IFeatureLayer pFeatureLayer = pMap.get_Layer() as IFeatureLayer;
IFeatureClass pFeatureClass = pFeatureLayer.FeatureClass; //设置点击点的位置
IPoint point = pActiveView.ScreenDisplay.DisplayTransformation.ToMapPoint(e.x, e.y);
ITopologicalOperator pTOpo = point as ITopologicalOperator;
double length;
length = ConvertPixelsToMapUnits(pActiveView, );
IGeometry pBuffer = pTOpo.Buffer(length);
IGeometry pGeomentry = pBuffer.Envelope;
//空间滤过器
ISpatialFilter pSpatialFilter = new SpatialFilterClass();
pSpatialFilter.Geometry = pGeomentry;
//根据被选择要素的不同,设置不同的空间滤过关系
switch (pFeatureClass.ShapeType)
{
case esriGeometryType.esriGeometryPoint:
pSpatialFilter.SpatialRel=esriSpatialRelEnum.esriSpatialRelContains;
break;
case esriGeometryType.esriGeometryPolyline:
pSpatialFilter.SpatialRel=esriSpatialRelEnum.esriSpatialRelCrosses;
break;
case esriGeometryType.esriGeometryPolygon :
pSpatialFilter.SpatialRel=esriSpatialRelEnum.esriSpatialRelIntersects;
break; }
IFeatureSelection pFSelection=pFeatureLayer as IFeatureSelection;
pFSelection.SelectFeatures(pSpatialFilter,esriSelectionResultEnum.esriSelectionResultNew,false);
ISelectionSet pSelectionset=pFSelection.SelectionSet;
ICursor pCursor;
pSelectionset.Search(null,true,out pCursor);
IFeatureCursor pFeatCursor=pCursor as IFeatureCursor;
IFeature pFeature=pFeatCursor.NextFeature();
while(pFeature!=null)
{
pMap.SelectFeature(pFeatureLayer,pFeature);
pFeature=pFeatCursor.NextFeature();
}
pActiveView.PartialRefresh(esriViewDrawPhase.esriViewGraphicSelection,null,null); //另外的改写:
pSpatialFilter.GeometryField = pFeatureClass.ShapeFieldName;
IQueryFilter pFilter = pSpatialFilter;
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 = null;
IEnvelope pEnv;
IActiveView pActiveView = axMapControl1.ActiveView;
IMap pMap = axMapControl1.Map;
pEnv = axMapControl1.TrackRectangle();
if (pEnv.IsEmpty == true)
{
ESRI.ArcGIS.Display.tagRECT r;
r.bottom = e.y + ;
r.top = e.y - ;
r.left = e.x - ;
r.right = e.x + ;
pActiveView.ScreenDisplay.DisplayTransformation.TransformRect(pEnv, ref r, );
pEnv.SpatialReference = pActiveView.FocusMap.SpatialReference;
}
g = pEnv as IGeometry;
axMapControl1.Map.SelectByShape(g, null, false);
axMapControl1.Refresh(esriViewDrawPhase.esriViewGeoSelection, null, null);
2 拉框选择
IMap pMap = axMapControl1.Map;
IActiveView pActiveView = pMap as IActiveView;
IEnvelope pEnv = axMapControl1.TrackRectangle();
pMap.SelectByShape(pEnv, null, false);
pActiveView.PartialRefresh(esriViewDrawPhase.esriViewGeoSelection,null, null);
Arcengine 实现要素选取的方法(转载)的更多相关文章
- C# 3.0 扩展方法[转载]
实践 扩展方法是C# 3.0中新加入的特性.MSDN中对扩展方法的定义是:扩展方法使您能够向现有类型"添加"方法,而无需创建新的派生类型.重新编译或以其他方式修改原始类型. 以下以 ...
- “error LNK1169: 找到一个或多个多重定义的符号”的解决方法(转载)
解决方案: “error LNK1169: 找到一个或多个多重定义的符号”的解决方法(转载) 遇到的问题: 在.h头文件中采用namespace 命名空间报错 test.h namespace LMR ...
- ArcEngine数据删除几种方法和性能比较
转自原文 ArcEngine数据删除几种方法和性能比较 一. 几种删除方法代码 1. 查询结果中删除 private void Delete1(IFeatureClass PFeatureclas ...
- ArcEngine判断要素(feature)是否为multipart feature及分解(炸开)代码
转自原文 ArcEngine判断要素(feature)是否为multipart feature及分解(炸开)代码 #region 校验合法性 ArrayList pFeatureArray = nul ...
- Cstring转char、string、int等数据类型的方法(转载)
Cstring转char.string.int等数据类型的方法 (-- ::) 转载 标签: 杂谈 分类: VC CString 转char * CString cstr; char *p = (LP ...
- arcengine新建要素类
ArcGIS里面新建数据集,看起来简单,平时都是默认创建,实际上好多细节问题我们都没注意到 一.在数据集上新建要素类: How to create a feature class within a f ...
- Duilib改进窗口拖动,使整个窗口都能拖动两种方法(转载)
转载:http://www.cnblogs.com/XiHua/articles/3490490.html 转载:http://blog.csdn.net/lostspeed/article/deta ...
- python字符串内容替换的方法(转载)
python字符串内容替换的方法 时间:2016-03-10 06:30:46来源:网络 导读:python字符串内容替换的方法,包括单个字符替换,使用re正则匹配进行字符串模式查找与替换的方法. ...
- JAVA方法和本地方法(转载)
转载自:http://blog.sina.com.cn/s/blog_5b9b4abe01016zw0.html JAVA中有两种方法:JAVA方法和本地方法 JAVA方法是由JAVA编写的,编译 ...
随机推荐
- 记号(notation)的学习
数学的记号(notation) 记号具体代表什么含义,取决于你的定义: 比如这样的 d⃗ 一个向量,每个分量 d(i) 表示的是从初始结点 v 到当前节点 vi 的最短路径:也即这样的一个向量的每一 ...
- 企业部署Linux应用将拥有更低的TCO
650) this.width=650;" onclick='window.open("http://blog.51cto.com/viewpic.php?refimg=" ...
- Java学习笔记八
IO流:就是input/output输入/输出流. 一.字节流操作文件的便捷类:FileWriter和FileReader import java.io.FileWriter; import java ...
- Javascript 继承和克隆
个人总结: call 继承的是父类私有 prototype 继承的父类公有 create 可以将公有或私有继承到子类上去(克隆) for in 克隆 不管公有还是私有的都克隆成私有的 1.原型继承:将 ...
- [Javascirpt AST] Babel Plugin -- create new CallExpression
The code we want to trasform: 2 ** 3; a ** b; a **b * c; a ** b ** c; (a+1) ** (b+1); transform to: ...
- 怎样将OpenStack部署到Hadoop
随着信息时代的快速发展,大数据技术和私有云环境都非常实用;只是,假设将两者结合在一起.企业会获得巨大的利润.虽然结合两者会让环境变得更复杂.企业仍然能够看到将 OpenStack 私有云和 Apach ...
- 修改chrome的安装目录(默认的竟然安装在documents and settings目录,google真不厚道)
修改chrome的安装目录(默认的竟然安装在documents and settings目录,google真不厚道) 把chrome从系统目录提取出来 Vista下,Win+R运行 C:/Users/ ...
- jquery验证篇
jquery验证:验证不了(包括easy ui 插件引用的js) jquery easy ui 引用的js <span style="color:#000000;">& ...
- BC 52 div2 A Victor and Machine
简单数学题,把这道题目贴上去的不过为了不想看到这个月写了某个数字篇博客,该数字有点不吉利... 近期没有学习的欲望.. . 集中不了注意力,今天打BC还是做出来一题,尽管涨分了,真心希望能接近cf的水 ...
- (转)oracle常用的数据字典
一.oracle数据字典主要由以下几种视图构成: .user视图 以user_为前缀,用来记录用户对象的信息 .all视图 以all_为前缀,用来记录用户对象的信息及被授权访问的对象信息 .dba视图 ...