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编写的,编译 ...
随机推荐
- [LuoguP4892]GodFly的寻宝之旅 状压DP
链接 基础状压DP,预处理出sum,按照题意模拟即可 复杂度 \(O(n^22^n)\) #include<bits/stdc++.h> #define REP(i,a,b) for(in ...
- Linux中iptables学习
防火墙:是一种位于内部网络与外部网络之间安全的防护系统,依照特定的规则,允许或是限制传输的数据通过.iptables通常被用作类UNIX系统中的防火墙,更准确的说,可以称为iptables/netfi ...
- Android JNI用于驱动測试
硬件平台:S3C6410 操作系统:Ubuntu.windows 板子系统:Android 开发工具:jdk.ndk,eclipse 本次測试从linux内核模块编译開始.以S3C6410的pwm驱动 ...
- java解压多目录Zip文件(解决中文乱码问题)--转载
原文地址:http://zhangyongbo.iteye.com/blog/1749439 import java.io.BufferedOutputStream; import java.io.F ...
- 绝对定位等html结构,水平居中的处理方案
1.父子结构,父relative,子absolute.子元素要水平居中:left:50%:margin-left:子元素一半的宽度.因为定位的left是按左边框开始计算.[固定问题的模块化解决]
- NYOJ448_寻找最大数【贪心】
寻找最大数 时间限制:1000 ms | 内存限制:65535 KB 难度:2 描写叙述 请在整数 n 中删除m个数字, 使得余下的数字按原次序组成的新数最大, 比方当n=920813467185 ...
- 关于VUE的安装和一些简单属性
安装vue 安装前初始化package.json 主要用来描述自己的项目,记录安装过得文件有哪些,在当前文件夹下生产json 安装vue --save(-S)代表项目依赖 --save-dev(-D) ...
- 关于JS面向对象继承问题
1.原型继承(是JS中很常用的一种继承方式) 子类children想要继承父类father中的所有的属性和方法(私有+公有),只需要让children.prototype=new father;即可. ...
- ntp 服务器
ntp.sjtu.edu.cn 202.120.2.101 (上海交通大学网络中心NTP服务器地址)s1a.time.edu.cn 北京邮电大学s1b.time.edu.cn 清华大学s1c.time ...
- UVA 10943 - How do you add? 递推
http://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&page=show_problem&p ...