Retrieve records from related table in ArcGIS Runtime SDK for .NET

4559
20
Jump to solution
07-25-2017 07:01 AM
MiriEshel
New Contributor III

Hi everybody,

We are using ArcGIS Runtime 100.1 and we want to retrieve records from a related table in a FeatureService.

We are able to perform QueryRelatedFeaturesAsync and get the number of features by using NumberOfFeatures but we cannot find any method/property to retrieve the data itself.

Here is the code we are using:

// Select the features based on query parameters defined above
var selectedFeatures = await idLayer.SelectFeaturesAsync(queryParams, Esri.ArcGISRuntime.Mapping.SelectionMode.New);
var feature = selectedFeatures.First() as ArcGISFeature;
var relatedResult = await table.QueryRelatedFeaturesAsync(feature);
var relatedTbl = relatedResult[0].RelatedTable;

var num = relatedTbl.NumberOfFeatures;

What next??

Thanks a lot,

Miri

0 Kudos
20 Replies
NagmaYasmin
Occasional Contributor III

Hi Chad,

I found a bug that is related with your issue but logged against Android 100.1. I believe you are seeing the same issue with .Net 100.1 as well. Below is the bug:


[BUG-000106463: GeodatabaseFeatureTable.queryRelatedFeaturesAsync does not return the related records when using ArcGIS Runtime SDK for Android 100.1.0. ]

Best,

Nagma

0 Kudos
ChadYoder1
Occasional Contributor II

Thanks, we're using Xamarin, so this impacts iOS, Android and UWP.

0 Kudos
JenniferNery
Esri Regular Contributor

Hi Chad,

The workflow you mentioned, consuming runtime content from ArcMap, should have also worked. I just checked that the issue Nagma referenced had something to do with related tables not participating in the same map which is why no related features were returned. This is a requirement per https://developers.arcgis.com/net/latest/wpf/api-reference//html/M_Esri_ArcGISRuntime_Data_ArcGISFea...

Are your related tables all part of the same map? 

Thanks.

0 Kudos
ChadYoder1
Occasional Contributor II

Yes, all of the tables (2 feature layers and 1 table) are all part of the same map.  

The relationship infos exist, but using QueryRelatedFeaturesAsync doesn't return any records.

I could share the geodatabase if that helps, but it's nothing complicated, just some parcel data I downloaded from the web for development and testing purposes.

Thanks.

0 Kudos
JenniferNery
Esri Regular Contributor

Sure that will be helpful, thanks! We will investigate, it sounds like a different issue then. 

0 Kudos
ChadYoder1
Occasional Contributor II

Thanks, I shared to geodatabase with you via Dropbox.  Let me know if you don't get it.

0 Kudos
JenniferNery
Esri Regular Contributor

Thanks, Chad for the geodatabase. I'm unable to repro with v100.1. It seems like the first relationship reports no related features and the rest of the tables have at least one related feature. Is this what you'd expect with your data?

I used the following code.. similar code for Xamarin Android, slight differences would be namespace how you retrieve file path and display alert messages.

public MainWindow()
{
    InitializeComponent();
    MyMapView.Map = new Map(Basemap.CreateTopographic());
    MyMapView.LayerViewStateChanged += OnLayerViewStateChanged;
    MyMapView.GeoViewTapped += OnGeoViewTapped;
}

private async void OnGeoViewTapped(object sender, GeoViewInputEventArgs e)
{
    try
    {
        var results = await MyMapView.IdentifyLayersAsync(e.Position, 2, false);
        var layerResult = results?.FirstOrDefault(f =>
        f.LayerContent is FeatureLayer &&
        ((FeatureLayer)f.LayerContent).FeatureTable is ArcGISFeatureTable &&
        f.GeoElements.Any());
        if (layerResult == null)
            return;
        var layer = (FeatureLayer)layerResult.LayerContent;
        var table = (ArcGISFeatureTable)layer.FeatureTable;
        var feature = (ArcGISFeature)layerResult.GeoElements.FirstOrDefault();
        var queryResults = await table.QueryRelatedFeaturesAsync(feature);
        foreach (var r in queryResults.ToArray())
        {
            MessageBox.Show($"Feature with ID `{feature.Attributes[table.ObjectIdField]}` has `{r.Count()}` related features from `{r.RelatedTable.TableName}`.");
        }
    }
    catch (Exception ex)
    {
        MessageBox.Show(ex.Message, ex.GetType().Name);
    }
}

private void OnLayerViewStateChanged(object sender, LayerViewStateChangedEventArgs e)
{
    var error = e.LayerViewState.Error ?? e.Layer.LoadError;
    if (error != null)
        MessageBox.Show(error.Message, error.GetType().Name);
}

private async void OnLoad(object sender, RoutedEventArgs e)
{
    try
    {
        var geodatabase = await Geodatabase.OpenAsync(@"E:\dev\palmbeach.geodatabase");
        var extent = geodatabase.GenerateGeodatabaseExtent as Envelope;
        foreach(var table in geodatabase.GeodatabaseFeatureTables)
        {
            await table.LoadAsync();
            if (table.HasGeometry)
            {
                if (extent == null || extent.IsEmpty)
                    extent = table.Extent;
                else
                    extent = GeometryEngine.CombineExtents(extent, table.Extent);
                MyMapView.Map.OperationalLayers.Add(new FeatureLayer(table));
            }
            else
                MyMapView.Map.Tables.Add(table);
            if (extent != null && !extent.IsEmpty)
                await MyMapView.SetViewpointAsync(new Viewpoint(extent));
        }
    }
    catch(Exception ex)
    {
        MessageBox.Show(ex.Message, ex.GetType().Name);
    }
}‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍
ChadYoder1
Occasional Contributor II

Thanks Jennifer, the results seem correct, but it is different from what I'm seeing.  

Was your test with WPF or UWP?

I have not tried in UWP, but Android and iOS were not showing the relationships.

I can easily plug in your code into these platforms and see what I get.  I'll report back once I have a chance to test.

Thanks!

0 Kudos
ChadYoder1
Occasional Contributor II

Jennifer, I have to apologize, I see that your code is in fact working in iOS and Android, so something is not right in my code/logic.

I'll continue to compare and get this figured out.

Again, I apologize for wasting your time, and certainly appreciate your help.

Thanks!!

0 Kudos
JenniferNery
Esri Regular Contributor

No problem at all. It wasn't a waste of time. You actively checked other ways to create geodatabase and query related features and those were very good feedback. I'm glad it's working for you too.

0 Kudos