- URL:
- https://<layer-url>/query
- Methods:
GET
- Required Capability:
- Data
- Version Introduced:
- 9.3
Description
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 11.4
- Two new parameters are introduced to work with unique-ids i.e. non-integer based unique identifiers.
return
to return non-integer unique identifiers.Unique I d s Only unique
to pass in non-integer unique identifiers in a query operation.Ids
New in 11.2
-
esri
supports 64-bit integer values.Field Type Object I D -
When
esri
's precision is 1, query response includes milliseconds. When precision value is 0, last 3 digits of epoch values are always 0s.Field Type Date -
Support for four new field types are added. They are:
esri
,Field Type B i g Int esri
,Field Type Timestamp Offset esri
,Field Type Date Only esri
. Please see Date-time queries section below.Field Type Time Only -
Values returned for
esri
field types are string literals conforming to ISO 8601 standard i.e.Field Type Timestamp Offset YYYY-MM-DDThh:
. These values represent absolute time comprised of wall-clock time and an offset from UTC.m m: ss.sss+/-HH: M M - This field type allows storing date/time values from multiple time zones in a single field.
-
Values returned for
esri
field types are string literals conforming to ISO 8601 standard and contains only date parts without any time parts i.e.Field Type Date Only YYYY-MM-DD
-
Values returned for
esri
field types are string literals conforming to ISO 8601 standard and contains only time parts without any date parts i.e.Field Type Time Only h
. There is no milliseconds support in this field type.h: m m: ss
-
-
A special keyword
current_
is supported in theuser where clause
. This is helpful when you want to view records/features that belongs to or edited/inserted by the currently logged in user. This keyword is supported when "supportsCurrentUserQueries": true in the layers "advancedQueryCapabilities" property. Note that this enhancement requires the server to have standardizedQueries enabled
New in 10.9
-
The
Query
operation is enhanced to return spatially aggregated results in regularly shaped polygon (such as hexagon, square, and so on) tessellation from point features.- You need to check the value for
Supports
property in the layer resources before making requests withLOD lod
,lod
orType lod
optionally combined withS R out
and other query parameters.Statistics
- You need to check the value for
-
Percentile in an
out
query is supported for layers and tables in a file geodatabase.Statistics
10.8.1
The layer query operation supports percentile
as a statistic
when using out
for map services published from ArcGIS Pro that reference enterprise geodatabase data. Layers that support percentiles include the supports
property as true
, found in the advanced
layer object.
New in 10.7.1
- Map Services now support the protocol buffer (
pbf
) format. This format is supported on map services from ArcGIS Pro. Thesupported
layer property will listQuery Formats pbf
if it is available on the layer.
New in 10.7
- Support for
amf
output format was removed.
New in 10.6.1
-
Supports the following new parameters.
historic
to query from a given moment in an archive enabled layer.Moment
-
Supports returning 'number of unique values', instead of a list of unique value, off a field when values for both
return
andCount Only return
are true.Distinct Values -
Map services now support
quantization
.Parameters
New in 10.5
-
Supports the following new parameters.
datum
to provide a desired datum transformation to be applied while features get projected.Transformations range
to set values to ranges.Values parameter
to set value to parameterized filters.Values
-
Supports passing in SQL expressions in
out
. CheckStatistics supports
on resources to find out whether the layer/table allows SQL expressions.S q l Expression
New at 10.4
- Supports GeoJSON as a response format.
- Supports passing in expressions in
order
andBy Fields group
. WhenBy Fields F o r Statistics use
isStandardized Queries true
, you can pass in expressions that conform toStandardized
specifications. Otherwise, any expressions that are supported by the underlying database can be passed in.Queries
New at 10.3.1
- The
exceeded
property is now included in the JSON response when paging through a query result with theTransfer Limit result
andOffset result
parameters. WhenRecord Count exceeded
isTransfer Limit true
, it indicates there are more query results and you can continue to page through the results. Whenexceeded
isTransfer Limit false
, or this property is absent in a query result, it indicates that you have reached the end of the query results.
New at 10.3
- Supports pagination in a query layer. Use
result
andOffset result
parameters to page through a query result.Record Count - Note that when you pass in one of these two parameters and
order
is left empty, the map service uses the object-id field to sort the result. For a query layer with a pseudocolumn as the object-id field (for example, FID), you must provideBy Fields order
or else the query will fail.By Fields query
now supports true curves in an inputgeometry
parameter.query
now returns true curves in output geometries when thereturn
parameter is set to true.True Curves - Learn more about JSON Curve Objects in Geometry Objects.
New at 10.2
- The
where
parameter value must conform to the standardized queries, if the layer/table resource advertisesuse
is true. Learn more about standardized queries.Standardized Queries out
now supports theStatistics gdb
parameter.Version
New at 10.1 SP1
- Support for a new parameter named
return
that accepts a Boolean value was added. When true, the query result would contain distinct values based on the fields specified in theDistinct Values out
parameter.Fields out
now supports theStatistics geometry
parameter.
New at 10.1
- Support for
order
,By Fields out
, andStatistics group
was added for both layers and tables.By Fields F o r Statistics - Support for
return
andZ return
was added for layers. Default value forM return
andZ return
is false.M - When output format
f
is kmz, the result would always contain a z-value irrespective of thereturn
property value. If the feature geometry does not support z, a default value of 0 would be returned for z.Z - Support for the
gdb
parameter was added. Use this parameter to specify the geodatabase version to query.Version - The
geometry
parameter was introduced. This option can be used to specify the number of decimal places in the response geometries returned by the query operation.Precision - JSON response contains an optional property
exceeded
. This property will be true only if the number of records exceeds the maximum number configured by the server administrator.Transfer Limit
New at 10.0 SP1
- At 10.0 SP1, support for returning the count (number of features/records) that would be returned by a query was added for both layers and tables.
New at 10.0
-
Support for querying layers and tables based on time was added at 10.0. For time-aware layers, users can use the time parameter to specify the time instant or the time extent to query.
-
A new
return
parameter was introduced. If set toI d s Only false
(default), the response will be a feature set. Iftrue
, the response will be an array of object IDs. -
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
return
and subsequently requesting feature sets for subsets of object IDs.I d s Only=true -
Support for query based on
object
was added.Ids -
Support for
f=amf
was added. -
Support for
generalizing
geometries returned by the query operation was added. -
The
query
operation returns an additionalfields
array (JSON and AMF only) that contains array of field information for returned values. This array contains only fields specified in theout
parameter. See Layer/Table for details on fields.Fields -
The
field
member is deprecated.Aliases
You can provide arguments to the query operation as query parameters defined in the parameters table below.
Request parameters
Parameter | Details |
---|---|
| 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 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, for envelopes and points, you can specify the geometry with a simpler comma-separated syntax. Syntax
|
| 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: |
| The spatial reference of the input |
| The spatial relationship to be applied on the input Values: |
| 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. |
| A WHERE clause for the query filter. Any legal SQL WHERE clause operating on the fields in the layer is allowed. Example
|
| The object IDs of this layer or table to be queried. Syntax
|
| 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
Syntax
|
| This parameter only applies if The buffer distance for the input geometries. The distance unit is specified by 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
Example
|
| This parameter only applies if Values: |
| 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 Example
|
| If Values: |
| This option was added at 10.0. This option can be used to specify the Example
|
| 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 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 When using |
| If Values: |
| If Values: |
| If Values: |
| This parameter specifies one or more field names or expressions that the features or records need to be ordered by. Use Syntax
Example
|
| 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
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
Example
|
| This parameter specifies one or more field names using the values that need to be grouped for calculating the statistics. Expressions are allowed in addition to field name. When Syntax
Example
|
| If |
| If |
| GeoDatabase version to query. This parameter applies only if the Syntax
Example
|
| If Syntax
Example
|
| If Values: |
| This option can be used for fetching query results by skipping the specified number of records and starts from the next record (for example, |
| This option can be used for fetching query results up to the Example
|
| The Values: |
| Use this parameter to apply a datum transformation while projecting geometries in the results when For a list of valid datum transformation ID values (WKID) and well-known text (WKT) strings, see Using spatial references. For more information on datum transformations, see the Syntax
Examples
|
| It allows you to filter features from the layer that are within the specified range instant or extent. Syntax
Example
|
| 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. |
| 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 Syntax
Example
|
| This specifies the historic moment to query. This parameter applies only if the layer is archiving enabled and the If Syntax
Example
|
(Binning LOD Type ) | Added at 10.9. This specifies the Values: |
(Binning LOD Level) | Added at 10.9. This specifies the lod level. Check layer resources for available levels. |
(Binning LOD Spatial Reference) | Added at 10.9. This specifies the lod level. Check layer resources for available LOD spatial reference. |
| The unique identifiers of this layer or table to be queried. Syntax
|
| If Values: |
| The response format. The default response format is Values: Values: Values: |
Quantization parameters JSON properties
The following table outlines the JSON properties for the quantization
parameter:
Property | Details |
---|---|
| 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. |
| Geometry coordinates are optimized for viewing and displaying of data. Value: |
| Integer coordinates will be returned relative to the origin position defined by this property value. Values: |
| 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 If the tolerance is not specified, the maxAllowableOffset is used. |
Example one
The following example demonstrates possible values for the quantization
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 quantization
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=
Date-time queries
Time zone properties
In general, the date
property of the feature service layer identifies the time zone that all dates are stored in. The exception cases involve editor tracking date fields and time aware layer time zones.
When you are working with your data, you need to consider the time zone of the fields that you are working with. If you are querying a date type field and date
is set to a specific time zone, make sure your WHERE clause issues the time in that specific time zone. For example, if you want to return all the records that match 1:00 p.m. on February 9, 2015, Pacific standard time, your WHERE clause would be as follows:
Querying records in PST
where=pacific_time_date_field = TIMESTAMP '2015-02-09 13:00:00'
However, it is possible to have up to three different time zones defined on your service. If your query includes dates from the editor tracking fields or the time aware fields, you need to make sure you submit the query in their respective time zones. The time zones for these fields can be found in the properties mentioned above. If the date
is null the data is assumed to be in UTC, and if it is Unknown the time zone is assumed to be undefined. The example below demonstrates how to query three date fields that have three different times zones. When querying fields in different time zones, you need to make sure the time you use corresponds with the time zone of the date field. There is a date field in PST, one in EST, and the editor tracking field created_
in UTC:
Querying records in three different time zones
where=(DateTime_PST=TIMESTAMP '2012-01-01 15:20:00' AND (DateTime_EST=TIMESTAMP '2012-01-01 18:20:00' AND created_date=TIMESTAMP '2012-01-01 22:20:00')
Although you issue local time in your WHERE clause, the query operation always returns date values in UTC. You can set the date fields time zone, which shows up in the date
property of the feature service layer either during publishing or in the ArcGIS Server Manager after publishing. In the Server Manager, navigate to service you wish to edit and click on the Parameters tab to update the time zone information. If the date
property is not set, it will show up as null and the data will be assumed to be in UTC. In this case make sure you issue your WHERE clause in UTC.
As of ArcGIS Pro 3.1 and ArcGIS Enterprise 10.9, there is a new option when defining the time zone during publishing. If you don't want to define a time zone at all (not even UTC), you can set it to Unknown. Using the Unknown time zone makes it so that there is no translation done when the query operation submits and returns date values, they are stored and returned as is. This is particularly useful if you have data which spans multiple time zones.
Date, time and time zone offset format
When Standardized
is enabled, use following SQL functions and syntaxes while querying against a date-time field. When StandardizedQueries is turned off, you must consult to the underlying database's help references to find the correct syntax.
Note: At 11.2 release, both map and feature services added support for 3 new field types in addition to the existing esri
.
Field type | Description |
---|---|
| Values contains both date, time parts and time zone offset from UTC. The data and time represent local (or wall-clock) time. The time part supports milliseconds. SQL Syntax
Example
|
| Values contains both date and time parts. The data and time represent local (or wall-clock) time, and are assumed in SQL Syntax
Example
|
| Values contains only date part without associated to any particular time zone. SQL Syntax
Example
|
| Values contains only time part without associated to any particular time zone. SQL Syntax
Example
|
Interval queries
the INTERVAL
syntax can be used in place of the date-time queries and is standardized across all map and feature services. The INTERVAL syntax can be used to specify either the current date or timestamp in the query when StandardizedQueries is enabled:
//Date
<DateField> >= CURRENT_DATE -+ INTERVAL '<IntervalValue>' <TimeStampFormat>
//Timestamp
<DateField> >= CURRENT_TIMESTAMP -+ INTERVAL '<IntervalValue>' <TimeStampFormat>
For the syntax demonstrated above, you can interchange the CURRENT_
and CURRENT_
values. Both can be used with +
or -
of INTERVAL
values.
The examples below outline the different ways in which the INTERVAL syntax can be modified for the purposes of your query:
//'DD' Day
<DateField> >= CURRENT_TIMESTAMP -+ INTERVAL 'DD' DAY
//'HH' Hour
<DateField> >= CURRENT_TIMESTAMP -+ INTERVAL 'HH' HOUR
//'MI' Minute
<DateField> >= CURRENT_TIMESTAMP -+ INTERVAL 'MI' MINUTE
//'SS(.FFF)' Second
<DateField> >= CURRENT_TIMESTAMP -+ INTERVAL 'SS(.FFF)' SECOND
//'DD HH' DAY TO HOUR
<DateField> >= CURRENT_TIMESTAMP -+ INTERVAL 'DD HH' DAY TO HOUR
//'DD HH:MI' DAY TO MINUTE
<DateField> >= CURRENT_TIMESTAMP -+ INTERVAL 'DD HH:MI' DTY TO MINUTE
//'DD HH:MI:SS(.FFF)' DAY TO SECOND
<DateField> >= CURRENT_TIMESTAMP -+ INTERVAL 'DD HH:MI:SS(.FFF)' DAY TO SECOND
//'HH:MI' HOUR TO MINUTE
<DateField> >= CURRENT_TIMESTAMP -+ INTERVAL 'HH:MI' HOUR TO MINUTE
//'HH:SS(.FFF)' HOUR TO SECOND
<DateField> >= CURRENT_TIMESTAMP -+ INTERVAL 'HH:SS(.FFF)' HOUR TO SECOND
//'MI:SS(.FFF)' MINUTE TO SECOND
<DateField> >= CURRENT_TIMESTAMP -+ INTERVAL 'MI:SS(.FFF)' MINUTE TO SECOND
To demonstrate the INTERVAL
format, the example below uses the INTERVAL syntax to query data gathered over the 3 days, 5 hours, 32 minutes, and 28 seconds:
DateField >= CURRENT_TIMESTAMP - INTERVAL '3 05:32:28' DAY TO SECOND
Percentile statistic type
The percentile statistic
is supported if the supports
layer property (in advanced
) 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 statistic
, PERCENTILE_
(discrete) and PERCENTILE_
(continuous). Discrete returns a data value from within that dataset, while continuous is an interpolated value.
The order
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 order
set as ascending (ASC
) is 9, while the percentile for value
0.9 with order
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—Query using the
text
parameter on the states layer of ESRI_StateCityHighway_USA. - Example two—Query using a WHERE statement on the same layer.
- Example three—Query strings are case sensitive. In this example, UPPER is used to make the query case insensitive.
- Example four—Query the same states layer using geometry (envelope).
- Example five—Query the states layer by both geometry (envelope) and a WHERE statement.
- Example six—Query the states layer by a WHERE statement, specifying a list of fields to return, and requesting no geometry in the results.
- Example seven—Query the states layer by text parameter and requesting the geometry with the well-known ID of 102113 (Web Mercator).
- Example eight—Query a table using a WHERE clause and return object IDs only.
- Example nine—Use
group
andBy Fields F o r Statistics out
.Statistics - Example ten—Page through a query result using
result
andOffset result
.Record Count
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 group
and out
:
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 result
and result
, 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 return
and return
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 return
is false
:
{
"objectIdFieldName": "<objectIdFieldName>",
"objectIds": [
<objectId1>,
<objectId2>
]
}
Example three
The following example syntax is returned when return
is true
:
{
"count": <count>
}
Example four
The following example syntax is returned when group
and out
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 return
and return
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 return
is true
:
{
"objectIdFieldName": "objectid",
"objectIds": [
1,
2,
3,
4,
5,
7
]
}
Example three
The following example response is returned when return
is true
:
{
"count":48
}
Example four
The following example response is returned when group
and out
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
}
}
]
}