您的位置:首页 > 产品设计 > UI/UE

Here's an example that shows how to enumerate through the features of a selection set, returning the value of each field in the attribute table except for the geometry colum.

2007-07-21 08:56 1746 查看
//C#
private void SelectFeatures(IGeometry selectionShape, IFeatureLayer layer)
{
IFeatureClass featureClass = layer.FeatureClass;
ISpatialFilter filter = new SpatialFilterClass();
filter.Geometry = selectionShape;
filter.GeometryField = featureClass.ShapeFieldName;
filter.SpatialRel = esriSpatialRelEnum.esriSpatialRelIntersects;
ISelectionSet selectionSet = featureClass.Select(filter, esriSelectionType.esriSelectionTypeIDSet, esriSelectionOption.esriSelectionOptionNormal, null);
IEnumIDs enumIds = selectionSet.IDs;
enumIds.Reset();
int objectID = enumIds.Next();
IFeature feature = null;
List<string> fieldNames = GetFieldNames(featureClass);
while (objectID != -1)
{
feature = featureClass.GetFeature(objectID);
foreach (string name in fieldNames)
{
System.Diagnostics.Debug.WriteLine("Field " + name + "  : " + feature.get_Value(featureClass.FindField(name)));
}
objectID = enumIds.Next();
}
IFeatureSelection selection = layer as IFeatureSelection;
selection.SelectionSet = selectionSet;
this.axMapControl1.Refresh(esriViewDrawPhase.esriViewGeoSelection, layer, this.axMapControl1.ActiveView.ScreenDisplay.DisplayTransformation.VisibleBounds);
selection.SelectionChanged();
this.axMapControl1.Refresh(esriViewDrawPhase.esriViewGeoSelection, layer, this.axMapControl1.ActiveView.ScreenDisplay.DisplayTransformation.VisibleBounds);
}
private List<string> GetFieldNames(IFeatureClass featureClass)
{
IFields fields = featureClass.Fields;
List<string> fieldNames = new List<string>();
IField field = null;
for (int i = 0; i < fields.FieldCount; i++)
{
field = fields.get_Field(i);
if (field.Type != esriFieldType.esriFieldTypeGeometry)
{
fieldNames.Add(field.Name);
}
}
return fieldNames;
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: 
相关文章推荐