//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;
}

相关文章:

  • 2022-12-23
  • 2021-09-04
  • 2022-12-23
  • 2021-11-05
  • 2022-12-23
  • 2021-08-25
  • 2021-07-20
  • 2021-10-02
猜你喜欢
  • 2022-12-23
  • 2022-12-23
  • 2021-10-31
  • 2021-09-26
  • 2022-03-08
  • 2022-02-03
相关资源
相似解决方案