Get a cursor of Rows given a set of object ids.
[Visual Basic 6.0] Function GetFeatures(
ByVal fids As Variant, _
ByVal Recycling As Boolean _
) As IFeatureCursor
[Visual Basic .NET] Public Function GetFeatures ( _ ByVal fids As Object, _ ByVal Recycling As Boolean _ ) As IFeatureCursor
[C#] public IFeatureCursor GetFeatures ( object fids, bool Recycling );
[Java] public IFeatureCursor getFeatures ( Object fids, Boolean Recycling ) throws IOException, AutomationException
[C++] HRESULT GetFeatures( VARIANT fids, VARIANT_BOOL Recycling, IFeatureCursor** Cursor );
Parameters
fids [in]
fids is a parameter of type VARIANT
Recycling [in]
Recycling is a parameter of type VARIANT_BOOL
Cursor [out, retval]
Cursor is a parameter of type IFeatureCursor
GetFeatures will return an IFeatureCursor which contains all the features in the feature class with the given Object IDs (OID). This method can be used to loop through a particular set of features that you know the OIDs for.
Calling the GetFeatures method in IFeatureClass has the same effect as calling the GetRows method in ITable except that the IFeatureClass method returns the IFeatureCursor interface on the returned cursor.
//e.g, nameOfField = "Symbol"
public void IFeatureClass__GetFeatures(IFeatureClass featureClass, string nameOfField)
{
//get the index of the field we are interested in
int fieldIndexValue = featureClass.FindField(nameOfField);
System.Collections.Generic.List<int> constructoidList = new System.Collections.Generic.List<int>();
constructoidList.Add(1);
constructoidList.Add(2);
constructoidList.Add(3);
constructoidList.Add(4);
constructoidList.Add(10);
int[] oidList = constructoidList.ToArray();
IFeatureCursor featureCursor = featureClass.GetFeatures(oidList, false);
IFeature feature = featureCursor.NextFeature();
// loop through the returned features and get the value for the field
while (feature != null)
{
//do something with each feature(ie update geometry or attribute)
Console.WriteLine("The {0} field contains a value of {1}", nameOfField, feature.get_Value(fieldIndexValue));
feature = featureCursor.NextFeature();
}
}
The following example loops through a set of features of the feature class and pops up a message box with the value of a particular field for each of those features.
Dim pFeatcls As IFeatureClass
Dim pFeatLayer As IFeatureLayer
Dim pDoc As IMxDocument
Dim pMap As IMap
Set pDoc = ThisDocument
Set pMap = pDoc.Maps.Item(0)
Set pFeatLayer = pMap.Layer(0)
Set pFeatcls = pFeatLayer.FeatureClass
' get the index of the field we are intersected in
Dim lFld As Long
lFld = pFeatcls.FindField("SYMBOL")
Dim iOIDList() As Long
Dim iOIDListCount As Long
Dim pFeatureCursor As IFeatureCursor
iOIDListCount = 5
ReDim iOIDList(iOIDListCount)
iOIDList(0) = 1
iOIDList(1) = 2
iOIDList(2) = 3
iOIDList(3) = 4
iOIDList(4) = 5
Set pFeatureCursor = pFeatcls.GetFeatures(iOIDList, False)
' loop through the first 10 features and get the value for the field
Dim pFeat As IFeature
Set pFeat = pFeatureCursor.NextFeature
While Not pFeat Is Nothing
' do something with each feature.
MsgBox pFeat.Value(lFld)
Set pFeat = pFeatureCursor.NextFeature
Wend
IFeatureClass Interface | IFeature Interface | IFeatureCursor Interface