arcgis engine查询系统设计代码
时间: 2023-06-20 15:04:45 浏览: 128
ArgisEngine查询代码
以下是一个简单的ArcGIS Engine查询系统设计代码示例,包括创建地图控件、添加图层、设置查询条件、执行查询以及显示结果等功能:
```csharp
using ESRI.ArcGIS.SystemUI;
using ESRI.ArcGIS.Carto;
using ESRI.ArcGIS.Geodatabase;
using ESRI.ArcGIS.ADF.BaseClasses;
using ESRI.ArcGIS.ADF.CATIDs;
using ESRI.ArcGIS.Controls;
using ESRI.ArcGIS.Geometry;
namespace ArcGISQuerySystem
{
public partial class Form1 : Form
{
private IMapControl3 mapControl;
private IFeatureLayer featureLayer;
private IFeatureLayerDefinition featureLayerDef;
private IQueryFilter queryFilter;
public Form1()
{
InitializeComponent();
InitializeMapControl();
AddFeatureLayer();
}
private void InitializeMapControl()
{
mapControl = new MapControl();
mapControl.Dock = DockStyle.Fill;
panel1.Controls.Add((Control)mapControl);
}
private void AddFeatureLayer()
{
IWorkspaceFactory workspaceFactory = new ShapefileWorkspaceFactory();
IWorkspace workspace = workspaceFactory.OpenFromFile(@"C:\data", 0);
IFeatureWorkspace featureWorkspace = (IFeatureWorkspace)workspace;
IFeatureClass featureClass = featureWorkspace.OpenFeatureClass("cities");
featureLayer = new FeatureLayer();
featureLayer.FeatureClass = featureClass;
featureLayer.Name = "Cities";
mapControl.Map.AddLayer((ILayer)featureLayer);
}
private void btnQuery_Click(object sender, EventArgs e)
{
string cityName = txtCityName.Text;
string queryExpression = "CITY_NAME = '" + cityName + "'";
queryFilter = new QueryFilter();
queryFilter.WhereClause = queryExpression;
featureLayerDef = (IFeatureLayerDefinition)featureLayer;
featureLayerDef.DefinitionExpression = queryExpression;
mapControl.Map.ClearSelection();
mapControl.ActiveView.PartialRefresh(esriViewDrawPhase.esriViewGeography, null, null);
IFeatureCursor featureCursor = featureLayer.FeatureClass.Search(queryFilter, true);
IFeature feature = featureCursor.NextFeature();
while (feature != null)
{
mapControl.Map.SelectFeature(featureLayer, feature);
feature = featureCursor.NextFeature();
}
mapControl.ActiveView.PartialRefresh(esriViewDrawPhase.esriViewGeoSelection, null, null);
}
}
}
```
在该示例中,我们首先创建了一个地图控件,并将其添加到 Windows 窗体中的一个面板中。接着,我们从一个 Shapefile 工作空间中打开一张名为 “cities” 的城市要素类,并将其添加到地图控件中作为一个矢量图层。然后,我们在查询按钮的点击事件中构造一个查询表达式,并将其设置为图层的筛选条件,以实现按城市名查询的功能。最后,我们使用 IFeatureCursor 对象遍历查询结果,并将查询到的要素在地图控件中高亮显示出来。
阅读全文