View in MAUI WPF WinUI View on GitHub
import InlineCode from "@esri-dx/starship-doc-components/components/InlineCode.astro";

Find features in a spatial table related to features in a non-spatial table.

Image of map image layer tables

Use case

The non-spatial tables contained by a map service may contain additional information about sublayer features. Such information can be accessed by traversing table relationships defined in the service.

How to use the sample

Once the map image layer loads, a list view will be populated with comment data from non-spatial features. Click on one of the comments to query related spatial features and display the first result on the map.

How it works

  1. Create an
    with the URL of a map image service.
  2. Load the layer and get one of its tables with
    .
  3. To query the table, create a
    object.You can set
    to filter the request features.
  4. Use
    to get a
    object.
  5. The
    is an iterable, so simply loop through it to get each result
    .
  6. To query for related features, get the table’s relationship info with
    . This returns a list of
    objects. Choose which one to base your query on.
  7. Now create
    passing in the
    . To query related features, use
    .
  8. This returns a list of
    objects, each containing a set of related features.

Relevant API

  • ArcGISFeature
  • ArcGISMapImageLayer
  • Feature
  • FeatureQueryResult
  • QueryParameters
  • RelatedFeatureQueryResult
  • RelatedQueryParameters
  • RelationshipInfo
  • ServiceFeatureTable

About the data

This sample uses the ServiceRequests map image server, which is used to collect non-emergency requests for service from the general public.

Additional information

You can use

to recursively load all sublayers and tables associated with a map image layer.

Tags

features, query, related features, search

Sample Code

QueryRelatedFeaturesFromNonSpatialTable.xaml QueryRelatedFeaturesFromNonSpatialTable.xaml QueryRelatedFeaturesFromNonSpatialTable.xaml.cs
<UserControl x:Class="ArcGIS.WinUI.Samples.QueryRelatedFeaturesFromNonSpatialTable.QueryRelatedFeaturesFromNonSpatialTable"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:esriUI="using:Esri.ArcGISRuntime.UI.Controls">
<Grid>
<esriUI:MapView x:Name="MyMapView" />
<Border Style="{StaticResource BorderStyle}">
<Grid>
<Grid.RowDefinitions>
<RowDefinition Height="auto" />
<RowDefinition Height="*" />
</Grid.RowDefinitions>
<TextBlock Grid.Row="0"
FontWeight="SemiBold"
Text="Select a comment to see the related service request."
TextWrapping="Wrap" />
<ListBox x:Name="CommentsListBox"
Grid.Row="1"
MaxHeight="140"
Margin="0,5,0,0"
SelectionChanged="CommentsListBox_SelectionChanged"
SelectionMode="Single">
<ListBox.ItemTemplate>
<DataTemplate>
<TextBlock Text="{Binding Attributes[comments]}" />
</DataTemplate>
</ListBox.ItemTemplate>
</ListBox>
</Grid>
</Border>
</Grid>
</UserControl>