博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
AE要素选择(点选和拉框选择)
阅读量:5917 次
发布时间:2019-06-19

本文共 4340 字,大约阅读时间需要 14 分钟。

原文

 

选择一个要素或者一个要素集(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 conversionIPoint 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(0) 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, 4);    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 + 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.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);
 

 

转载地址:http://mvgpx.baihongyu.com/

你可能感兴趣的文章
初识Linux_3
查看>>
继承与静态成员
查看>>
linux VPN 多IP出口 iptables设置
查看>>
测试计算机是小端存储还是大端存储
查看>>
c++ 写时拷贝
查看>>
Linux下搭建SMB文件共享服务,Linux/Windows互联互通
查看>>
2013年七月GBin1月刊
查看>>
MaxCompute 学习计划(一)
查看>>
数据让生意更简单,网聚宝创业团队利用数加快速打造核心业务竞争力,在激烈的市场竞争中弯道超车。...
查看>>
聊聊storm TridentWindowManager的pendingTriggers
查看>>
一个复杂的Linux下的socket程序
查看>>
tigase 集群配置
查看>>
组策略部署软件之一:软件分发概论与部署MSI程序包
查看>>
JSP技术
查看>>
python装载模块的顺序
查看>>
GoldenGate简单复制环境的搭建
查看>>
TPCM及可信平台主板标准
查看>>
HCIE-RS 首次挂靠有效期到2020年
查看>>
智能手机浏览器中的一些手势事件
查看>>
Eclipse 工程迁移到 Android Studio
查看>>