FRAMES | NO FRAMES | Description | Parameters | Examples | Response |
URL | http://<layer-url>/query |
Parent Resource | Layer / Table |
---|
Note: Prior to 10, the query operation could only be performed on layers. From 10 onward, in addition to layers, the query operation can be performed on tables as well.
The query operation is performed on a layer / table resource. The result of this operation is a featureset. This featureset 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 featureset. For tables, the featureset does not include geometries.
Note that all parameters related to geometry will be ignored when querying tables.
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 / tables.
Support for querying layers / tables based on time was added at 10.
For time-aware layers, users can use the time
parameter
to specify the time instant or the time extent to query.
At 10, a new returnIdsOnly
parameter was introduced.
If set to false
(default), the response will be a featureset.
If true
, 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
returnIdsOnly=true
and subsequently requesting feature sets for subsets of object IDs.
At 10, support for query based on objectIds
was added.
Supported for f=amf
was also added at 10.
At 10, support for generalizing
geometries returned by the query
operation was added.
At 10, query
operation returns additional fields
array
(JSON and AMF only) that contains array of field information for returned
values.
This array contains only fields specified in outFields
parameter.
See Layer/Table for defails on fields
.
NOTE: domains
member is not included in field information objects
returned with the response.
At 10, fieldAliases
member is deprecated.
You can provide arguments to the query operation as query parameters defined in the parameters table below.
Parameter | Details |
---|---|
f |
Description: The
response format. The default response format is html. Values: html | json | kmz | amf (default, when returnIdsOnly=false and returnCountOnly=false ) Values: html | json (when returnIdsOnly=true or returnCountOnly=true )
|
text | Description: 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 a short hand for a where clause of: . The text is case sensitive. This parameter is ignored if the where parameter is specified.Example: text=Los |
geometry | Description: 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:
|
geometryType | Description: 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 |
Description: 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 | Description: The spatial relationship to be applied on the input geometry
while performing the query. The supported spatial relationships include
intersects, contains, envelope intersects, within, etc. The default
spatial relationship is intersects (esriSpatialRelIntersects ).Values: esriSpatialRelIntersects
| esriSpatialRelContains | esriSpatialRelCrosses |
esriSpatialRelEnvelopeIntersects | esriSpatialRelIndexIntersects |
esriSpatialRelOverlaps | esriSpatialRelTouches | esriSpatialRelWithin | esriSpatialRelRelation |
relationParam | Description: 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 please refer to the documentation for the spatial relate function. |
where | Description:
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 |
objectIds |
Description:
The object IDs of this layer / table to be queried.
Syntax: objectIds=<objectId1>, <objectId2>
Example: objectIds=37, 462
|
time |
Description:
The time instant or the time extent to query.
Time instant Syntax: time=<timeInstant> Example: time=1199145600000 (1 Jan 2008 00:00:00 GMT)
Time extent Syntax: time=<startTime>, <endTime> Example: time=1199145600000, 1230768000000 (1 Jan 2008 00:00:00 GMT to 1 Jan 2009 00:00:00 GMT)
A null value specified for start time or end time will represent infinity for start or end time respectively. |
outFields | Description:
The list of fields to be included in the returned resultset. 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 Example (wildcard usage): outFields=* |
returnGeometry | Description: If true,
the resultset includes the geometry associated with each result. The default is true. Values: true | false |
maxAllowableOffset |
//This option was added at 10.0 Description: 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 then maxAllowableOffset is assumed to be in the unit of the spatial reference of the map.Example: maxAllowableOffset=2
|
outSR |
Description: 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. |
returnIdsOnly |
Description:
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=true and subsequently requesting feature sets for subsets of object IDs.
Values: false | true |
returnCountOnly |
//This option was added at 10.0 SP1 Description: 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: false | true |
Example 1: Query using the text parameter on the states layer of the ESRI_StateCityHighway_USA on sampleserver1:
http://sampleserver1.arcgisonline.com/ArcGIS/rest/services/Specialty/ESRI_StateCityHighway_USA/MapServer/1/query?text=TexasExample 2: Query using a where statement on the same layer. The output is JSON format:
http://sampleserver1.arcgisonline.com/ArcGIS/rest/services/Specialty/ESRI_StateCityHighway_USA/MapServer/1/query?where=STATE_NAME='Florida'&f=jsonExample 3: Query strings are case sensitive. In this example, UPPER is used to make the query case insensitive:
http://sampleserver1.arcgisonline.com/ArcGIS/rest/services/Specialty/ESRI_StateCityHighway_USA/MapServer/1/query?where=UPPER(STATE_NAME)=UPPER('colorado')Example 4: Querying the same states layer using geometry (envelope):
http://sampleserver1.arcgisonline.com/ArcGIS/rest/services/Specialty/ESRI_StateCityHighway_USA/MapServer/1/query?geometry=-125.4,35.2,-118.7,43.8&geometryType=esriGeometryEnvelopeExample 5: Querying the states layer by both geometry (envelope) and a where statement:
http://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>5000000Example 6: Querying the states layer by where statement, specifying a list of fields to return, and requesting no geometry in the results:
http://sampleserver1.arcgisonline.com/ArcGIS/rest/services/Specialty/ESRI_StateCityHighway_USA/MapServer/1/query?where=POP1999>15000000&returnGeometry=false&outFields=STATE_NAME,MALES,FEMALES,POP1999Example 7: Querying the states layer by text parameter and requesting the geometry with the well-known ID of 102113 (Web Mercator):
http://sampleserver1.arcgisonline.com/ArcGIS/rest/services/Specialty/ESRI_StateCityHighway_USA/MapServer/1/query?text=New+York&outSR=102113Example 8: Query a table using a WHERE clause and return OBJECTIDs only http://sampleserver3.arcgisonline.com/ArcGIS/rest/services/SanFrancisco/311Incidents/MapServer/1/query?objectIds=&where=agree_with_incident+%3D+1&returnGeometry=true&returnIdsOnly=true&f=html
returnIdsOnly=false
and returnCountOnly=false
){ "displayFieldName" : "<displayFieldName>", //fieldAliases deprecated at 10 "fieldAliases" : { "<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 "features" : [ //features may include geometry for layers only <feature1>, <feature2> ] }
returnIdsOnly=true
){ "objectIdFieldName" : "<objectIdFieldName>", "objectIds" : [ <objectId1>, <objectId2> ] }
returnCountOnly=true
){ "count" : <count> }
{
"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 }
}
]
}
{ "objectIdFieldName":"objectid", "objectIds":[1,2,3,4,5,7] }
{ "count":48 }