Query map image sublayer

View inWPFUWPFormsiOSAndroid
View on GitHub

Find features in a sublayer based on attributes and location.

Image of query map image sublayer

Use case

Sublayers of an ArcGISMapImageLayer may expose a ServiceFeatureTable through a table property. This allows you to perform the same queries available when working with a table from a FeatureLayer: attribute query, spatial query, statistics query, query for related features, etc. An image layer with a sublayer of counties can be queried by population to only show those above a minimum population.

How to use the sample

Specify a minimum population in the input field (values under 1810000 will produce a selection in all layers) and tap the query button to query the sublayers in the current view extent. After a short time, the results for each sublayer will appear as graphics.

How it works

  1. Create an ArcGISMapImageLayer object using the URL of an image service.
  2. After loading the layer, get the sublayer you want to query with (ArcGISMapImageSublayer) layer.Sublayers[index].
  3. Load the sublayer, and then get its ServiceFeatureTable with sublayer.getTable().
  4. Create QueryParameters. You can set queryParameters.WhereClause to query against a table attribute and/or set queryParameters.Geometry to limit the results to an area of the map.
  5. Call sublayerTable.QueryFeaturesAsync(queryParameters) to get a FeatureQueryResult with features matching the query. The result is an iterable of features.

Relevant API

  • ArcGISMapImageLayer
  • ArcGISMapImageSublayer
  • QueryParameters
  • ServiceFeatureTable

About the data

The ArcGISMapImageLayer in the map uses the "USA" map service as its data source. This service is hosted by ArcGIS Online, and is composed of four sublayers: "states", "counties", "cities", and "highways". Since the cities, counties, and states tables all have a POP2000 field, they can all execute a query against that attribute and a map extent.

Tags

search and query

Sample Code

MapImageSublayerQuery.xamlMapImageSublayerQuery.xaml.cs
                                                                
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
<?xml version="1.0" encoding="utf-8" ?>
<ContentPage
    x:Class="ArcGISRuntime.Samples.MapImageSublayerQuery.MapImageSublayerQuery"
    xmlns="http://xamarin.com/schemas/2014/forms"
    xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
    xmlns:esriUI="clr-namespace:Esri.ArcGISRuntime.Xamarin.Forms;assembly=Esri.ArcGISRuntime.Xamarin.Forms">
    <Grid>
        <esriUI:MapView x:Name="MyMapView" />
        <Frame
            Margin="20"
            BackgroundColor="White"
            HorizontalOptions="Center"
            VerticalOptions="Start"
            WidthRequest="250">
            <Grid Margin="5">
                <Grid.RowDefinitions>
                    <RowDefinition />
                    <RowDefinition />
                </Grid.RowDefinitions>
                <Grid.ColumnDefinitions>
                    <ColumnDefinition />
                    <ColumnDefinition />
                </Grid.ColumnDefinitions>
                <Label
                    Grid.Row="0"
                    Grid.Column="0"
                    Margin="2"
                    HorizontalOptions="End"
                    Text="[POP2000] &gt; "
                    VerticalOptions="Center">
                    <Label.TextColor>
                        <OnPlatform x:TypeArguments="Color">
                            <On Platform="Android" Value="DarkBlue" />
                        </OnPlatform>
                    </Label.TextColor>
                </Label>
                <Entry
                    x:Name="PopulationTextBox"
                    Grid.Row="0"
                    Grid.Column="1"
                    Margin="2"
                    HorizontalOptions="Fill"
                    HorizontalTextAlignment="End"
                    Text="1810000"
                    VerticalOptions="Center">
                    <Entry.TextColor>
                        <OnPlatform x:TypeArguments="Color">
                            <On Platform="Android" Value="DarkBlue" />
                        </OnPlatform>
                    </Entry.TextColor>
                </Entry>
                <Button
                    x:Name="QuerySublayers"
                    Grid.Row="1"
                    Grid.Column="0"
                    Grid.ColumnSpan="2"
                    Margin="2"
                    Clicked="QuerySublayers_Click"
                    Text="Query in extent"
                    VerticalOptions="Center" />
            </Grid>
        </Frame>
    </Grid>
</ContentPage>

Your browser is no longer supported. Please upgrade your browser for the best experience. See our browser deprecation post for more details.