转自原文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 实现要素选取的方法(转载)的更多相关文章

  1. C# 3.0 扩展方法[转载]

    实践 扩展方法是C# 3.0中新加入的特性.MSDN中对扩展方法的定义是:扩展方法使您能够向现有类型"添加"方法,而无需创建新的派生类型.重新编译或以其他方式修改原始类型. 以下以 ...

  2. “error LNK1169: 找到一个或多个多重定义的符号”的解决方法(转载)

    解决方案: “error LNK1169: 找到一个或多个多重定义的符号”的解决方法(转载) 遇到的问题: 在.h头文件中采用namespace 命名空间报错 test.h namespace LMR ...

  3. ArcEngine数据删除几种方法和性能比较

    转自原文 ArcEngine数据删除几种方法和性能比较 一.  几种删除方法代码 1.  查询结果中删除 private void Delete1(IFeatureClass PFeatureclas ...

  4. ArcEngine判断要素(feature)是否为multipart feature及分解(炸开)代码

    转自原文 ArcEngine判断要素(feature)是否为multipart feature及分解(炸开)代码 #region 校验合法性 ArrayList pFeatureArray = nul ...

  5. Cstring转char、string、int等数据类型的方法(转载)

    Cstring转char.string.int等数据类型的方法 (-- ::) 转载 标签: 杂谈 分类: VC CString 转char * CString cstr; char *p = (LP ...

  6. arcengine新建要素类

    ArcGIS里面新建数据集,看起来简单,平时都是默认创建,实际上好多细节问题我们都没注意到 一.在数据集上新建要素类: How to create a feature class within a f ...

  7. Duilib改进窗口拖动,使整个窗口都能拖动两种方法(转载)

    转载:http://www.cnblogs.com/XiHua/articles/3490490.html 转载:http://blog.csdn.net/lostspeed/article/deta ...

  8. python字符串内容替换的方法(转载)

    python字符串内容替换的方法 时间:2016-03-10 06:30:46来源:网络 导读:python字符串内容替换的方法,包括单个字符替换,使用re正则匹配进行字符串模式查找与替换的方法.   ...

  9. JAVA方法和本地方法(转载)

    转载自:http://blog.sina.com.cn/s/blog_5b9b4abe01016zw0.html JAVA中有两种方法:JAVA方法和本地方法   JAVA方法是由JAVA编写的,编译 ...

随机推荐

  1. 1.18 Python基础知识 - Python内置函数

    官方地址:https://docs.python.org/3.5/library/functions.html abs(x): 返回数字的绝对值 all(iterable): 如果迭代器的所有元素都为 ...

  2. BZOJ4372: 烁烁的游戏(动态点分治)

    Description 背景:烁烁很喜欢爬树,这吓坏了树上的皮皮鼠.题意:给定一颗n个节点的树,边权均为1,初始树上没有皮皮鼠.烁烁他每次会跳到一个节点u,把周围与他距离不超过d的节点各吸引出w只皮皮 ...

  3. Caused by: java.lang.NoSuchMethodError:javax.servlet.http.HttpServletRequest.getServletContext()L

    在做项目的时候,出现Caused by: java.lang.NoSuchMethodError: javax.servlet.http.HttpServletRequest.getServletCo ...

  4. Excel查询序列所相应的值-vLoopup函数,求比例分子改变但分母不变

    watermark/2/text/aHR0cDovL2Jsb2cuY3Nkbi5uZXQveWV3ZWlvdXlhbmc=/font/5a6L5L2T/fontsize/400/fill/I0JBQk ...

  5. Cocos2d-x学习笔记(三)CCNode分析

    原创文章.转载请注明出处:http://blog.csdn.net/sfh366958228/article/details/38706483 通过前两份学习笔记,我们不难发现CCScene.CCLa ...

  6. R语言-方差分析

    方差分析指的是不同变量之间互相影响从而导致结果的变化 1.单因素方差分析: 案例:50名患者接受降低胆固醇治疗的药物,其中三种治疗条件使用药物相同(20mg一天一次,10mg一天两次,5mg一天四次) ...

  7. Log4j.properties 属性详解以及 LOG4J日志级别详解

    转自:https://blog.csdn.net/lovely0903jpp/article/details/82261607 假如项目的生产环境上增加请求以及响应信息的打印,这个时候,对于新手来说, ...

  8. [D3] Build an Area Chart with D3 v4

    Similar to line charts, area charts are great for displaying temporal data. Whether you’re displayin ...

  9. httpclient 模拟浏览器动作需注意的cookie和HTTP头等信息

    转自:http://resolute.javaeye.com/blog/491701 commons-httpclient是apache下的一个开源项目,提供了一个纯java实现的http客户端.使用 ...

  10. Project Euler 363 Bézier Curves(几何+二分)

    题目链接: https://projecteuler.net/problem=363 题目: A cubic Bézier curve is defined by four points: \(P_0 ...