Class: QueryE-mail This Topic Printable Version Give Us Feedback

Description

Query for input to the QueryTask. Not all query properties are required to execute a QueryTask. The query definition requires one of the following properties: queryGeometry, text, or where. Optional properties include outFields, outSpatialReference, and returnGeometry.

Class hierarchy

esri.tasks.Query

Constructor

Constructor Description
esri.tasks.Query() Creates a new QueryTask object used to execute a query on the layer resource identified by the URL.

Properties

Property Type Description
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, Point, Multipoint, Polyline, or Polygon.

outFields String[] Attribute fields to include in the FeatureSet. Fields must exist in the map layer. 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. You can set field alias names in the map document or in Manager.

When you specify the output fields, you should limit the fields to only those you expect to use in the query or the results. The fewer fields you include, the faster the response will be.

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.
outSpatialReference SpatialReference The spatial reference for the returned geometry. If not specified, the geometry is returned in the spatial reference of the map. See Projected Coordinate Systems and Geographic Coordinate Systems for the list of supported spatial references.
returnGeometry Boolean If "true", each feature in the FeatureSet includes the geometry. Set to "false" (default) if you do not plan to include highlighted features on a map since the geometry makes up a significant portion of the response.
spatialRelationship String The spatial relationship to be applied on the input geometry while performing the query. The valid values are listed in the Constants table.
text String Shorthand for a where clause using "like". The field used is the display field defined in the map document. You can determine what the display field is for a layer in Services Directory.
where String A where clause for the query. Any legal SQL where clause operating on the fields in the layer is allowed.

Constants

Constant Description
SPATIAL_REL_CONTAINS Part or all of a feature from feature class 1 is contained within a feature from feature class 2.
SPATIAL_REL_CROSSES The feature from feature class 1 crosses a feature from feature class 2.
SPATIAL_REL_ENVELOPEINTERSECTS The envelope of feature class 1 intersects with the envelope of feature class 2.
SPATIAL_REL_INDEXINTERSECTS The envelope of the query feature class intersects the index entry for the target feature class.
SPATIAL_REL_INTERSECTS Part of a feature from feature class 1 is contained in a feature from feature class 2.
SPATIAL_REL_OVERLAPS Features from feature class 1 overlap features in feature class 2.
SPATIAL_REL_TOUCHES The feature from feature class 1 touches the border of a feature from feature class 2.
SPATIAL_REL_WITHIN The feature from feature class 1 is completely enclosed by the feature from feature class 2
Constructor Detail

esri.tasks.Query()

Creates a new QueryTask object used to execute a query on the layer resource identified by the URL.
Properties Detail

<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, Point, Multipoint, Polyline, or Polygon.

Code snippets:
      function executeQueryTask(event) {
        //When the user clicks on a map, the onClick event returns the event point 
		where the user clicked. The event contains mapPoint (esri.geometry.Point)

        query.geometry = event.mapPoint;

        //Execute task
        queryTask.execute(query, showResults);
      }

<String[]> outFields

Attribute fields to include in the FeatureSet. Fields must exist in the map layer. 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. You can set field alias names in the map document or in Manager.

When you specify the output fields, you should limit the fields to only those you expect to use in the query or the results. The fewer fields you include, the faster the response will be.

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.
Code snippets:
query.outFields = ["NAME", "STATE_ABBR", "POP04"];

<SpatialReference> outSpatialReference

The spatial reference for the returned geometry. If not specified, the geometry is returned in the spatial reference of the map. See Projected Coordinate Systems and Geographic Coordinate Systems for the list of supported spatial references.

<Boolean> returnGeometry

If "true", each feature in the FeatureSet includes the geometry. Set to "false" (default) if you do not plan to include highlighted features on a map since the geometry makes up a significant portion of the response.
Known values: true | false
Default value: false

<String> spatialRelationship

The spatial relationship to be applied on the input geometry while performing the query. The valid values are listed in the Constants table.
Default value: SPATIAL_REL_INTERSECTS
Code snippets:
var myQuery = new esri.tasks.Query();
myQuery.spatialRelationship = esri.tasks.Query.SPATIAL_REL_CONTAINS;

<String> text

Shorthand for a where clause using "like". The field used is the display field defined in the map document. You can determine what the display field is for a layer in Services Directory.
Code snippets:
query.text = stateName;

<String> where

A where clause for the query. Any legal SQL where clause operating on the fields in the layer is allowed.
Code snippets:
Sring query example. Be sure you have the correct sequence of single and double quotes when writing the where clause in JavaScript.
  query.where = "NAME = '" + stateName + "'"; 
		
Number query example.
  query.where = "POP04 > " + population;