- URL:
- https://<root>/<serviceName>/FeatureServer/<layerId>/queryTopFeatures
- Methods:
GET
- Required Capability:
- Query
- Version Introduced:
- 10.7
Description
The query
operation is performed on a feature service layer resource. This operation returns a feature set based on the top features by order within a group. For example, when querying counties in the United States, you want to return the top five counties by population in each state. To do this, you can use query
to group by state name, order by descending population, and return the first five rows from each group (state).
The top
parameter is used to set the group by, order by, and count criteria used in generating the result. The operation also has many of the same parameters (for example, where
and geometry
) as the layer query operation. However, unlike the layer query operation, query
does not support parameters such as out
and its related parameters or return
. Consult the advanced
layer property for more details.
If the feature service supports the query
operation, it will include supports
as true
in the advanced
layer property.
Request parameters
Parameter | Details |
---|---|
| A WHERE clause for the query filter. SQL-92 WHERE clause syntax on the fields in the layer is supported for most data sources. Some data sources have restrictions. For more information, see Query (Feature Service/Layer). |
| The object IDs of the layer or table to be queried. Syntax
Example
|
| The time instant or the time extent to query. Syntax
Example
A null value specified for start time or end time will represent infinity for start or end time, respectively. Example
|
| The JSON parameters that define the aggregation of the data. Syntax
Example
|
| The geometry to apply as the spatial filter. The structure of the geometry is the same as the structure of the JSON geometry objects returned by the ArcGIS REST API. In addition to the JSON structures, you can specify the geometry of envelopes and points with a simple comma-separated syntax. Syntax
Examples
|
| The type of geometry specified by the geometry parameter. The geometry type can be an envelope, a point, a line, or a polygon. The default geometry type is an envelope. Values: |
| The spatial reference of the input geometry. The spatial reference can be specified as either a well-known ID or as a spatial reference JSON object. If the |
| The spatial relationship to be applied to the input geometry while performing the query. The supported spatial relationships include intersects, contains, envelope intersects, within, and so on. The default spatial relationship is intersects ( Values: |
| The buffer distance for the input geometries. The distance unit is specified by units. For example, if the distance is 100, the query geometry is a point, The geodesic buffer is created based on the datum of the output spatial reference if it exists. If there is no output spatial reference, the input geometry spatial reference is used. Otherwise, the native layer spatial reference is used to generate the geometry buffer used in the query. This parameter only applies if Syntax
Example
|
| The unit for calculating the buffer distance. If Values: |
| The list of fields to be included in the returned result set. This list is a comma-delimited list of field names. You can also specify the wildcard ( Example
|
| If Values: |
| The maximum allowable offset to be used for generalizing geometries returned by the query operation. The Example
|
| The number of decimal places in the response geometries returned by the query operation. This applies to x- and y-values only (not m- or z-values). Example
|
| The spatial reference of the returned geometry. The spatial reference can be specified as either a well-known ID or as a spatial reference JSON object. If |
| If When Values: |
| If Values: |
| If Values: |
| If |
| If |
(Optional) | The Values: |
| The response format. The default response format is Values: |
Considerations for result Type
The max
and max
are determined by the server. The feature service assigns the max
relevant to the value from the result
parameter. If result
is not included in the request, the default max
is always used. This can be the default server assigned value (1000, 2000) or an overwritten value provided by the service owner or admin. The values of the max record counts may vary based on the type of data (polygon, point, polyline, table).
The server advertises max
with the layer metadata. For example, the following max record count is returned for points data:
{"maxRecordCount": 2000, "tileMaxRecordCount": 8000, "standardMaxRecordCount": 32000}
If the result
is specified, but the result
is not specified with the result
, the server will determine the max
relevant to the result
query parameter. The client can supply the result
parameter in the request. This cannot be greater than the standard/tile max
value if result
is used.
The layer metadata also includes maxRecordCountFactor that can be configured from the admin API. The server max
for the tile
and standard
is used as a multiplier for the server base value. All max
values are adjusted with the max
.
Example usage
Example one: standard query
The following is a sample request URL that demonstrates how to query the last two deliveries made by an employee:
https://machine.domain.com/webadaptor/rest/services/Hosted/deliveries/FeatureServer/0/queryTopFeatures?where=&objectIds=&time=&topFilter={"groupByFields": "employeeName", "topCount": 2, "orderByFields": "deliveryNumber desc"}&geometry=&geometryType=esriGeometryEnvelope&inSR=&spatialRel=esriSpatialRelIntersects&distance=&units=esriSRUnit_Foot&outFields=employeeName,deliveryNumber&returnGeometry=true&maxAllowableOffset=&geometryPrecision=&outSR=&returnIdsOnly=false&returnCountOnly=false&returnExtentOnly=false&returnZ=false&returnM=false&resultType=&f=pjson
Example two: result Type
of none
, max Record Count
The following is a sample request URL used to demonstrate the none
result
value. Along with the none
value, the maxRecordCount is always used ("max
) or an overwritten value by the service owner or admin is used.
https://machine.domain.com/webadaptor/rest/services/USAStatesRiversCapitals/FeatureServer/2/query?where=1=1&objectIds=&time=&geometry=&geometryType=esriGeometryEnvelope&inSR=&spatialRel=esriSpatialRelIntersects&resultType=none&distance=&units=esriSRUnit_Meter&outFields=*&returnGeometry=true&multipatchOption=&maxAllowableOffset=&geometryPrecision=&outSR=&returnIdsOnly=false&returnCountOnly=false&returnExtentOnly=false&returnDistinctValues=false&orderByFields=&groupByFieldsForStatistics=&outStatistics=&resultOffset=&resultRecordCount=&returnZ=false&returnM=false&quantizationParameters=&sqlFormat=none&f=html&token=
Example three: result Type
of standard
, standard Max Record Count
The following is a sample request URL used to demonstrate the standard
result
value. Along with the standard
value, the standardMaxRecordCount is always used ("standard
) for point and table layers.
https://machine.domain.com/webadaptor/rest/services/USAStatesRiversCapitals/FeatureServer/2/query?where=1=1&objectIds=&time=&geometry=&geometryType=esriGeometryEnvelope&inSR=&spatialRel=esriSpatialRelIntersects&resultType=standard&distance=
&units=esriSRUnit_Meter&outFields=*&returnGeometry=true&multipatchOption=&maxAllowableOffset=&geometryPrecision=&outSR=&returnIdsOnly=false
&returnCountOnly=false&returnExtentOnly=false&returnDistinctValues=false&orderByFields=&groupByFieldsForStatistics=&outStatistics=
&resultOffset=&resultRecordCount=&returnZ=false&returnM=false&quantizationParameters=&sqlFormat=none&f=html&token=
Example four: result Type
of tile
, tile Max Record Count
The following is a sample request URL used to demonstrate the tile
result
value. Along with the tile
value, the tileMaxRecordCount is always used ("tile
) for point layers.
https://machine.domain.com/webadaptor/rest/services/USAStatesRiversCapitals/FeatureServer/2/query?where=1=1&objectIds=&time=&geometry=&geometryType=esriGeometryEnvelope&inSR=&spatialRel=esriSpatialRelIntersects&resultType=tile&distance=
&units=esriSRUnit_Meter&outFields=*&returnGeometry=true&multipatchOption=&maxAllowableOffset=&geometryPrecision=&outSR=&returnIdsOnly=false
&returnCountOnly=false&returnExtentOnly=false&returnDistinctValues=false&orderByFields=&groupByFieldsForStatistics=&outStatistics=
&resultOffset=&resultRecordCount=&returnZ=false&returnM=false&quantizationParameters=&sqlFormat=none&f=html&token=
JSON Response syntax
{
"exceededTransferLimit": <true | false>,
"features: [<feature1, feature2>],
"fields": [
{
"name": "<fieldName1>",
"type": "<fieldType1>",
"alias": "<fieldAlias1>",
"length": "<length1>"
},
{
"name": "<fieldName2>",
"alias": "<fieldAlias2>",
"type": "<fieldType2>",
"length": "<length2>"
}
],
"geometryType": "<geometryType>",
"spatialReference": {<spatialReference>},
"globalIdFieldName": "<fieldName>",
"objectIdFieldName": "<fieldName>",
"hasZ": <true | false>,
"hasM": <true | false>
}
JSON Response example
{
"exceededTransferLimit": false,
"features": [
{
"attributes": {
"employeeName": "Jason",
"deliveryNumber": 25
},
"geometry": {
"x": -76.9505202472378,
"y": 36.02168768903079
}
},
{
"attributes": {
"employeeName": "Jason",
"deliveryNumber": 24
},
"geometry": {
"x": -80.28022828451529,
"y": 34.9904342763449
}
},
],
"fields": [
{
"name": "employee",
"alias": "employee",
"type": "esriFieldTypeString",
"length": 100
},
{
"name": "deliveryNumber",
"alias": "deliveryNumber",
"type": "esriFieldTypeDouble",
"length": 1000
}
],
"geometryType": "esriGeometryPoint",
"spatialReference": {
"wkid": 4326,
"latestWkid": 4326
},
"globalIdFieldName": "globalid",
"objectIdFieldName": "objectid",
"hasZ": false,
"hasM": false
}