1

I want to get all fieldnames of feature class and then read data in each field. I have used table.fieldDef, table.fieldinformation but i am unable to get fieldnames if featureclass.

My code which i have tried so far is as follows:

Table table = geodatabase.OpenTable("sw_Manhole");
// Iterate through the results, populating the results vector.
foreach (Row row in table.Search("*", "", RowInstance.Recycle))
    {
        count++;
        city currentCity = new city();
        PointShapeBuffer geometry = row.GetGeometry();
        Esri.FileGDB.Point point = geometry.point;
        currentCity.xCoord = point.x;
        currentCity.yCoord = point.y;
    }

I have also tried row.fieldDef and row.fieldinformation but i am not getting names of field.

  • Please always specify the product and version in each and every question you ask. – Vince Oct 29 '15 at 14:43
  • This question doesn't provide an MCVE, which would be just the first line of the current code, plus your failed efforts at FieldDef and/or FieldInformation – Vince Oct 29 '15 at 15:01
3

To get the field names of a feature class you can use the following code:

ITable table = featWorkSpace.OpenTable("sw_Manhole");
for (int i = 0; i < table.Fields.FieldCount; i++)
{
    IField field = table.Fields.Field[i];
    string fieldName = field.Name;
    string fieldAlias = field.AliasName;
}

The second question was how to read data of your table. You have to identify the Field by name (for example the attribute "Source"):

int idSource = table.FindField("Source");

You can use this idSource to read the information of an IRow

ICursor cur = table.Search(null, true);
if (cur != null)
{
    IRow row = cur.NextRow();
    while (row != null)
    {
        var help = row.get_Value(idSource);

        //here you can make a type cast and check against DBNull...

        row = cur.NextRow();
    }
}
  • 1
    This is ArcObjects, but the question is about the file geodatabase API (albeit tagged incorrectly, and not explicitly mentioned in the question body) – Vince Oct 29 '15 at 10:51
1

The ...\FileGDB_API_VS2010_1_4\samplesC#\ExecutingSQL\ExecutingSQL.cs file contains an example of using FieldInfo, as retrieved by Row.FieldInformation (FieldDef is only used to make XML for table creation). You can also use Table.FieldInformation.

The doc seems to be missing the properties of FieldInfo (though they are shown in the sample). The following is the C++ equivalent:

typedef struct {
        wstring          name;
        FieldType        type;
        ...
        } binding_t;

        binding_t        *pb;
        binding_t         bindings[512];
        FieldInfo         finfo;
        fgdbError         hr;
        Geodatabase       geodatabase;
        int               i;
        int               ncols                         = 0;
        Table             table;
        wchar_t           gdbPath[FILENAME_MAX+1]       = L"";
        wchar_t           gdbTable[FILENAME_MAX+1]      = L"";

        // gdbPath and gdbTable populated elsewhere

/* .. Open FGDB
 */
        if ((hr = OpenGeodatabase(gdbPath,geodatabase)) != S_OK) {
                msg = L"Geodatabase not found";
                goto bailout;
        }

/* .. Open table
 */
        if ((hr = geodatabase.OpenTable(gdbTable,table)) != S_OK) {
                msg = L"Table not found";
                goto bailout;
        }

/* .. Describe table
 */
        if ((hr = table.GetFieldInformation(finfo)) != S_OK) {
                msg = L"Table not found";
                goto bailout;
        }

        if ((hr = finfo.GetFieldCount(ncols)) != S_OK) {
                msg = L"GetFieldCount failed";
                goto bailout;
        }

        pb = bindings;
        for (i = 0; i < ncols; i++,pb++) {
                finfo.GetFieldName(i,pb->name);
                finfo.GetFieldType(i,pb->type);
        }

Converting to C# is left as an exercise.

When you have question, I strongly recommend that you review the samples in addition to the documentation. The "support" mechanism for the FileGDB API is to post questions on GeoNet.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.