[GIS] Retrieve data from FeatureClass

arcmaparcobjectscfeatures

I have :

  • FeatureClass (Structure)
  • column (Type)
  • column (OID)

I am trying to get the (Type) for specific OID.
I tried to use this code but it dose not work.

IFeatureWorkspace featureWorkspace = (IFeatureWorkspace)workspace;
IFeatureClass testFeatureClass = featureWorkspace.OpenFeatureClass("Structure");
IQueryFilter queryFilter = new QueryFilterClass();
queryFilter.SubFields = "Type";
queryFilter.WhereClause = "OBJECTID = " + feature.OID;
IFeatureCursor fCursor = testFeatureClass.Search(queryFilter, true);

I don't know what is the wrong, any help would be appreciated.

Best Answer

You can get field value by doing the following. 1. Select your feature. 2. Cursor through feature to see if selection set is > 1 (below is code example for step 2).

IFeatureSelection pFSel = default(IFeatureSelection);
pFSel = pFLayer;
ESRI.ArcGIS.Geodatabase.ISelectionSet2 pSelSet = default(ESRI.ArcGIS.Geodatabase.ISelectionSet2);
pSelSet = pFSel.SelectionSet;
if (pSelSet.Count < 1) {
    MsgBox("No Features Selected")
    return;
}

ESRI.ArcGIS.Geodatabase.IFeatureCursor pFCursor = null;
pSelSet.Search(null, false, pFCursor);

IFeature pFeature = default(IFeature);
pFeature = pFCursor.NextFeature;
// Get First Feature
if (pFeature == null) {
    Interaction.MsgBox("No Features Selected!");
    // Just in case, but probably already taken care of earlier
    return;
}

long lFIndex = 0;
lFIndex = pFCursor.FindField(m_strGridIndexField);
// Replace with your field name
if (lFIndex > -1) {
    // Substute the correct data type to match the field type
    while ((pFeature != null)) {
        m_fValue = pFeature.Value(lFIndex);
        // Do something with the value stored in fValue
        pFeature = pFCursor.NextFeature;
    }
}
Related Question