Read table values from offline goedatabase

418
2
Jump to solution
12-05-2023 03:07 PM
Labels (2)
MoyerSolutions
New Contributor III

Hello! This is a follow up to a previous question.

I am trying to read the values in a table. I guess their called attributes in this context. How do I enumerate the rows in the table and read the actual values of the fields?

Its an offline geodatabase, its is correctly download via the GeodatabaseSyncTask.GenerateGeodatabase()

Now I am trying to enumerate the values in the fields. The fields are loaded via table.LoadAsync(), and the field object contains the Field Name and other properties, but not the value.

I think I need ArcGISFeature.GetAttributeValue(field)? But how do I get the feature object from the table?

foreach (GeodatabaseFeatureTable table in geodatabase.GeodatabaseFeatureTables) {
    await table.LoadAsync();
    string message = "";
    foreach (Field field in table.Fields) {
        ArcGISFeature feature = ?????
        object value = feature.GetAttributeValue(field);
        message += "\n" + field.Name + ": " + value;
    }
    await Application.Current.MainPage.DisplayAlert(table.TableName, message, "OK");
}

 

0 Kudos
1 Solution

Accepted Solutions
AndyWeis
Esri Contributor

Hi @MoyerSolutions ,  a quick way to get the values you're looking for is as follows:

  1. Add a call to `QueryFeaturesAsync` on the table in question with an empty `WhereClause` (this will grab every feature available)
  2. Assign the result of this to a new `FeatureQueryResult` object.
  3. Iterate through the fields in the table and each feature from this result. This will give you each feature in default order.
foreach (GeodatabaseFeatureTable table in geodatabase.GeodatabaseFeatureTables)
{
    await table.LoadAsync();
    string message = "";
    QueryParameters queryParams = new QueryParameters()
    {
        WhereClause = ""
    };
    FeatureQueryResult result = await table.QueryFeaturesAsync(queryParams);
    foreach (Field field in table.Fields)
    {
        foreach (ArcGISFeature feature in result)
        {
            object value = feature.GetAttributeValue(field);
            message += "\n" + field.Name + ": " + value;
        }
        await Application.Current.MainPage.DisplayAlert(table.TableName, message, "OK");
    }
}

View solution in original post

2 Replies
AndyWeis
Esri Contributor

Hi @MoyerSolutions ,  a quick way to get the values you're looking for is as follows:

  1. Add a call to `QueryFeaturesAsync` on the table in question with an empty `WhereClause` (this will grab every feature available)
  2. Assign the result of this to a new `FeatureQueryResult` object.
  3. Iterate through the fields in the table and each feature from this result. This will give you each feature in default order.
foreach (GeodatabaseFeatureTable table in geodatabase.GeodatabaseFeatureTables)
{
    await table.LoadAsync();
    string message = "";
    QueryParameters queryParams = new QueryParameters()
    {
        WhereClause = ""
    };
    FeatureQueryResult result = await table.QueryFeaturesAsync(queryParams);
    foreach (Field field in table.Fields)
    {
        foreach (ArcGISFeature feature in result)
        {
            object value = feature.GetAttributeValue(field);
            message += "\n" + field.Name + ": " + value;
        }
        await Application.Current.MainPage.DisplayAlert(table.TableName, message, "OK");
    }
}
MoyerSolutions
New Contributor III

Aha! I was knew I was close... Thank you!

0 Kudos