Skip to content

Query

A query provides the ability to return a subset of features from a dataset based on any combination of attribute, spatial, and temporal (time) criteria.

  • Attribute criteria are defined with a standard SQL expression based on the available attribute fields.

  • Spatial criteria use a geometry and a spatial relationship (within, contains, intersects, and so on).

  • A temporal filter can be defined using a single date or time, or a range.

For defining attribute criteria, you can use a compound SQL expression that uses several attribute fields, data types, and operators. For example the SQL expression "POP > 1000000 AND NAME LIKE 'San%'" will obtain a subset of features where the population is greater than 100,000 people and where the city name begins with the characters "San" (like San Diego, San Francisco, San Antonio, etc.). You can also perform queries to return related features, a feature count, an extent containing all features meeting your criteria, or statistical information about a dataset.

A query does not require that all types of criteria be defined (attribute, spatial, and temporal). Leaving spatial and temporal filters undefined, for example, means that the search will not be restricted using those criteria (in other words, the entire spatial and temporal extent will be evaluated).

How query works

Query criteria are defined using a query parameters object. This is where you specify the attribute, spatial, and/or temporal inputs. Most queries take query parameters as an input to define the query criteria as well as some preferences for the results. When the query is executed against a specific dataset (feature table), results are returned as a collection of features.

A query does not require that each type of criteria be defined. Query criteria are only evaluated if explicitly defined (missing temporal criteria, for example, means not to filter the results according to time).

Relevant classes and members in the API ref

Query parameters

Query parameters define the query criteria using:

  • An SQL expression for attribute criteria.
  • Geometry and a spatial relationship for spatial criteria.
  • A date/time or a range of dates/times for temporal criteria.

In querying for features, you can define a geometry and determine if a feature's geometry participates in a specific spatial relationship with the defined geometry. The query returns features that meet the spatial relationship.

  • Intersects: the geometry and a feature share at least one point.
  • Touches: the geometry touches a border of a feature.
  • Crosses: the geometry crosses a feature.
  • Within: the geometry is completely contained by a feature.
  • Contains: the geometry completely contains a feature.

The query parameters can be used in a standard query to return features, or in queries that return a feature count or extent. You can also use the query parameters to make a selection in the map showing the features that match the criteria.

Specialized query parameters are used for queries that return statistics or related features. In addition to query criteria, these query parameters define things like the type of statistics to return or the relationships to evaluate.

This example uses spatial criteria to find features inside a polygon. Instead of executing a query on the FeatureTable, however, the query parameters are simply passed to the FeatureLayer to display features that meet the criteria as a new selection.

Use dark colors for code blocksCopy
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
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
    // Creates a buffer from the point.
    val searchGeometry = GeometryEngine.bufferOrNull(
        geometry = point,
        distance = 30000.0
    )
    // Creates a query parameters.
    val parameters = QueryParameters().apply {
        geometry = searchGeometry
        spatialRelationship = SpatialRelationship.Contains
    }

    // Selects features based on spatial query.
    damageFeatureLayer.selectFeatures(
        parameters = parameters,
        mode = SelectionMode.New
    ).getOrElse { error ->
        return showError(error.message.toString())
    }

Query results

Query results typically provide a collection of features. You can iterate the result features to display them on the map, read their attributes, and so on. A query for statistics returns a collection of records that describe the requested statistics for features in the dataset. Queries for feature count or extent return a number and an envelope, respectively.

Geometry for the query results can be returned in a specified spatial reference by specifying the output spatial reference in the query parameters. If a spatial reference is not specified, results will be returned in the spatial reference of the dataset. Most often, you will need the result features in the same spatial reference as your app's map.

You can also set a maximum number of features to return in the result. This is useful in situations where you might only need a subset of features that meet your criteria. It may also improve performance by limiting the amount of information returned with the result.

Identify

Identify is like a shortcut for a spatial query. It allows you to quickly answer the question: what is here? It gives users a quick way to explore and learn about the map or scene content by tapping or clicking. Information returned from an identify operation can be shown in pop-ups or other UI components in your app. Unlike a query, you can't provide attribute or time criteria to filter results. Identify returns geoelements or graphics at the specified location.

Use dark colors for code blocksCopy
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
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
        val identifyLayerResult = mapViewProxy.identify(
            layer = damageFeatureLayer,
            screenCoordinate = singleTapConfirmedEvent.screenCoordinate,
            tolerance = 12.dp,
            returnPopupsOnly = false,
            maximumResults = 10
        ).getOrElse { error ->
            return showError(error.message.toString())
        }
        val features: List<Feature> = identifyLayerResult.geoElements.filterIsInstance<Feature>()
        val layerContent = identifyLayerResult.layerContent
        if (layerContent is FeatureLayer) {
            layerContent.selectFeatures(features)
        }

Identify geoelements and graphics

You can identify geoelements from layers or graphics from graphics overlays. An identify on layers returns non-graphic geoelements, and an identify on graphics overlays returns graphics.

Relevant classes and members in the API ref

The following API is used to identify geoelements in layers and graphics in graphics overlays. The identify methods are defined in GeoViewProxy in the ArcGIS Maps SDK for Kotlin Toolkit.

  • identify(): Methods that identify geoelements in a specific layer, or graphics in a specific graphics overlay. Passing maximumResult = 1 returns just the topmost geoelement or graphic.

  • identifyLayers(): Method that identifies geolements in all layers in the map or scene view. Passing maximumResult = 1 returns the topmost geoelement in each layer.

  • identifyGraphicsOverlays(): Method that identifies graphics in all graphics overlays in the map or scene view. Passing maximumResult = 1 returns the topmost graphic in each overlay.

  • IdentifyLayerResult: Contains the results of an identify for a layer. Methods that identify on all layers have an IdentifyLayerResult for each layer.

  • IdentifyGraphicsOverlayResult Contains the results of an identify for a graphics overlay. Methods that identify on all graphics overlays have an IdentifyGraphicsOverlayResult for each graphics overlay.

Identify parameters

The identify methods have very similar signatures. The following are parameters they can take.

  • screenCoordinate: the location on the screen tapped or clicked by the user.
  • tolerance: the radius (in pixels) of a circle centered at the screen point, within which to identify geoelements or graphics.
  • returnPopupsOnly: true to return pop-ups only. False to return geoelements or graphics as well as popups.
  • maximumResults: the maximum number of geoelements or graphics to return. If this parameter is set to 1, which is the default, the methods return the topmost item (geoelement or graphic) in the specified layer or graphics overlay; or the topmost item in each layer or graphics overlay. If you are identifying on a group layer or a map image layer, this parameter determines the non-zero number of results per sublayer. (See Identify on group layers and Identify on map image layers.)

Identify results

The results of calling one of the identify methods for a specific layer or for all layers are available in an IdentifyLayerResult or a collection of IdentifyLayerResult, respectively. You can get the geoelements from an identify layer result.

The results of calling one of the identify methods for a specify graphics overlay or for all graphics overlays are available in an IdentifyGraphicsOverlayResult or a collection of IdentifyGraphicsOverlayResult, respectively. You can get the graphics from the identify graphics overlay result.

Identify on other layer types

While any Layer can be identified, the following describe considerations for some of them.

Identify on group layers

If you want to perform an identify on a group layer GroupLayer, call the identify layer method and pass the group layer as the layer argument. Identify operates on all the child layers of the group layer. The method returns an IdentifyLayerResult for the group layer, but the result has no geoelements for the group layer. Instead, you should access results for child layers using the sublayerResults property in the IdentifyLayerResult. The sublayer results property is a collection of IdentifyLayerResult, one for each child layer.

If you want to perform an identify on all layers, some of which are group layers, call the identify layers method. The collection returned contains no identify layer result for a group layer, but has an identify layer result for each of its child layers. Effectively, this behavior treats the child layers as independent layers and otherwise ignores the group layers.

When calling identify methods that take a maximumResults parameter, this value determines the non-zero number of features returned per sublayer. See Identify parameters.

Identify on map image layers

You can use the identify layers method to identify against map image layers and tiled map layers. Iterate over the results collection, and use the layer content property of IdentifyLayerResult to test if the LayerContent is an ArcGISMapImageLayer or ArcGISMapImageSublayer.

The following points apply when identifying against map image layers:

  • Results are returned as features; unlike other features, however, they will not have a reference to a FeatureTable.
  • Map image layers may have one or more sublayers. Identify results from map image layers reflect this structure, and return results for each sublayer separately. (Note that if you have specified a maximum number of results to return, this value applies per sublayer.)

Identify on raster layers

Identify on raster layers returns the RasterCell value for a tapped location in a MapView or SceneView. The identified RasterLayer can be local on the device or from a web service layer hosted on ArcGIS Online or ArcGIS Enterprise. Identify returns raster cell values to display in a simple callout, or if a pop-up is configured for the raster layer, the information can be displayed in a formatted UI.

For mosaicked images, a mosaic rule defines how the individual rasters are combined. When identifying images mosaicked from a collection of images, the values returned from identify can vary according to the mosaic rule settings. You can use the default rule defined with the service or define rule settings to control how overlapping areas in the mosaic are handled. Rendering rules applied on the raster layer on the client, as well as information from attribute tables (if present), will also be represented in the identify results.

Identify features in a WMS layer

WMS layers differ from other layers, as they do not support returning individual attributes or geometry for a feature. WMS services perform identify on the server and return HTML documents describing identified features. Each feature will be a WmsFeature, which allows you access to the the returned HTML document string. Use the feature's attributes property to get the dictionary of attributes, and then find the attribute that has the key HTML. The value is an HTML string suitable for display in a web view.

It is impossible to get the geometry for an identified (or any other) WMS feature. An identified WMS feature's geometry will always be null. Consequently, WMS layers do not support feature selection/highlight.

Display filters

Display filters limit the number of features displayed to reduce clutter in a map or scene. Use FeatureLayer.displayFilterDefinition when you want to draw a subset of features while maintaining access to all of them. Unlike a definition expression, features hidden by a display filter are available for selection, identify, editing, and geoprocessing operations.

You can add display filters to maps and scenes authored with this API, or published in web maps using ArcGIS Pro 2.9 or higher.

Tutorials

Samples

Query feature table

Select features in feature layer

Query features with arcade expression

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