ArcGISEngine二次开发(4):属性查询(2)
生活随笔
收集整理的這篇文章主要介紹了
ArcGISEngine二次开发(4):属性查询(2)
小編覺得挺不錯的,現在分享給大家,幫大家做個參考.
屬性查詢(2)
使用IGeometry接口TrackPolygon方法建立對象實現屬性查詢
使用ISpatialFilter接口SpatialRel屬性定義Intersects取交集為查詢對象
之后將查詢到的(FindField方法)屬性顯示在新的windowsform中的listbox中顯示屬性字段
單擊Listbox中的屬性字段,地圖高亮顯示對應多邊形
添加引用:
using System; using System.Collections.Generic; using System.Linq; using System.Text; using ESRI.ArcGIS.Carto; using ESRI.ArcGIS.SystemUI; using ESRI.ArcGIS.esriSystem; using ESRI.ArcGIS.Controls; using ESRI.ArcGIS.Geometry; using ESRI.ArcGIS.Geodatabase; using ESRI.ArcGIS.DataSourcesFile;添加ToolTripButton,添加Click事件代碼如下
ICommand spatialqueryintersect = new spatialquery(); spatialqueryintersect.OnCreate(axMapControl1.Object); spatialqueryintersect.OnClick(); ITool ptool = spatialqueryintersect as ITool; axMapControl1.CurrentTool = ptool;
新建windowsform窗體,并在里邊添加Listbox,Modifiers屬性Public,否則在其他窗體的事件代碼中不能檢測到該控件,事件代碼如下
新建類庫,手動實現Icommand,ITool 接口,定義全局變量:
IMapControlDefault m_app; //Onclick函數設為空,因為單擊Button沒有立刻開始畫多邊形,而是在單擊axmapcontrol對象以后開始畫 public void OnClick(){} //傳入ImapControl對象 public void OnCreate(object Hook){m_app = Hook as IMapControlDefault;} //其他接口置為空 public void OnMouseDown(int button, int shift, int x, int y){IGeometry pGeometry = m_app.TrackPolygon();IFeatureLayer pfeatureLayer = m_app.get_Layer(0) as IFeatureLayer;ISpatialFilter pSpatialfilter =new SpatialFilterClass();pSpatialfilter.SubFields="*";pSpatialfilter.GeometryField="shape";//所畫圖形類型pSpatialfilter.Geometry=pGeometry;pSpatialfilter.SpatialRel=esriSpatialRelEnum.esriSpatialRelIntersects;//空間交集IFeatureCursor pfeaturecursor = pfeatureLayer.Search(pSpatialfilter, false);IFeature pfeature = pfeaturecursor.NextFeature();int ifname = pfeaturecursor.FindField("NAME");//屬性查詢字段SpatialQueryListBox listboxwindows = new SpatialQueryListBox();//SpatialQueryListBox為新建的windowsform窗體listboxwindows.spaqury = m_app;//該窗體中的全局變量while (pfeature != null){listboxwindows.listBox1.Items.Add(pfeature.get_Value(ifname).ToString());m_app.FlashShape(pfeature.Shape, 3, 500, null);pfeature = pfeaturecursor.NextFeature();}listboxwindows.Show();}總結
以上是生活随笔為你收集整理的ArcGISEngine二次开发(4):属性查询(2)的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: github网页版使用教程
- 下一篇: 多线程有几种实现方法,都是什么?优劣点?