Find features in a spatial table related to features in a non-spatial table.
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
- Create an
ArcGISMapImageLayer
with the URL of a map image service. - Load the layer and get one of its tables with
imageLayer.Tables[index]
. - To query the table, create a
QueryParameters
object.You can setqueryParameters.WhereClause
to filter the request features. - Use
table.QueryFeaturesAsync(parameters)
to get aFeatureQueryResult
object. - The
FeatureQueryResult
is an iterable, so simply loop through it to get each resultFeature
. - To query for related features, get the table's relationship info with
table.LayerInfo.RelationshipInfos
. This returns a list ofRelationshipInfo
objects. Choose which one to base your query on. - Now create
RelatedQueryParameters
passing in theRelationshipInfo
. To query related features, usetable.QueryRelatedFeaturesAsync(feature, relatedQueryParameters)
. - This returns a list of
RelatedFeatureQueryResult
objects, each containing a set of related features.
Relevant API
- ArcGISFeature
- ArcGISMapImageLayer
- Feature
- FeatureQueryResult
- QueryParameters
- RelatedFeatureQueryResult
- RelatedQueryParameters
- RelationshipInfo
- ServiceFeatureTable
Additional information
You can use arcGISMapImageLayer.LoadTablesAndLayersAsync()
to recursively load all sublayers and tables associated with a map image layer.
Tags
features, query, related features, search
Sample Code
<UserControl x:Class="ArcGISRuntime.WinUI.Samples.MapImageLayerTables.MapImageLayerTables"
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>