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编写的,编译 ...
随机推荐
- worktools-git 工具的使用总结(2)
1.创建分支 git branch son parent //创建分支,是在master 分支的基础上创建 :~/myGit$ git st # On branch master nothing to ...
- 前端项目中常用es6知识总结 -- let、const及数据类型延伸
项目开发中一些常用的es6知识,主要是为以后分享小程序开发.node+koa项目开发以及vueSSR(vue服务端渲染)做个前置铺垫. 项目开发常用es6介绍 1.块级作用域 let const 2 ...
- BZOJ1030: [JSOI2007]文本生成器(Trie图+dp)
Description JSOI交给队员ZYX一个任务,编制一个称之为“文本生成器”的电脑软件:该软件的使用者是一些低幼人群,他们现在使用的是GW文本生成器v6版.该软件可以随机生成一些文章―――总是 ...
- 18/9/9牛客网提高组Day1
牛客网提高组Day1 T1 中位数 这好像是主席树??听说过,不会啊... 最后只打了个暴力,可能是n2logn? 只过了前30% qwq #include<algorithm> #in ...
- jquery模拟可输入的下拉框
//页面html <div id="select" class="select" > <ul> <c:forEach items= ...
- 让人难过的 openssl_pkcs7_encrypt
让人难过的 openssl_pkcs7_encrypt 用PHP.NET的范例,没有加密结果,也没有报错信息,而openssl_pkcs7_sign()函数则返回 error opening inpu ...
- Android 开发之锁屏弹窗
尝试利用 WindowManager 添加浮窗的方式实现 想在锁屏上面实现弹窗,第一个想法就是利用 WindowManager 设置 Window 的 Flag,通过设置 Flag 的显示优先级来让窗 ...
- windows 批处理脚本(batch scripting)
Guide to Windows Batch Scripting DOS 不需对变量事先声明.未声明或未初始化变量是一个空字符串("") 1. 变量赋值 set命令用于变量赋值.s ...
- Java Web学习总结(7)——HttpServletRequest对象
一.HttpServletRequest介绍 HttpServletRequest对象代表客户端的请求,当客户端通过HTTP协议访问服务器时,HTTP请求头中的所有信息都封装在这个对象中,通过这个对象 ...
- The Swift Programming Language 中文翻译版
原文(http://www.cnblogs.com/lkvt/p/3765349.html) 一.Welcome to Swift 1.关于Swift Swift是一种用于iOS和OS X应用的全新编 ...