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; }
相关文章推荐
- How to fix the issue that GEM_HOME and/or GEM_PATH not set issue for rvm in mac version 10.12
- How to limit an array of similar hashes to those that have more than one of the same key:value pair
- sql: Query to Display Foreign Key Relationships and Name of the Constraint for Each Table in Database
- How to set the default input focus on a field in an HTML web form
- How-to find the SQL that using lots of temp tablespace in Oracle
- How can I set the background of UITableView (the tableview style is "Grouped") to use an image?
- how to loop through the Params property for a page and how to display each key/value pair
- [Tips] How to Add New field into Shapefile attribute table in ArcGIS ?
- How to know whether the attribute belongs to one types of productin Magento?
- How to access the features in an in-memory output layer using an IFeatureCursor
- How to find child controls that are located in the template of a parent control
- How to get the field descriptions of a table?
- How do you copy the contents of an array to a std::vector in C++ without looping? (From stack over flow)
- HOW TO: Change the Owner of a User-Defined Data Type That Is in Use in SQL Server 2000
- How to popup a UIPickerView from the bottom of a UIScrollView in response to UITextField selection
- [entity framework ] The conversion of a char data type to a datetime data type resulted in an out-of-range datetime value.
- How do I sort an array of hashes by a value in the hash?
- How to get the MouseEvent coordinates for an element that has CSS3 Transform?
- How to access the features in an in-memory output layer using an IFeatureCursor
- flex/in the datagrid,how to get the new value of cell in the datagrid after edit