Arcgis二次开发-ArcEngine属性查询
FeatureLayer类用于操作要素的集合和可视化表达,实现了IFeatureLayer接口和IFeatureSelection接口,其中与查询相关的方法包括Search和SelectionFeature。FeatureCursor类是用于操作要素的游标类,实现了IFeatureCursor接口,主要方法包括NextFeature,用于移动游标位置并返回要素对象。FeatureClass类用于控
在ArcGIS.Geodatabase命名空间中,与属性查询功能相关的主要类包括QueryFilter、QueryDef、Cursor、FeatureCursor等。这些类涉及的接口有IQueryFilter、IQueryDef、ICursor、IFeatureCursor以及IFeatureSelection等。
- QueryFilter类
QueryFilter类用于根据属性值或关系来过滤数据,它实现了IQueryFilter接口,提供以下主要方法和属性:
- WhereClause属性:设置用于过滤数据的SQL条件子句,可以使用运算符、通配符、函数等构建条件。
- SubField属性:定义过滤所需的属性字段列表。
- QueryDef类
QueryDef类是ESRI的查询定义类,用于创建基于属性的查询。它实现了IQueryDef接口,包含以下属性和方法:
- Tables属性:定义所查询表的名称和列表。
- WhereClause属性:定义查询的条件。
- SubField属性:定义需要返回的字段。
- Evaluate方法:执行查询并返回结果游标。
- Cursor类
Cursor类是用于操作数据行的类,实现了ICursor接口,提供以下功能:
- NextRow方法:将游标位置向前移动一位,并返回该位置的行对象。
- FeatureCursor类
FeatureCursor类是用于操作要素的游标类,实现了IFeatureCursor接口,主要方法包括NextFeature,用于移动游标位置并返回要素对象。
- FeatureLayer类
FeatureLayer类用于操作要素的集合和可视化表达,实现了IFeatureLayer接口和IFeatureSelection接口,其中与查询相关的方法包括Search和SelectionFeature。
- FeatureClass类
FeatureClass类用于控制要素类的属性和行为,主要方法包括search和Select,用于执行查询并选择相应的要素。
private void frmQueryByAttribute_Load(object sender, EventArgs e)
{
try
{
comboBoxLayerName.Items.Clear();
string layerName;
for (int i = 0; i < currentMap.LayerCount; i++)
{
if (currentMap.get_Layer(i) is GroupLayer)
{
ICompositeLayer compositeLayer = currentMap.get_Layer(i) as ICompositeLayer;
for (int j = 0; j < compositeLayer.Count; j++)
{
layerName = compositeLayer.get_Layer(j).Name;
comboBoxLayerName.Items.Add(layerName);
}
}
else
{
layerName = currentMap.get_Layer(i).Name;
comboBoxLayerName.Items.Add(layerName);
}
}
comboBoxLayerName.SelectedIndex = 0;
comboBoxSelectMethod.SelectedIndex = 0;
}
catch { }
}
private void comboBoxLayerName_SelectedIndexChanged(object sender, EventArgs e)
{
listBoxFields.Items.Clear();
listBoxValues.Items.Clear();
IField field;
for (int i = 0; i < currentMap.LayerCount; i++)
{
if (currentMap.get_Layer(i) is GroupLayer)
{
ICompositeLayer compositeLayer = currentMap.get_Layer(i) as ICompositeLayer;
for (int j = 0; j < compositeLayer.Count; j++)
{
if (compositeLayer.get_Layer(j).Name == comboBoxLayerName.SelectedItem.ToString())
{
currentFeatureLayer = compositeLayer.get_Layer(j) as IFeatureLayer;
break;
}
}
}
else
{
if (currentMap.get_Layer(i).Name == comboBoxLayerName.SelectedItem.ToString())
{
currentFeatureLayer = currentMap.get_Layer(i) as IFeatureLayer;
break;
}
}
}
for (int i = 0; i < currentFeatureLayer.FeatureClass.Fields.FieldCount; i++)
{
field = currentFeatureLayer.FeatureClass.Fields.get_Field(i);
if (field.Name.ToUpper() != "SHAPE")
listBoxFields.Items.Add("\"" + field.Name + "\"");
}
labelwhere.Text = currentFeatureLayer.Name + " WHERE:";
textBoxWhere.Clear();
}
private void listBoxFields_SelectedIndexChanged(object sender, EventArgs e)
{
listBoxValues.Items.Clear();
if (buttonGetUniqeValue.Enabled == false)
buttonGetUniqeValue.Enabled = true;
string str = listBoxFields.SelectedItem.ToString();
str = str.Substring(1);
str = str.Substring(0, str.Length - 1);
currentFieldName = str;
}
private void buttonGetUniqeValue_Click(object sender, EventArgs e)
{
try
{
IDataset dataset = (IDataset)currentFeatureLayer.FeatureClass;
IQueryDef queryDef = ((IFeatureWorkspace)dataset.Workspace).CreateQueryDef();
queryDef.Tables = dataset.Name;
queryDef.SubFields = "DISTINCT (" + currentFieldName + ")";
ICursor cursor = queryDef.Evaluate();
IFields fields = currentFeatureLayer.FeatureClass.Fields;
IField field = fields.get_Field(fields.FindField(currentFieldName));
IRow row = cursor.NextRow();
while (row != null)
{
if (field.Type == esriFieldType.esriFieldTypeString)
{
listBoxValues.Items.Add("\'" + row.get_Value(0).ToString() + "\'");
}
else
{
listBoxValues.Items.Add(row.get_Value(0).ToString());
}
row = cursor.NextRow();
}
}
catch
{
}
}
更多推荐
所有评论(0)