This page describes an older version, please see latest API at http://resources.arcgis.com/en/help/flex-api/apiref/com/esri/ags/tasks/supportClasses/Query.html.
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
Live sample - Query on map extent changes.
Live sample - Query a raster catalog in an ImageService
Spatial relationship operators in SOAP documentation
com.esri.ags.tasks.QueryTask


Public Properties
 PropertyDefined By
  geometry : Geometry
[read-only] The geometry to apply to the spatial filter.
Query
  maxAllowableOffset : Number
[read-only] The maximum allowable offset used for generalizing geometries returned by the Query operation.
Query
  objectIds : Array
[read-only] The object IDs of this layer/table to be queried.
Query
  outFields : Array
[read-only] Attribute fields to include in the FeatureSet.
Query
  outSpatialReference : SpatialReference
[read-only] The well-known ID of the spatial reference for the returned geometry.
Query
  relationParam : String
[read-only] The spatial relate function that can be applied while performing the query operation.
Query
  returnGeometry : Boolean
[read-only] If true, each feature in the FeatureSet includes the geometry.
Query
  spatialRelationship : String
[read-only] The spatial relationship to be applied on the input geometry while performing the query.
Query
  text : String
[read-only] Shorthand for a literal search text on the display field, equivalent to: where YourDisplayField like '%SearchText%'.
Query
  timeExtent : TimeExtent
[read-only] The time instant or the time extent to query.
Query
  where : String
[read-only] 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  [read-only]

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

See also

maxAllowableOffsetproperty 
maxAllowableOffset:Number  [read-only]

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
objectIdsproperty 
objectIds:Array  [read-only]

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
outFieldsproperty 
outFields:Array  [read-only]

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

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  [read-only]

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

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">
relationParamproperty 
relationParam:String  [read-only]

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
returnGeometryproperty 
returnGeometry:Boolean  [read-only]

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
spatialRelationshipproperty 
spatialRelationship:String  [read-only]

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

See also

textproperty 
text:String  [read-only]

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
timeExtentproperty 
timeExtent:TimeExtent  [read-only]

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
whereproperty 
where:String  [read-only]

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

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"];