《2022年2022年空间数据查询 .pdf》由会员分享,可在线阅读,更多相关《2022年2022年空间数据查询 .pdf(7页珍藏版)》请在淘文阁 - 分享文档赚钱的网站上搜索。
1、空间数据查询按查询方式来分,主要分为两类: 根据属性条件查询对象和根据几何条件查询对象。无论是根据属性还是根据几何来查询对象,都必须设置相应的查询条件。在ArcGIS Engine 中,FeatureLayer 对象 和 IFeatureClass 对象 有一个 Search()方法专门用于空间数据查询,同时ArcGIS Engine 中提供了一个IQueryFilter 接口来设置查询的条件(属性条件和几何条件)。首先来看一下IFeatureLayer 接口的 Search()方法,其定义如下:public IFeatureCursor Search (IQueryFilter queryF
2、ilter, bool recycling);该方法有两个参数:第一个参数queryFilter 为一个 IQueryFilter 对象,用于指定查询的条件了;第二个参数recycling 为一个 Bool 数据类型,表示查询结果游标是否循环。该方法的返回值为一个IFeatureCursor 对象,该游标对象表示查询的结果对象。下面就分别根据属性条件查询对象和根据几何条件查询对象来介绍空间数据查询的过程:一、根据属性条件查询对象首先新建一个项目,设置项目名称为“ 空间数据查询” ,并在窗体上添加如下图所示控件(axMapControl1 、axTOCControl1 、axLicenseCon
3、trol1 、axToolbarControl1 ):同 时 为 了 便 于 设 置 条 件 来 查 询 对 象 , 添 加 如 下 图 所 示 控 件 ( layerComboBox 、queryFiltertextBox 和根据属性条件查询对象):其中,layerComboBox 控件用于表示要查询的图层,queryFiltertextBox控件表示查询的条件。1、定义刷新图层函数在每次添加新数据或打开新地图时,都要更新layerComboBox控件中的显示项来表示当前地图中的图层。定义刷新图层函数RefreshLayer(),其代码如下:private void RefreshLayer
4、() layerComboBox.Items.Clear();for (int i = 0; i 2) DrawPolygon(pointCollection, axMapControl1); 4)查询范围内对象设计当鼠标在axMapControl1 控件上双击时即完成面范围的绘制,所以执行面范围的查询就在axMapControl1 的 OnDoubleClick()事件中,如下代码所示: private void axMapControl1_OnDoubleClick(object sender, ESRI.ArcGIS.Controls.IMapControlEvents2_OnDoubl
5、eClickEvent e) if(DoQueryIndex = 2)/ 面范围查询 ESRI.ArcGIS.Geometry.IPoint point = new ESRI.ArcGIS.Geometry.PointClass(); point.PutCoords(e.mapX, e.mapY); pointCollection.AddPoints(1, ref point); if (pointCollection.PointCount 2) axMapControl1.Refresh(); ESRI.ArcGIS.Carto.IFeatureLayer pFeatureLayer = a
6、xMapControl1.get_Layer(layerComboBox.SelectedIndex) as ESRI.ArcGIS.Carto.IFeatureLayer; ESRI.ArcGIS.Geometry.IPolygon pPolygon; pPolygon = (ESRI.ArcGIS.Geometry.IPolygon)pointCollection; ESRI.ArcGIS.Geodatabase.ISpatialFilter spatialFilter = new ESRI.ArcGIS.Geodatabase.SpatialFilterClass(); spatialF
7、ilter.Geometry = pPolygon; spatialFilter.SpatialRel = ESRI.ArcGIS.Geodatabase.esriSpatialRelEnum.esriSpatialRelIntersects; ESRI.ArcGIS.Geodatabase.IFeatureCursor featureCursor = pFeatureLayer.Search(spatialFilter, false); ESRI.ArcGIS.Geodatabase.IFeature pFeature; int featureCount = 0; while (pFeatu
8、re = featureCursor.NextFeature() != null) 名师资料总结 - - -精品资料欢迎下载 - - - - - - - - - - - - - - - - - - 名师精心整理 - - - - - - - 第 6 页,共 7 页 - - - - - - - - - axMapControl1.FlashShape(pFeature.Shape); featureCount+; MessageBox.Show(选择范围内共有 + featureCount.ToString() + 个对象 !); 调用几何条件查询在“ 根据几何条件查询对象” 按钮的Click()
9、 事件中完成,所以在调用面范围查询时还需要对全局变量pointCollection 进行实例化,所以“ 根据几何条件查询对象” 按钮 Click() 事件的代码如下: private void 根据几何条件查询对象_Click(object sender, EventArgs e) if ( 根据几何条件查询对象.Text = 根据几何条件查询对象) if (pointRadioButton.Checked)/ 点击查询 DoQueryIndex = 1; else if (polygonRadioButton.Checked)/ 面范围查询 DoQueryIndex = 2; pointCollection = new ESRI.ArcGIS.Geometry.PolygonClass(); 根据几何条件查询对象.Text = 停止几何条件查询对象; else 根据几何条件查询对象.Text = 根据几何条件查询对象; DoQueryIndex = 0; 名师资料总结 - - -精品资料欢迎下载 - - - - - - - - - - - - - - - - - - 名师精心整理 - - - - - - - 第 7 页,共 7 页 - - - - - - - - -
限制150内