Packagecom.esri.ags.tasks.supportClasses
Classpublic class Query
InheritanceQuery Inheritance flash.events.EventDispatcher

Input parameters for a QueryTask or one of the query or select methods for a FeatureLayer. The query definition requires at least one of the following properties: geometry and/or either text OR where. Optional properties include outFields, outSpatialReference and returnGeometry.

The text property will search the display field of your layer, it is a short hand for a where clause of: where YourDisplayField like '%SearchText%'.

View the examples

See also

Concepts - Using Query
ArcGIS SOAP API Help - Spatial relationship operators
Live sample - Query on map extent changes.
Live sample - Query a raster catalog in an ImageService
Live sample - Query for statistics
Live sample - Query for statistics (advanced)
com.esri.ags.tasks.QueryTask


Public Properties
 PropertyDefined By
  geometry : Geometry
The geometry to apply to the spatial filter.
Query
  groupByFieldsForStatistics : Array
This will contain a list of fields to group by during statistical analysis.
Query
  maxAllowableOffset : Number
The maximum allowable offset used for generalizing geometries returned by the Query operation.
Query
  objectIds : Array
The object IDs of this layer/table to be queried.
Query
  orderByFields : Array
One or more field names using which the features/records need to be ordered.
Query
  outFields : Array
Attribute fields to include in the FeatureSet.
Query
  outSpatialReference : SpatialReference
The well-known ID of the spatial reference for the returned geometry.
Query
  outStatistics : Array
The definitions for one or more field-based statistic to be calculated.
Query
  pixelSizeX : Number
The size of pixel in X direction used to query visible rasters.
Query
  pixelSizeY : Number
The size of pixel in Y direction used to query visible rasters.
Query
  relationParam : String
The spatial relate function that can be applied while performing the query operation.
Query
  returnDistinctValues : Boolean
If true then returns distinct values based on the fields specified in outFields.
Query
  returnGeometry : Boolean
If true, each feature in the FeatureSet includes the geometry.
Query
  returnM : Boolean
If true, M values will be included in the geometry if the features have M values.
Query
  returnZ : Boolean
If true, Z values will be included in the geometry if the features have Z values.
Query
  spatialRelationship : String
The spatial relationship to be applied on the input geometry while performing the query.
Query
  text : String
Shorthand for a literal search text on the display field, equivalent to: where YourDisplayField like '%SearchText%'.
Query
  timeExtent : TimeExtent
The time instant or the time extent to query.
Query
  where : String
A where clause for the query.
Query
Public Constants
 ConstantDefined By
  SPATIAL_REL_CONTAINS : String = esriSpatialRelContains
[static] Part or all of a feature from feature class 1 is contained within a feature from feature class 2.
Query
  SPATIAL_REL_CROSSES : String = esriSpatialRelCrosses
[static] Two polylines cross if they share only points in common, at least one of which is not an endpoint.
Query
  SPATIAL_REL_ENVELOPEINTERSECTS : String = esriSpatialRelEnvelopeIntersects
[static] The envelope of feature class 1 intersects with the envelope of feature class 2.
Query
  SPATIAL_REL_INDEXINTERSECTS : String = esriSpatialRelIndexIntersects
[static] The envelope of the query feature class intersects the index entry for the target feature class.
Query
  SPATIAL_REL_INTERSECTS : String = esriSpatialRelIntersects
[static] Part of a feature from feature class 1 is contained in a feature from feature class 2.
Query
  SPATIAL_REL_OVERLAPS : String = esriSpatialRelOverlaps
[static] Features from feature class 1 overlap features in feature class 2.
Query
  SPATIAL_REL_RELATION : String = esriSpatialRelRelation
[static] Allows specification of a spatial relate function.
Query
  SPATIAL_REL_TOUCHES : String = esriSpatialRelTouches
[static] The feature from feature class 1 touches the border of a feature from feature class 2.
Query
  SPATIAL_REL_WITHIN : String = esriSpatialRelWithin
[static] The feature from feature class 1 is completely enclosed by the feature from feature class 2.
Query
Property Detail
geometryproperty
geometry:Geometry

The geometry to apply to the spatial filter. The spatial relationship as specified by spatialRelationship is applied to this geometry while performing the query. The valid geometry types are Extent, MapPoint, Multipoint, Polyline, or Polygon.

This property can be used as the source for data binding.


Implementation
    public function get geometry():Geometry
    public function set geometry(value:Geometry):void

See also

groupByFieldsForStatisticsproperty 
groupByFieldsForStatistics:Array

Since : ArcGIS API 3.0 for Flex

This will contain a list of fields to group by during statistical analysis. If an out field is not being used in the outStatistics calculation it should be placed here. This property works together with outStatistics. Requires ArcGIS 10.1 or later.

This property can be used as the source for data binding.


Implementation
    public function get groupByFieldsForStatistics():Array
    public function set groupByFieldsForStatistics(value:Array):void
maxAllowableOffsetproperty 
maxAllowableOffset:Number

Since : ArcGIS API for Flex 2.0

The maximum allowable offset used for generalizing geometries returned by the Query operation. The units are the same as the returned features. Requires ArcGIS Server 10.0 or above.

This property can be used as the source for data binding.


Implementation
    public function get maxAllowableOffset():Number
    public function set maxAllowableOffset(value:Number):void
objectIdsproperty 
objectIds:Array

Since : ArcGIS API for Flex 2.0

The object IDs of this layer/table to be queried. Requires ArcGIS Server 10.0 or above.

This property can be used as the source for data binding.


Implementation
    public function get objectIds():Array
    public function set objectIds(value:Array):void
orderByFieldsproperty 
orderByFields:Array

Since : ArcGIS API 3.0 for Flex

One or more field names using which the features/records need to be ordered. Use ASC or DESC, for ascending or descending respectively, following every field to control the ordering. Defaults to ASC (ascending order) if unspecified. Requires ArcGIS 10.1 or later.

This property can be used as the source for data binding.


Implementation
    public function get orderByFields():Array
    public function set orderByFields(value:Array):void

Example
ActionScript - ordering for specific fields:
     myQuery.orderByFields = ["STATE_NAME ASC", "RACE DESC", "GENDER"];
outFieldsproperty 
outFields:Array

Since : Note that with ArcGIS Server 10.0 the wildcard no longer implicitly implies returnGeometry=true.

Attribute fields to include in the FeatureSet. Fields must exist in the layer or table. You must list the actual field names rather than the alias names. Returned fields are also the actual field names. However, you are able to use the alias names when you display the results.

For optimal performance, limit the output fields to only those you expect to use.

Each query must have access to the Shape and Objectid fields for a layer, but your list of fields does not need to include these two fields.

To return all fields, specify the wildcard "*" as the value of this parameter. In this case, the query results include all the fields.

This property can be used as the source for data binding.


Implementation
    public function get outFields():Array
    public function set outFields(value:Array):void

Example
ActionScript - ask for specific fields:
     myQuery.outFields = ["CITY_NAME","AGE_UNDER5","AGE_5_17","AGE_18_64","AGE_65_UP"];
ActionScript - To request all fields, use the star wildcard (this implies returnGeometry=true and setting returnGeometry to false will have no effect):
     myQuery.outFields = ["*"];
outSpatialReferenceproperty 
outSpatialReference:SpatialReference

The well-known ID of the spatial reference for the returned geometry. If not specified, the geometry is returned in the spatial reference of the map.

This property can be used as the source for data binding.


Implementation
    public function get outSpatialReference():SpatialReference
    public function set outSpatialReference(value:SpatialReference):void

Example
To display query results on a map, make sure to return geometries and setting the outSpatialReference as appropriate:
     <esri:Query id="query" outSpatialReference="{myMap.spatialReference}" text="{qText.text}" returnGeometry="true">
outStatisticsproperty 
outStatistics:Array

Since : ArcGIS API 3.0 for Flex

The definitions for one or more field-based statistic to be calculated. This is supported on only those layers / tables that indicate suppportsStatistics is true. When using outStatistics, the only other properties that will be used are "groupByFieldsForStatistics", "orderByFields", "geometry", "text", "timeExtent" and "where". Requires ArcGIS 10.1 or later. ArcGIS 10.2 or later also supports gdbVersion.

This property can be used as the source for data binding.


Implementation
    public function get outStatistics():Array
    public function set outStatistics(value:Array):void

See also

pixelSizeXproperty 
pixelSizeX:Number

Since : ArcGIS API 3.1 for Flex

The size of pixel in X direction used to query visible rasters. Requires ArcGIS for Server 10.1 or later.

This property can be used as the source for data binding.


Implementation
    public function get pixelSizeX():Number
    public function set pixelSizeX(value:Number):void
pixelSizeYproperty 
pixelSizeY:Number

Since : ArcGIS API 3.1 for Flex

The size of pixel in Y direction used to query visible rasters. Requires ArcGIS for Server 10.1 or later.

This property can be used as the source for data binding.


Implementation
    public function get pixelSizeY():Number
    public function set pixelSizeY(value:Number):void
relationParamproperty 
relationParam:String

The spatial relate function that can be applied while performing the query operation. An example for this spatial relate function is "FFFTTT***". This is used if spatialRelationship is SPATIAL_REL_RELATION ("esriSpatialRelRelation"). For more information on this spatial relate function please refer to the documentation for the spatial relate function.

This property can be used as the source for data binding.


Implementation
    public function get relationParam():String
    public function set relationParam(value:String):void
returnDistinctValuesproperty 
returnDistinctValues:Boolean

Since : ArcGIS API 3.1 for Flex

If true then returns distinct values based on the fields specified in outFields. This parameter applies only if supportsAdvancedQueries property of the layer is true. Requires ArcGIS for Server 10.1 Service Pack 1 or later.

The default value is false.

This property can be used as the source for data binding.


Implementation
    public function get returnDistinctValues():Boolean
    public function set returnDistinctValues(value:Boolean):void
returnGeometryproperty 
returnGeometry:Boolean

If true, each feature in the FeatureSet includes the geometry. Since the geometry makes up a significant portion of the response, only use when you plan to use the geometry of the feature, for example, to include them on a map.

The default value is false.

This property can be used as the source for data binding.


Implementation
    public function get returnGeometry():Boolean
    public function set returnGeometry(value:Boolean):void
returnMproperty 
returnM:Boolean

Since : ArcGIS API 3.0 for Flex

If true, M values will be included in the geometry if the features have M values. Requires ArcGIS 10.1 or later (and data with M values).

The default value is false.

This property can be used as the source for data binding.


Implementation
    public function get returnM():Boolean
    public function set returnM(value:Boolean):void
returnZproperty 
returnZ:Boolean

Since : ArcGIS API 3.0 for Flex

If true, Z values will be included in the geometry if the features have Z values. Requires ArcGIS 10.1 or later (and data with Z values).

The default value is false.

This property can be used as the source for data binding.


Implementation
    public function get returnZ():Boolean
    public function set returnZ(value:Boolean):void
spatialRelationshipproperty 
spatialRelationship:String

The spatial relationship to be applied on the input geometry while performing the query. See constants below for possible input values.

The default value is SPATIAL_REL_INTERSECTS.

This property can be used as the source for data binding.


Implementation
    public function get spatialRelationship():String
    public function set spatialRelationship(value:String):void

See also

textproperty 
text:String

Shorthand for a literal search text on the display field, equivalent to: where YourDisplayField like '%SearchText%'. The search text is case sensitive. This parameter is ignored if the where parameter is specified. You can determine what the display field is for a layer using the ArcGIS Services Directory.

This property can be used as the source for data binding.


Implementation
    public function get text():String
    public function set text(value:String):void
timeExtentproperty 
timeExtent:TimeExtent

Since : ArcGIS API for Flex 2.0

The time instant or the time extent to query. Set the TimeExtent's startTime and endTime to the same time to define a time instant. Requires ArcGIS Server 10.0 or above.

This property can be used as the source for data binding.


Implementation
    public function get timeExtent():TimeExtent
    public function set timeExtent(value:TimeExtent):void
whereproperty 
where:String

A where clause for the query. Any valid SQL where clause operating on the fields in the layer is allowed, for example:

Strings must always be enclosed in single quotes in queries. For example: query.where = "STATE_NAME = 'California'".

Strings are case sensitive in expressions. For feature classes and tables, you can use the UPPER or LOWER function to set the case for a selection. For example: query.where = "UPPER(STATE_NAME) = 'RHODE ISLAND'".

The wildcards you use to conduct a partial string search also depend on the data source you are querying. For example, in a file-based or ArcSDE geodatabase data source, this expression would select Mississippi and Missouri among USA state names: query.where = "STATE_NAME LIKE 'Miss%'". The percent symbol (%) means that anything is acceptable in its place - one character, a hundred characters, or no character. The wildcards you use to query personal geodatabases are asterisk ( for any number of characters and question mark (?) for one character.

The decimal point (.) is always used as the decimal delimiter, regardless of your locale or regional settings. The comma cannot be used as a decimal or thousands delimiter in an expression. You can query numbers using the equal (=), not equal (<>), greater than (>), less than (<), greater than or equal to (>=), less than or equal to (<=), and BETWEEN operators. For example: query.where = "POP2000 > 350000".

Other examples: query.where = "OBJECTID BETWEEN 1 AND 10". query.where = "STATE IN ('CA','OR')". query.where = "NOT (STATE IN ('KY','WV'))". query.where = "POCTEL1 IS Null".

What constitutes "valid" SQL depends on the backend database for a specific REST endpoint. The backend can be a Personal Geodatabase, File Geodatabase, Shapefile, or SDE Geodatabase (of different databases). Depending on the type and database, the SQL might be slightly different, especially for dates.

Refer to the documentation of your DBMS for a list of supported functions.

This property can be used as the source for data binding.


Implementation
    public function get where():String
    public function set where(value:String):void

See also

Constant Detail
SPATIAL_REL_CONTAINSConstant
public static const SPATIAL_REL_CONTAINS:String = esriSpatialRelContains

Part or all of a feature from feature class 1 is contained within a feature from feature class 2.

SPATIAL_REL_CROSSESConstant 
public static const SPATIAL_REL_CROSSES:String = esriSpatialRelCrosses

Two polylines cross if they share only points in common, at least one of which is not an endpoint. A polyline and an polygon cross if they share a polyline in common on the interior of the polygon which is not equivalent to the entire polyline. Cross is a Clementini operator.

SPATIAL_REL_ENVELOPEINTERSECTSConstant 
public static const SPATIAL_REL_ENVELOPEINTERSECTS:String = esriSpatialRelEnvelopeIntersects

The envelope of feature class 1 intersects with the envelope of feature class 2.

SPATIAL_REL_INDEXINTERSECTSConstant 
public static const SPATIAL_REL_INDEXINTERSECTS:String = esriSpatialRelIndexIntersects

The envelope of the query feature class intersects the index entry for the target feature class.

SPATIAL_REL_INTERSECTSConstant 
public static const SPATIAL_REL_INTERSECTS:String = esriSpatialRelIntersects

Part of a feature from feature class 1 is contained in a feature from feature class 2.

SPATIAL_REL_OVERLAPSConstant 
public static const SPATIAL_REL_OVERLAPS:String = esriSpatialRelOverlaps

Features from feature class 1 overlap features in feature class 2.

SPATIAL_REL_RELATIONConstant 
public static const SPATIAL_REL_RELATION:String = esriSpatialRelRelation

Allows specification of a spatial relate function.

SPATIAL_REL_TOUCHESConstant 
public static const SPATIAL_REL_TOUCHES:String = esriSpatialRelTouches

The feature from feature class 1 touches the border of a feature from feature class 2.

SPATIAL_REL_WITHINConstant 
public static const SPATIAL_REL_WITHIN:String = esriSpatialRelWithin

The feature from feature class 1 is completely enclosed by the feature from feature class 2.

Examples
ActionScript code for a query
 var query:Query = new Query();
 query.where = "STATE_NAME = 'Alaska' AND TYPE = 'city'";
 query.returnGeometry = true;
 query.outFields = ["CITY_NAME","AGE_UNDER5","AGE_5_17","AGE_18_64","AGE_65_UP"];