Missing attributes after pulling a feature from feature service

525
2
Jump to solution
07-31-2017 04:06 PM
YifanLiu
New Contributor II

Hi,

I encountered a strange issue with pulling data from the feature service. The problem is that a feature pulled from a feature service loses some of the fields that was in its feature table. What I am doing is I pulled a feature layer hosted on the portal and queried the feature layer. The result feature, however, only contains a portion of the fields that are in its feature table.

Here I first created a feature layer from a service feature table.

string url = "*******/FeatureServer/0";
Uri uri = new Uri(url);
ServiceFeatureTable sft = new ServiceFeatureTable(uri);
_mapViewModel.fireExLayer = new FeatureLayer(sft);

 Then I query the feature layer and get the Selectedfeature. (I removed error checking code here)

var queryParams = convertTapToQuery(e.Location.X, e.Location.Y, 1);
var result = await _mapViewModel.fireExLayer.SelectFeaturesAsync(queryParams, SelectionMode.New);‍‍‍‍‍‍
_mapViewModel.SelectedFeature = result.ToList()[0];

At last, I try to get the attributes of the SelectedFeature by doing this:

As seen in the screenshot, for each field in the feature table of a feature, I tried to get the attribute value of that field, but this triggers an exception, whose message says “the given key was not present in the dictionary.” I was bewildered seeing the field from a feature’s own feature table is not a key in the feature’s attribute dictionary.

What am I doing wrong here? Appreciate any help and thoughts!

Best,

Yifan

Reply
0 Kudos
1 Solution

Accepted Solutions
JenniferNery
Esri Regular Contributor

Features from SelectFeaturesAsync and QueryFeaturesAsync are usually not loaded unless you pass QueryFeatureFields.LoadAll parameter in QueryFeaturesAsync so by default it would contain the minimal set of fields that are used for rendering the feature. You can use the following code to test using the service Nagma provided.

            try
            {
                var layer = MyMapView.Map.OperationalLayers.FirstOrDefault(l => l is FeatureLayer) as FeatureLayer;
                var query = new QueryParameters() { WhereClause = "typdamage = 'Major'" };
                var result = await ((ServiceFeatureTable)layer.FeatureTable).QueryFeaturesAsync(query, QueryFeatureFields.LoadAll);
                foreach (ArcGISFeature f in result.ToArray())
                {
                    if (f.LoadStatus != LoadStatus.Loaded)
                        await f.LoadAsync();
                    // Update attributes here.
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message, ex.GetType().Name);
            }

You can pass the result of this query to SelectFeatures to mark them selected.

View solution in original post

2 Replies
NagmaYasmin
Occasional Contributor III

Hi Yifan,

I am seeing the same issue at my side while testing with the feature service, Layer: Damage to Residential Buildings (ID: 0) to retrieve the attribute values of the feature(s).

I noticed that for the numeric data (field:numoccup), it always gives the same error as you receive.

For the string field:"typdamage", doesn't give that error but for the string field: "descdamage" always gives the same error no matter whatever the value is.

Best,

Nagma

Reply
0 Kudos
JenniferNery
Esri Regular Contributor

Features from SelectFeaturesAsync and QueryFeaturesAsync are usually not loaded unless you pass QueryFeatureFields.LoadAll parameter in QueryFeaturesAsync so by default it would contain the minimal set of fields that are used for rendering the feature. You can use the following code to test using the service Nagma provided.

            try
            {
                var layer = MyMapView.Map.OperationalLayers.FirstOrDefault(l => l is FeatureLayer) as FeatureLayer;
                var query = new QueryParameters() { WhereClause = "typdamage = 'Major'" };
                var result = await ((ServiceFeatureTable)layer.FeatureTable).QueryFeaturesAsync(query, QueryFeatureFields.LoadAll);
                foreach (ArcGISFeature f in result.ToArray())
                {
                    if (f.LoadStatus != LoadStatus.Loaded)
                        await f.LoadAsync();
                    // Update attributes here.
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message, ex.GetType().Name);
            }

You can pass the result of this query to SelectFeatures to mark them selected.

View solution in original post