Query map image sublayer

View inQMLC++
View on GitHub
Sample viewer app

Find features in a sublayer based on attributes and location.

screenshot

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 click 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()::at(index).
  3. Load the sublayer, and then get its ServiceFeatureTable with sublayer::table().
  4. Create QueryParameters. You can use queryParameters::setWhereClause(sqlQueryString) to query against a table attribute and/or set queryParameters::setGeometry(extent) to limit the results to an area of the map.
  5. Call sublayerTable::queryFeatures(queryParameters) to get a FeatureQueryResult with features matching the query. The result is an iterable of features.

    Relevant API

  6. ServiceFeatureTable
  7. ArcGISMapImageLayer
  8. ArcGISMapImageLayer::loadTablesAndLayers
  9. ArcGISMapImageSublayer
  10. ArcGISMapImageSublayer::table
  11. QueryParameters

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.

Additional information

An ArcGISMapImageSublayer must be loaded before accessing its metadata or table. Use ArcGISMapImageLayer::loadTablesAndLayers to recursively load all sublayers and tables associated with a map image layer. Some sublayers do not have an associated table (group layers, for example) and some may not support specific types of queries. Consult the map service metadata for details.

Tags

Query, Sublayer, MapServer, Table

Sample Code

QueryMapImageSublayer.qmlQueryMapImageSublayer.cppQueryMapImageSublayer.h
                                                                                  
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
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
// [WriteFile Name=QueryMapImageSublayer, Category=Layers]
// [Legal]
// Copyright 2018 Esri.

// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
// http://www.apache.org/licenses/LICENSE-2.0

// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
// [Legal]

import QtQuick 2.6
import QtQuick.Window 2.3
import QtQuick.Controls 2.2
import Esri.Samples 1.0

QueryMapImageSublayerSample {
    id: rootRectangle
    clip: true
    width: 800
    height: 600



    // add a mapView component
    MapView {
        anchors.fill: parent
        objectName: "mapView"
    }

    Rectangle {
        anchors {
            fill: controlColumn
            margins: -5
        }
        color: "#efefef"
        radius: 5
        border {
            color: "darkgray"
            width: 1
        }
    }

    Column {
        id: controlColumn
        anchors {
            left: parent.left
            top: parent.top
            margins: 10
        }
        spacing: 5

        Row {
            spacing: 5
            Text {
                id: fieldText
                anchors.verticalCenter: parent.verticalCenter
                text: "POP2000 >"
            }

            TextField {
                id: populationText
                anchors.verticalCenter: parent.verticalCenter
                width: 100
                text: "1100000"
                selectByMouse: true
                validator: IntValidator{}
            }
        }

        Button {
            anchors.horizontalCenter: parent.horizontalCenter
            text: "Query in extent"
            onClicked: query(fieldText.text + populationText.text);
        }
    }
}

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