Query (Image Service)
- URL:https://<imageservice-url>/query
- Required Capability:Catalog
- Version Introduced:10.0
Description
As of 10.5, you must license your ArcGIS Server as an ArcGIS Image Server to use this resource.
The query operation is performed on an image service resource. It queries by applying the filter specified by the user. The result of this operation is a set of features or an array of raster IDs (if returnIdsOnly is set to true), a count (if returnCountOnly is set to true), or a set of field statistics (if outStatistics is used).
While there is a limit (maxRecordCount) to the number of features included in the feature set response, there is no limit to 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.8.1, the query operation supports rasterQuery if the image service uses ArcObjects11 or ArcObjectsRasterRendering as the service provider.
At 10.7, the exceededTransferLimit property is included in the JSON response if it hasnât reached the end of the query results. This property is typically used when paging through a query result with the optional resultOffset and resultRecordCount parameters, and it will also be affected by the maxRecordCount image service property. When exceededTransferLimit is true, it indicates there are more query results, and you can continue to page through the results. When the exceededTransferLimit property is false or missing, it indicates that you have reached the end of the query results.
At 10.4, the query operation supports geometryPrecision, maxAllowableOffset, and returnTrueCurves.
At 10.3.1, the query operation supports resultOffset and resultRecordCount.
At 10.3, the query operation supports multidimensionalDefinition.
At 10.2.1, the query operation supports outStatistics, groupByFieldsForStatistics, orderByFields, and returnDistinctValues.
You can provide arguments to the query operation as query parameters defined in the parameters table below.
Request parameters
Parameter |
Details |
---|---|
f |
The response format. The default response format is html. Values: html | json |
objectIds | The object IDs of the raster catalog to be queried. When this parameter is specified, any other filter parameters (including where) are ignored. When this parameter is specified, setting returnIdsOnly=true is invalid. Syntax: objectIds=<objectId1>, <objectId2> Example: objectIds=37, 462 |
where | A where clause for the query filter. Any legal SQL where clause operating on the fields in the raster catalog is allowed. Example: where=POP2000 > 350000 |
time | The time instant or the time extent to query.
|
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 comma-separated syntax. Syntax:
Examples:
|
geometryPrecision | This parameter 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 This parameter was added at 10.4. |
geometryType | The type of geometry specified by the geometry parameter. The geometry type can be envelope, point, line, or polygon. The default geometry type is 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 inSR is not specified, the geometry is assumed to be in the spatial reference of the service. |
spatialRel | 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 (esriSpatialRelIntersects). Values: esriSpatialRelIntersects | esriSpatialRelContains | esriSpatialRelCrosses | esriSpatialRelEnvelopeIntersects | esriSpatialRelIndexIntersects | esriSpatialRelOverlaps | esriSpatialRelTouches | esriSpatialRelWithin |
outFields | The list of fields to be included in the returned result set. This list is a comma-delimited list of field names. 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. The wildcard also implies returnGeometry=true; therefore, setting returnGeometry to false will have no effect. Example: outFields=AREANAME,ST,POP2000 Example (wildcard usage): outFields=* |
returnGeometry | If true, the result set includes the geometry associated with each result. The default is true. If the outFields parameter is set to the wildcard "*", it implies returnGeometry=true; therefore, setting returnGeometry to false has no effect. Values: true | false |
outSR | The spatial reference of the returned geometry. |
returnIdsOnly | If true, the response only includes an array of raster IDs. Otherwise, the response is a raster set. The default is false. While there is a limit to the number of rasters included in the raster set response, there is no limit to the number of raster IDs returned in the ID array response. Clients can exploit this to get all the query conforming raster IDs by specifying returnIdsOnly=true and subsequently requesting raster sets for subsets of raster IDs. Values: false | true |
returnCountOnly | If true, the response only includes the count (number of features) 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 This option was added at 10.0 SP1. |
pixelSize | Query visible rasters at a given pixel size. If pixelSize is not specified, rasters at all resolutions can be queried. The structure of the pixelSize parameter is the same as the structure of the point object returned by the ArcGIS REST API. In addition to the JSON structure, you can specify the pixel size with a comma-separated syntax. Syntax:
Examples:
This option was added at 10.1 SP1. |
orderByFields | Order results by one or more field names. Use ASC or DESC for ascending or descending order, respectively. Note:
Syntax: orderByFields=field1 <ORDER>, field2 <ORDER>, field3 <ORDER> Example: orderByFields=SensorName ASC, ProductName DESC This option was added at 10.2.1. |
returnDistinctValues | If true, returns distinct values based on the fields specified in outFields. This parameter applies only if the supportsAdvancedQueries property of the image service is true. Syntax: returnDistinctValues=<true | false> Example: returnDistinctValues=true This option was added at 10.2.1. |
outStatistics | The definitions for one or more field-based statistics to be calculated. Note:
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 option was added at 10.2.1. |
groupByFieldsForStatistics | One or more field names using the values that need to be grouped for calculating the statistics. Note: groupByFieldsForStatistics is valid only when the outStatistics parameter is used. Syntax: groupByFieldsForStatistics=field1, field2 Example: groupByFieldsForStatistics=SensorName, ProductName This parameter was added at 10.2.1. |
multidimensionalDefinition | The filters defined by multiple dimensional definitions. Syntax: [dimensionalDefinition1, dimensionalDefinition2, ...] This parameter was added at 10.3. See Dimensional Definition objects for more information. |
resultOffset | This option fetches query results by skipping a specified number of records. The query results start from the next record (for example, resultOffset + 1). The default value is 0. This parameter only applies when supportsPagination is true. You can use this option to fetch records that are beyond maxRecordCount. For example, if maxRecordCount is 1000, you can get the next 100 records by setting resultOffset = 1000 and resultRecordCount = 100. Query results can return the results in the range of 1001 to 1100. This parameter was added at 10.3.1. |
resultRecordCount | This option fetches query results up to the resultRecordCount specified. When resultOffset is specified and this parameter is not, the image service defaults 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: resultRecordCount=10 to fetch up to 10 records This parameter was added at 10.3.1. |
maxAllowableOffset | This option can be used to specify the maxAllowableOffset to be used for generalizing geometries returned by the query operation. The maxAllowableOffset parameter 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 service. Example: maxAllowableOffset=2 This option was added at 10.4. |
returnTrueCurves | If true, returns true curves in output geometries. Otherwise curves are converted to densified polylines or polygons. Syntax: returnTrueCurves=<true | false> Example: returnTrueCurves=true This option was added at 10.4. |
rasterQuery | Make query based on key properties of each raster catalog item. Any legal SQL where clause operating on the key properties of raster catalog items is allowed. Example: LANDSAT_WRS_PATH >= 150 AND LANDSAT_WRS_PATH<= 165 This option was added at 10.8.1. |
Example usage
Example 1: Query using a where clause and return specific outfields.
Example 2: Query using a point geometry and a where clause. Returns only OBJECTIDs.
Example 3: Query distinct sensors and products in an image service.
https://myserver/arcgis/rest/services/myImageService/ImageServer/query?where=1=1&outFields=SensorName,ProductName&returnDistinctValuesOnly=true&orderByFields=SensorName ASC, ProductName DESC
Example 4: Query latest image acquisition date for each sensor.
https://myserver/arcgis/rest/services/myImageService/ImageServer/query?outStatistics=[{ "statisticType": "max", "onStatisticField": "acquisitionDate", "outStatisticFieldName": "LatestImageDate" }]&groupByFieldsForStatistics=SensorName
JSON response syntax (when returnIdsOnly=false and returnCountOnly=false)
{
"objectIdFieldName" : "<objectIdFieldName>",
"spatialReference" : <spatialReference>,
"fields" : [
{"name" : "<fieldName1>", "type" : "<fieldType1>", "alias" : "<fieldAlias1>", "length" : "<length1>"},
{"name" : "<fieldName2>", "type" : "<fieldType2>", "alias" : "<fieldAlias2>", "length" : "<length2>"}
],
"features" : [
<feature1>, <feature2>
]
}
JSON response syntax (when returnCountOnly=true)
{
"count" : <count>
}
JSON response syntax (when returnIdsOnly=true)
{
"objectIdFieldName" : "<objectIdFieldName>",
"objectIds" : [ <objectId1>, <objectId2> ]
}
JSON response example
{
"objectIdFieldName" : "IMAGEID",
"spatialReference" : {"wkid" : 4326},
"fields" : [{ "name" : "ST", "alias" : "ST", "type" : "esriFieldTypeString", "length" : 2},
{
"name" : "OBJECTID", "alias" : "OBJECTID", "type" : "esriFieldTypeOID"},
{ "name" : "AREANAME", "alias" : "City Name", "type" : "esriFieldTypeString", "length" : 255}],
"geometryType" : "esriGeometryPolygon",
"features" : [
{
"geometry" : {
"rings" : [
[ [-97.06138,32.837], [-97.06133,32.836], [-97.06124,32.834], [-97.06127,32.832], [-97.06138,32.837] ]
]
},
"attributes" : {
"IMAGEID" : 37,
"OWNER" : "Joe Smith",
"VALUE" : 94820.37,
"APPROVED" : true,
"LASTUPDATE" : 1227663551096
}
},
{
"geometry" : {
"rings" : [
[ [-97.06326,32.759], [-97.06298,32.755], [-97.06153,32.749], [-97.06326,32.759] ]
]
},
"attributes" : {
"IMAGEID" : 462,
"OWNER" : "John Doe",
"VALUE" : 17325.90,
"APPROVED" : false,
"LASTUPDATE" : 1227628579430
}
}
]
}
JSON response example (when returnCountOnly=true)
{
"count":48
}