Query (Map Service/Layer)

Description

NoteNote:

Prior to 10.0, the query operation could only be performed on layers. From 10.0 onward, the query operation can be performed on tables and layers. Querying annotation is supported at the layer level, however querying annotation at the sublayer level is not supported.

Note that all parameters related to geometry will be ignored when querying tables.

The result of this operation is a feature set. This feature set contains feature objects including the values for the fields requested by the user. For layers, if you request geometry information, the geometry of each feature is also returned in the feature set. For tables, the feature set does not include geometries.

New in 10.9

10.8.1

The layer query operation supports percentile as a statisticType when using outStatistics for map services published from ArcGIS Pro that reference enterprise geodatabase data. Layers that support percentiles include the supportsPercentileStatistics property as true, found in the advancedQueryCapabilities layer object.

New in 10.7.1

New in 10.7

New in 10.6.1

New in 10.5

New at 10.4

New at 10.3.1

NoteNote:

When not using the resultOffset and resultRecordCount parameters, the exceededTransferLimit property may also be included in the query results. In this case, the property will be true only if the number of records exceeds the maximum number configured by the server administrator.

NoteNote:

In some cases when using the resultOffset and resultRecordCount parameters, the exceededTransferLimit property may be included in the query results even though the value specified in the resultRecordCount has not been exceeded. This is due to internal spatial index filtering of the query results. For this reason you should always rely on the exceededTransferLimit property to determine if you should page through results rather than relying on the number of results returned from each page. In some extreme cases zero results can be returned but the exceededTransferLimit property will be returned. In these cases you should continue paging though your results until exceededTransferLimit is no longer returned.

New at 10.3

New at 10.2

New at 10.1 SP1

New at 10.1

New at 10.0 SP1

New at 10.0

You can provide arguments to the query operation as query parameters defined in the parameters table below.

Request parameters

Parameter

Details

text

A literal search text. If the layer has a display field associated with it, the server searches for this text in this field. This parameter is shorthand for a WHERE clause of where <displayField> like '%<text>%'. The text is case sensitive. This parameter is ignored if the WHERE parameter is specified.

Example

text=Los
geometry

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, for envelopes and points, you can specify the geometry with a simpler comma-separated syntax.

Syntax

//Syntax for Envelope geometryType
geometry={xmin: -104, ymin: 35.6, xmax: -94.32, ymax: 41}

//Syntax for Envelope geometryType
geometry=-104,35.6,-94.32,41

//Syntax for Point geometryType
geometry=-104,35.6
geometryType

The type of geometry specified by the geometry parameter. The geometry type can be an envelope, point, line, or polygon. The default geometry type is an envelope.

Values: esriGeometryPoint | esriGeometryMultipoint | esriGeometryPolyline | esriGeometryPolygon | esriGeometryEnvelope

inSR

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 inSR is not specified, the geometry is assumed to be in the spatial reference of the map.

spatialRel

The spatial relationship to be applied on 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 (esriSpatialRelIntersects).

Values: esriSpatialRelIntersects | esriSpatialRelContains | esriSpatialRelCrosses | esriSpatialRelEnvelopeIntersects | esriSpatialRelIndexIntersects | esriSpatialRelOverlaps | esriSpatialRelTouches | esriSpatialRelWithin | esriSpatialRelRelation

relationParam

The spatial relate function that can be applied while performing the query operation. An example for this spatial relate function is "FFFTTT***." For more information on this spatial relate function, refer to the documentation for the spatial relate function.

where

A WHERE clause for the query filter. Any legal SQL WHERE clause operating on the fields in the layer is allowed.

Example

where=POP2000 > 350000

//When standardized queries are enabled
where = CHAR_LENGTH(cntry_name) > 18
objectIds

The object IDs of this layer or table to be queried.

NoteNote:

There might be a drop in performance if the layer/table data source resides in an enterprise geodatabase and more than 1,000 objectIds are specified.

Syntax

objectIds=<objectId1>, <objectId2>
objectIds=37, 462
time

The time instant or the time extent to query. A null value specified for start time or end time will represent infinity for start or end time, respectively.

Syntax

//Time instant
time=<timeInstant>

//Time extent
time=<startTime>, <endTime>

Syntax

//Time instant for 1 Jan 2008 00:00:00 GMT
time=1199145600000

//Time extent for 1 Jan 2008 00:00:00 GMT to 1 Jan 2009 00:00:00 GMT
time=1199145600000, 1230768000000
distance

This parameter only applies if supportsQueryWithDistance is true.

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, units is set to esriSRUnit_Meter, and all points within 100 meters of the point are returned.

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.

Syntax

distance=<distance>

Example

distance=100
units

This parameter only applies if supportsQueryWithDistance is true. The unit for calculating the buffer distance.

Values: esriSRUnit_Meter | esriSRUnit_StatuteMile | esriSRUnit_Foot | esriSRUnit_Kilometer | esriSRUnit_NauticalMile | esriSRUnit_USNauticalMile

outFields

The list of fields to be included in the returned result set. This list is a comma-delimited list of field names. If you specify the shape field in the list of return fields, it is ignored. To request geometry, set returnGeometry to true. You can also specify the wildcard "*" as the value of this parameter. In this case, the query results include all the field values.

Example

outFields=AREANAME,ST,POP2000

//Wildcard usage
outFields=*
returnGeometry

If true, the result set includes the geometry associated with each result. The default is true.

NoteNote:

This parameter cannot be used with returnDistinctValues.

Values: true | false

maxAllowableOffset

This option was added at 10.0. This option can be used to specify the maxAllowableOffset to be used for generalizing geometries returned by the query operation. The maxAllowableOffset is in the units of the outSR. If outSR is not specified, maxAllowableOffset is assumed to be in the unit of the spatial reference of the map.

Example

maxAllowableOffset=2
geometryPrecision

This option was added at 10.1. This option can be used to specify 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

geometryPrecision=3
outSR

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 outSR is not specified, the geometry is returned in the spatial reference of the map.

When using outSR with pbf, the pbf format will use coordinate quantization for layer queries. When an output spatial reference is not provided for a query operation, the Map Service derives coordinate quantization parameters from the layer's spatial reference. If the precision in the layer's spatial references is inadequate for the client application's use, it should pass in a spatial reference with suitable precision as the output spatial reference. If the layer's source spatial reference has the desired precision and it is suitable for the client's use, the client can use the source layer's spatial reference as the output spatial reference.

returnIdsOnly

If true, the response only includes an array of object IDs. Otherwise the response is a feature set. The default is false. Note that while there is a limit on the number of features included in the feature set response, there is no limit on the number of object IDs returned in the ID array response. Clients can exploit this to get all the query conforming object IDs by specifying returnIdsOnly is true and subsequently requesting feature sets for subsets of object IDs.

Values: true | false

returnCountOnly

This option was added at 10.0 SP1. If true, the response only includes the count (number of features/records) that would be returned by a query. Otherwise the response is a feature set. The default is false. This option supersedes the returnIdsOnly parameter.

Values: true | false

returnExtentOnly

This option was added at 10.4. If true, the response only includes the extent of the features that would be returned by the query. If returnCountOnly is true, the response will return both the count and the extent. The default is false. This parameter applies only if the supportsReturningQueryExtent property of the layer is true.

Values: true | false

orderByFields

This option was added at 10.1. This parameter specifies one or more field names or expressions that the features or records need to be ordered by. Use ASC or DESC for ascending or descending order, respectively. This parameter is supported on only those layers and tables that have the supportsAdvancedQueries property set to true. When used with outStatistics, only field names specified in outStatisticFieldName or groupByFieldsForStatistics are allowed. orderByFields defaults to ASC (ascending order) if <ORDER> is unspecified.

NoteNote:

At 10.4, expressions are allowed in addition to field name. When StandardizedQueries is enabled, only expressions that conform to the specifications are allowed. When StandardizedQueries is disabled, you can pass in any expression that the underlying database allows.

Syntax

orderByFields=expression1 <ORDER>, expression2 <ORDER>, expression3
<ORDER>

Example

orderByFields=STATE_NAME ASC, RACE DESC, GENDER

orderByFields=POPULATION / SHAPE_AREA
outStatistics

This option was added at 10.1. This parameter provides definitions for one or more field-based statistics to be calculated. This parameter is only supported on layers and tables that have the supportsStatistics property set to true. When using outStatistics, the following parameters are supported:

  • groupByFieldsForStatisticstext
  • orderByFields
  • text
  • time
  • where
  • geometry (Support added at 10.1 SP1)
  • gdbVersion (Support added at 10.2)
  • percentile (Support added at 10.8.1)
  • statisticType (Support added at 10.8.1)
    NoteNote:

    For more information on percentile statistic types, see the Percentile statistic type section below.

NoteNote:

If outStatisticFieldName is empty or missing, the map server will assign a field name to the returned statistic field. A valid field name can only contain alphanumeric characters and an underscore.

Values: An array of statistic definitions. A statistic definition specifies the type of statistic, the field on which it is to be calculated, and the resulting output field name.

Syntax

[
  {
    "statisticType": "<count | sum | min | max | avg | stddev | var | percentile_cont | percentile_desc>",
    "onStatisticField": "Field1",
    "statisticParameters": {   //only needed for percentile statistic type
      "value": value
    }, 
    "outStatisticFieldName": "Out_Field_Name1"
  },
  {
    "statisticType": "<count | sum | min | max | avg | stddev | var | percentile_cont | percentile_desc>",
    "onStatisticField": "Field2",
    "statisticParameters": {   //only needed for percentile statistic type
      "value": value
    }, 
    "outStatisticFieldName": "Out_Field_Name2"
  }  
]

Example

[
  {
    "statisticType": "sum",
    "onStatisticField": "GENDER",
    "outStatisticFieldName": "PopulationByGender"
  },
  {
    "statisticType": "avg",
    "onStatisticField": "INCOME",
    "outStatisticFieldName": "AverageIncome"
  }
]
groupByFieldsForStatistics

Added at 10.1. This parameter specifies one or more field names using the values that need to be grouped for calculating the statistics. At 10.4, expressions are allowed in addition to field name. When StandardizedQueries is enabled, only expressions that conform to the specifications are allowed. When StandardizedQueries is disabled, you can pass in any expression that the underlying database allows.

NoteNote:

This parameter is only valid when the outStatistics parameter is used.

Syntax

groupByFieldsForStatistics=expression1, expression2

Example

groupByFieldsForStatistics=STATE_NAME, GENDER

//Group by month when StandardizedQueries is enabled
groupByFieldsForStatistics=extract(month from incident_date)
returnZ

Added at 10.1. If true, the z-values will be included in the results if the features have z-values. Otherwise z-values are not returned. The default is false.

NoteNote:

This parameter only applies if returnGeometry is true.

returnM

Added at 10.1. If true, m-values will be included in the results if the features have m-values. Otherwise, m-values are not returned. The default is false.

NoteNote:

This parameter only applies if returnGeometry is true.

gdbVersion

Added at 10.1. GeoDatabase version to query. This parameter applies only if the hasVersionedData property of the service and the isDataVersioned property of the layers queried are true. If this is not specified, the query will apply to the published map's version.

Syntax

gdbVersion=<geodatabase version>

Example

gdbVersion=sde.USER1
returnDistinctValues

Added at 10.1 SP1. If true, returns distinct values based on the fields specified in outFields. This parameter applies only if the supportsAdvancedQueries property of the layer is true.

NoteNote:

This parameter cannot be used when returnGeometry is true.

Syntax

returnDistinctValues=<true | false>

Example

returnDistinctValues=true
returnTrueCurves

Added at 10.3. If true, returns true curves in output geometries; otherwise, curves are converted to densified polylines or polygons.

Values: true | false

resultOffset

Added at 10.3. This option can be used for fetching query results by skipping the specified number of records and starts from the next record (for example, resultOffset + 1th). The Default is 0. This parameter only applies if supportsPagination is true. You can use this option to fetch records that are beyond maxRecordCount. For example, if maxRecordCount is 1,000, you can get the next 100 records by setting resultOffset=1000 and resultRecordCount = 100; query results can return the results in the range of 1,001 to 1,100.

resultRecordCountsqlFormat

Added at 10.3. This option can be used for fetching query results up to the resultRecordCount specified. When resultOffset is specified but this parameter is not, the map service defaults it to maxRecordCount. The maximum value for this parameter is the value of the layer's maxRecordCount property. This parameter only applies if supportsPagination is true.

Example

//fetches up to 10 records
resultRecordCount=10
sqlFormat

The sqlFormat parameter can be either standard SQL-92 standard or it can use the native SQL of the underlying data store native. The default is none, which means the sqlFormat depends on the useStandardizedQuery parameter. The native format is supported when useStandardizedQuery is false. For more information on formatting, see the SQL format section below.

NoteNote:

You must check for the supportsSqlFormat layer property before using this parameter.

Values: none | standard | native

datumTransformation

This option was added at 10.5. Use this parameter to apply a datum transformation while projecting geometries in the results when outSR is different than the layer's spatial reference.

NoteNote:
While specifying transformation, consider which datum transformation is the most applicable to project the layer (not the map service) to the outSR. The sourceSpatialReference property in the layer resource reports which spatial reference features are stored in the source dataset.

For a list of valid datum transformation ID values and well-known text strings, see Using spatial references. For more information on datum transformations, see the transformation parameter in the Project operation.

Syntax

//Syntax to apply a transformation
datumTransformation=wkid1

//Syntax to apply a composite transformation
datumTransformation={<dt1>}

Examples

//Apply a transformation
datumTransformation=1623

//Apply a composite transformation
datumTransformation={"geoTransforms":[{"wkid":108889,"transformForward":true},{"wkid":1622,"transformForward":false}]}
rangeValues

This option was added at 10.5. It allows you to filter features from the layer that are within the specified range instant or extent.

NoteNote:
Check rangeInfos at the layer resources for the available ranges.

Syntax

[
  {
    "name": "<rangeName1>",  //range id
    "value": <value> | [ <value1>, <value2> ]  //single value or a value-range
        // null is allowed in value-range case -- that means infinity
       // e.g. [null, 1500] means all features with values <= 1500
      // [1000, null] means all features with values >= 1000
    },
    {
      "name": "<rangeName2>",
      "value": <value> |  [ <value3>, <value4> ]
    }
  }
]

Example

[
  {
    "name": "salinity",
    "value": 5  //a range instant (or single) value passed
  },
  {
    "name": "elevation",
    "value": [1000, 1500] //a range extent is passed
  }
]
quantizationParameters

This option was added at 10.6.1. This is used to project the geometry onto a virtual grid, likely representing pixels on the screen. For JSON property descriptions and examples, see the Quantization parameters JSON properties section below.

NoteNote:
This parameter only applies if supportsCoordinatesQuantization is true.
parameterValues

This option was added at 10.5. It allows you to filter the features layers by specifying values to an array of preauthored parameterized filters for those layers. When a value is not specified for any parameter in a request, the default value, which is assigned during authoring time, is used instead.

When a parameterInfo allows multiple values, you must pass them in an array.

NoteNote:

Check parameterInfos at the layer resources for the available parameterized filters, their default values, and expected data type.

Syntax

{
  "<parameterName1>": <value>, //when the multipleValues=false in the parameterInfo
  "<parameterName2>": [<value1> | <value2>]  //when the multipleValues=true in the parameterInfo
}

Example

{
  "floor": 10,
  "incidentDate": 1475877014000 //date time value needs to be passed in as epoch value
}
historicMoment

This option was added at 10.6.1. This specifies the historic moment to query. This parameter applies only if the layer is archiving enabled and the supportsQueryWithHistoricMoment property is set to true. This property is provided in the layer resource.

If historicMoment is not specified, the query will apply to the current features.

Syntax

historicMoment=<Epoch time in milliseconds>

Example

historicMoment=1199145600000
lodType

(Binning LOD Type )

Added at 10.9. This specifies the lodType. Check layer resources to find the lodType supported by a layer.

Values: esriGeometryPoint | esriGeometryMultipoint | esriGeometryPolyline | esriGeometryPolygon | esriGeometryEnvelope

lod

(Binning LOD Level)

Added at 10.9. This specifies the lod level. Check layer resources for available levels.

lodSR

(Binning LOD Spatial Reference)

Added at 10.9. This specifies the lod level. Check layer resources for available LOD spatial reference.

f

The response format. The default response format is html. Protocol buffer (pbf) format is only supported when the supportedQueryFormat property on the layer includes pbf.

NoteNote:
kmz will always return z-values.

Values: html | json | geojson | kmz | pbf (default, when returnIdsOnly=false and returnCountOnly=false)

Values: html | json (when outStatistics is specified)

Values: html | json | geojson | pbf (when either returnIdsOnly=true or returnCountOnly=true is specified)

NoteNote:

The output format f=geojson is not supported if returnM is true.

Quantization parameters JSON properties

The following table outlines the JSON properties for the quantizationParameters parameter:

Property

Details

extent

An extent defining the quantization grid bounds. Its SpatialReference matches the input geometry spatial reference if one is specified for the query. Otherwise, the extent will be in the layer's spatial reference.

mode

Geometry coordinates are optimized for viewing and displaying of data.

Value: view

originPosition

Integer coordinates will be returned relative to the origin position defined by this property value.

NoteNote:
Default is upperLeft origin position.

Values: upperLeft | lowerLeft

tolerance

The tolerance is the size of one pixel in the outSpatialReference units. This number is used to convert the coordinates to integers by building a grid with resolution matching the tolerance. Each coordinate is then snapped to one pixel on the grid. Consecutive coordinates snapped to the same pixel are removed to reduce the overall response size.

The units of tolerance are defined by outSpatialReference. If the outSpatialReference is not specified, tolerance is assumed to be in the unit of the spatial reference of the layer.

If the tolerance is not specified, the maxAllowableOffset is used.

NoteNote:
If the tolerance and maxAllowableOffset are not specified, a default 10,000 by 10,000 grid is used.

Example one

The following example demonstrates possible values for the quantizationParameters parameter:

quantizationParameters={"mode":"view","originPosition":"upperLeft","tolerance":1.0583354500042335,"extent":{"type":"extent","xmin":-18341377.47954369,"ymin":2979920.6113554947,"xmax":-7546517.393554582,"ymax":11203512.89298139,"spatialReference":{"wkid":102100,"latestWkid":3857}}}

The following is a sample URL that reflects the JSON object above:

https://machine.domain.com/arcgis/rest/services/USAShapeFoldersDec5/FeatureServer/2/query?f=html&where=1=1&returnGeometry=true&spatialRel=esriSpatialRelIntersects&outFields=*&outSR=102100&resultOffset=0&resultRecordCount=2000&quantizationParameters={"mode":"view","originPosition":"upperLeft","tolerance":1.0583354500042335,"extent":{"type":"extent","xmin":-19838806.04126036,"ymin":2146082.189218864,"xmax":-7455049.448307296,"ymax":11542768.51809405,"spatialReference":{"wkid":102100,"latestWkid":3857}}}

Example two

The following example demonstrates possible values for the quantizationParameters parameter:

{"mode":"view","originPosition":"lowerLeft","tolerance":1.0583354500042335,"extent":{"type":"extent","xmin":-18341377.47954369,"ymin":2979920.6113554947,"xmax":-7546517.393554582,"ymax":11203512.89298139,"spatialReference":{"wkid":102100,"latestWkid":3857}}}

The following is a sample URL that reflects the JSON object above:

https://machine.domain.com/arcgis/rest/services/USAShapeFoldersDec5/FeatureServer/1/query?where=1=1&objectIds=&time=&geometry=&geometryType=esriGeometryEnvelope&inSR=&spatialRel=esriSpatialRelIntersects&distance=&units=esriSRUnit_Meter&outFields=*&returnGeometry=true&maxAllowableOffset=1.0583354500042335&geometryPrecision=&outSR=102100&returnIdsOnly=false&returnCountOnly=false&returnExtentOnly=false&orderByFields=&groupByFieldsForStatistics=&outStatistics=&resultOffset=0&resultRecordCount=2000&returnZ=false&returnM=false&quantizationParameters={"mode":"view","originPosition":"lowerLeft","tolerance":1.0583354500042335,"extent":{"type":"extent","xmin":-18341377.47954369,"ymin":2979920.6113554947,"xmax":-7546517.393554582,"ymax":11203512.89298139,"spatialReference":{"wkid":102100,"latestWkid":3857}}}&f=html&token=

Percentile statistic type

The percentile statisticType is supported if the supportsPercentileStatistics layer property (in advancedQueryCapabilities) is true. The percentile indicates the value below or above which a given percentage of values in a group of data values falls. For example, the ninetieth percentile (value 0.9) is the value below which 90 percent of the data values may be found. For percentile statistics, there are two statisticTypes, PERCENTILE_DISC (discrete) and PERCENTILE_CONT (continuous). Discrete returns a data value from within that dataset, while continuous is an interpolated value.

The orderBy statistic parameter can also be used to calculate the percentile. For example, in a set of 10 values from 1 to 10, the percentile value for 0.9 with orderBy set as ascending (ASC) is 9, while the percentile for value 0.9 with orderBy set as descending (DESC) is 2. The default is ASC.

Syntax

[
  {
    "statisticType": "<PERCENTILE_CONT | PERCENTILE_DISC>",
    "statisticParameters": {
      "value": percentile_value,
      "orderBy": "<ASC | DESC>"
    },
    "onStatisticField": "Field1", 
    "outStatisticFieldName": "Out_Field_Name1"
  },
  {
    "statisticType": "<PERCENTILE_CONT | PERCENTILE_DISC>",
    "statisticParameters": {
      "value": percentile_value,
      "orderBy": "<ASC | DESC>"
    },
    "onStatisticField": "Field2", 
    "outStatisticFieldName": "Out_Field_Name2"
  }
]

Example

[
  {
    "statisticType": "PERCENTILE_CONT",
    "statisticParameters": {
      "value": 0.9
    },
    "onStatisticField": "NEAR_DIST",
    "outStatisticFieldName": "pop90_cont"
  },
  {
    "statisticType": "PERCENTILE_DISC",
    "statisticParameters": {
      "value": 0.9,
      "orderBy": "DESC"
    },
    "onStatisticField": "population",
    "outStatisticFieldName": "pop90_desc"
  }
]

Example usage

The following examples demonstrate various ways to create a sample query request URL for different use cases:

Example one

The following example demonstrates a query using the text parameter on the states layer of ESRI_StateCityHighway_USA:

https://sampleserver1.arcgisonline.com/ArcGIS/rest/services/Specialty/ESRI_StateCityHighway_USA/MapServer/1/query?text=Texas&f=pjson

Example two

The following example demonstrates a query using a WHERE statement on the same layer. The output is JSON format.

https://sampleserver1.arcgisonline.com/ArcGIS/rest/services/Specialty/ESRI_StateCityHighway_USA/MapServer/1/query?where=STATE_NAME='Florida'&f=json

Example three

The following example demonstrates a query with strings that are case sensitive. In this example, UPPER is used to make the query case insensitive.

https://sampleserver1.arcgisonline.com/ArcGIS/rest/services/Specialty/ESRI_StateCityHighway_USA/MapServer/1/query?where=UPPER(STATE_NAME)=UPPER('colorado')&f=pjson

Example four

The following example demonstrates querying the same states layer using geometry (envelope):

https://sampleserver1.arcgisonline.com/ArcGIS/rest/services/Specialty/ESRI_StateCityHighway_USA/MapServer/1/query?geometry=-125.4,35.2,-118.7,43.8&geometryType=esriGeometryEnvelope&f=pjson

Example five

The following example demonstrates querying the states layer by both geometry (envelope) and a WHERE statement:

https://sampleserver1.arcgisonline.com/ArcGIS/rest/services/Specialty/ESRI_StateCityHighway_USA/MapServer/1/query?geometry=-125.4,35.2,-118.7,43.8&geometryType=esriGeometryEnvelope&where=POP1999>5000000&f=pjson

Example six

The following example demonstrates querying the states layer by a WHERE statement, specifying a list of fields to return, and requesting no geometry in the results:

https://sampleserver1.arcgisonline.com/ArcGIS/rest/services/Specialty/ESRI_StateCityHighway_USA/MapServer/1/query?where=POP1999>15000000&returnGeometry=false&outFields=STATE_NAME,MALES,FEMALES,POP1999&f=pjson

Example seven

The following example demonstrates querying the states layer by text parameter and requesting the geometry with the well-known ID of 102113 (Web Mercator):

https://sampleserver1.arcgisonline.com/ArcGIS/rest/services/Specialty/ESRI_StateCityHighway_USA/MapServer/1/query?text=New+York&outSR=102113&f=pjson

Example eight

The following example demonstrates querying a table using a WHERE clause and return object IDs only:

https://sampleserver3.arcgisonline.com/ArcGIS/rest/services/SanFrancisco/311Incidents/MapServer/1/query?objectIds=&where=agree_with_incident+%3D+1&returnGeometry=true&returnIdsOnly=true&f=html

Example nine

The following example demonstrates using groupByFieldsForStatistics and outStatistics:

https://sampleserver6.arcgisonline.com/arcgis/rest/services/Census/MapServer/3/query?where=&text=&objectIds=&time=&geometry=&geometryType=esriGeometryEnvelope&inSR=&spatialRel=esriSpatialRelIntersects&relationParam=&outFields=&returnGeometry=true&maxAllowableOffset=&outSR=&returnIdsOnly=false&returnCountOnly=false&orderByFields=&groupByFieldsForStatistics=sub_region&outStatistics=[{"statisticType":"sum","onStatisticField":"pop2007","outStatisticFieldName":"Population_2007"},{"statisticType":"avg","onStatisticField":"AVE_FAM_SZ","outStatisticFieldName":"Average_Family_Size"}]&returnZ=false&returnM=false&gdbVersion=&f=pjson

Example ten

The following example demonstrates paging through a query result using resultOffset and resultRecordCount, and requesting to skip the first 5 records and return the next 10 counties in California in order by population:

https://machine.domain.com/arcgis/rest/services/USA/MapServer/3/query?where=STATE_NAME='California'&outFields=Name,Population&returnGeometry=false&resultOffset=5&resultRecordCount=10&orderByFields=Population&f=pjson

JSON Response syntax

The examples below demonstrate various JSON response syntax that can be returned for the query operation.

Example one

The following example syntax is returned when returnIdsOnly and returnCountOnly are false:

{
  "displayFieldName": "<displayFieldName>",
  "fieldAliases": {  //fieldAliases deprecated at 10
    "<fieldName1>": "<fieldAlias1>",
    "<fieldName2>": "<fieldAlias2>"
  },
  "fields": [
    {
      "name": "<fieldName1>",
      "type": "<fieldType1>",
      "alias": "<fieldAlias1>",
      "length": "<length1>"
    },
    {
      "name": "<fieldName2>",
      "type": "<fieldType2>",
      "alias": "<fieldAlias2>",
      "length": "<length2>"
    }
  ],
  "geometryType": "<geometryType>", //for layers only
  "spatialReference": <spatialReference>, //for layers only
  "hasZ": <true|false>, //added in 10.1
  "hasM": <true|false>, //added in 10.1
  "features": [ //features may include geometry for layers only
    <feature1>,
    <feature2>
  ]
}

Example two

The following example syntax is returned when returnIdsOnly is false:

{
  "objectIdFieldName": "<objectIdFieldName>",
  "objectIds": [
    <objectId1>,
    <objectId2>
  ]
}

Example three

The following example syntax is returned when returnCountOnly is true:

{
  "count": <count>
}

Example four

The following example syntax is returned when groupByFieldsForStatistics and outStatistics are specified:

{
  "displayFieldName": "",
  "fieldAliases": {
    "alias1": "fieldAlias1",
    "alias2": "fieldAlias2"
  },
  "fields": [
    {
      "name": "fieldName1",
      "type": "fieldType1",
      "alias": "fieldAlias1", 
      "length": fieldLength1
    },
    {
      "name": "fieldName2",
      "type": "fieldType2",
      "alias": "fieldAlias2", 
      "length": fieldLength2
    }
  ],
  "features": [<feature1>, <feature2>] //Feature object without geometry
}

JSON Response examples

The examples below demonstrate various JSON responses that can be returned for the query operation.

Example one

The following example response is returned when returnIdsOnly and returnCountOnly are false:

{
  "displayFieldName": "AREANAME",
  "fieldAliases": {
    "ST": "ST",
    "POP2000": "Population - 2000",
    "AREANAME": "City Name"
  },
  "fields": [
    {
      "name": "ST",
      "alias": "ST",
      "type": "esriFieldTypeString",
      "length": 2
    },
    {
      "name": "POP2000",
      "alias": "Population - 2000",
      "type": "esriFieldTypeInteger"
    },
    {
      "name": "AREANAME",
      "alias": "City Name",
      "type": "esriFieldTypeString",
      "length": 255
    }
  ],
  "geometryType": "esriGeometryPoint",
  "spatialReference": {
    "wkid": 4326
  },
  "features": [
    {
      "attributes": {
        "ST": "CA",
        "POP2000": 3694820,
        "AREANAME": "Los Angeles"
      },
      "geometry": {
        "x": -118.37,
        "y": 34.086
      }
    },
    {
      "attributes": {
        "ST": "CA",
        "POP2000": 461522,
        "AREANAME": "Long Beach"
      },
      "geometry": {
        "x": -118.15,
        "y" : 33.80
      }
    }
  ]
}

Example two

The following example response is returned when returnIdsOnly is true:

{
  "objectIdFieldName": "objectid",
  "objectIds": [
    1,
    2,
    3,
    4,
    5,
    7
  ]
}

Example three

The following example response is returned when returnCountOnly is true:

{
  "count":48
}

Example four

The following example response is returned when groupByFieldsForStatistics and outStatistics are specified:

{
  "displayFieldName": "",
  "fieldAliases": {
    "sub_region": "SUB_REGION",
    "Population_2007": "Population_2007",
    "Average_Family_Size": "Average_Family_Size"
  },
  "fields": [
    {
      "name": "sub_region",
      "type": "esriFieldTypeString",
      "alias": "SUB_REGION",
      "length": 20
    },
    {
      "name": "Population_2007",
      "type": "esriFieldTypeDouble",
      "alias": "Population_2007"
    },
    {
      "name": "Average_Family_Size",
      "type": "esriFieldTypeDouble",
      "alias": "Average_Family_Size"
    }
  ],
  "features": [
    {
      "attributes": {
        "sub_region": "Pacific",
        "Population_2007": 49731702,
        "Average_Family_Size": 3.2439999999999998
      }
    },
    {
      "attributes": {
        "sub_region": "Mountain",
        "Population_2007": 21492235,
        "Average_Family_Size": 3.165
      }
    },
    {
      "attributes": {
        "sub_region": "New England",
        "Population_2007": 14515009,
        "Average_Family_Size": 3.0249999999999999
      }
    },
    {
      "attributes": {
        "sub_region": "West North Central",
        "Population_2007": 20384497,
        "Average_Family_Size": 3.044285714285714
      }
    },
    {
      "attributes": {
        "sub_region": "East North Central",
        "Population_2007": 47176974,
        "Average_Family_Size": 3.0940000000000003
      }
    },
    {
      "attributes": {
        "sub_region": "Middle Atlantic",
        "Population_2007": 41116339,
        "Average_Family_Size": 3.1566666666666663
      }
    },
    {
      "attributes": {
        "sub_region": "South Atlantic",
        "Population_2007": 58943344,
        "Average_Family_Size": 3.0333333333333332
      }
    },
    {
      "attributes": {
        "sub_region": "East South Central",
        "Population_2007": 18077309,
        "Average_Family_Size": 3.0275000000000003
      }
    },
    {
      "attributes": {
        "sub_region": "West South Central",
        "Population_2007": 34910821,
        "Average_Family_Size": 3.1124999999999998
      }
    }
  ]
}