require(["esri/tasks/query"], function(Query) { /* code goes here */ });Description
(Added at v1.0)
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.
SamplesSearch for
samplesthat use this class.
Constructors new Query() Creates a new Query object used to execute a query on the layer resource identified by the URL. ConstantsSPATIAL_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_RELATION
Allows specification of any relationship defined using the Shape Comparison Language. 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. Properties
Constructor Details
Creates a new Query object used to execute a query on the layer resource identified by the URL.
Sample:require([ "esri/tasks/query", ... ], function(Query, ... ) { var query = new Query(); ... });
Property Details
Indicates if the service should cache the query results. It only applies if the layer's
advancedQueryCapabilities.supportsCacheHintis
true
. Use only for queries that have the same parameters every time the app is used. Some examples of cacheable queries:
Known values: true | false
Default value: false
The geometry to apply to the spatial filter. The spatial relationship as specified by
spatialRelationshipis applied to this geometry while performing the query. The valid geometry types are
Extent,
Point,
Multipoint,
Polyline, or
Polygon.
Sample: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); }
Specify the number of decimal places for the geometries returned by the query operation. (Added at v3.0)
Sample:query.geometryPrecision = 1;
One or more field names that will be used to group the statistics. groupByFieldsForStatistics
is only valid when outStatistics
have been defined. As of version 3.16, standard SQL expressions may also be used in place of field names when grouping by fields and querying hosted feature services for statistics. (Added at v2.6)
query.groupByFieldsForStatistics = ["SUB_REGION"];
The maximum allowable offset used for generalizing geometries returned by the query operation. The offset is in the units of the spatialReference. If a spatialReference is not defined the spatial reference of the map is used. (Added at v2.0)
Parameter to support querying feature services whose data source is a multipatch featureclass. (Added at v3.12)
Known values: xyFootprint
function queryTaskExecuteCompleteHandler(queryResults){ console.log("complete", queryResults); } function queryTaskErrorHandler(queryError){ console.log("error", queryError.error.details); } var queryTask = new QueryTask("http://servername.fqdn.suffix/arcgis/rest/services/Hosted/pasadena/FeatureServer/0"); var query = new Query(); query.objectIds = [22]; query.multipatchOption = "xyFootprint"; query.outFields = ["*"]; query.returnGeometry = true; queryTask.on("complete", queryTaskExecuteCompleteHandler); queryTask.on("error", queryTaskErrorHandler); queryTask.execute(query);
Number of features to retrieve. Should be used in conjunction with
query.start. Use this to implement paging and retrieve "pages" of results when querying. If not provided, but an instance of Query has a start property, num defaults to 10. It can be used with
hosted features servicesin addition to map and feature services hosted by ArcGIS for Server that support pagination (versions 10.3.1 or higher).
(Added at v3.9)A comma delimited list of ObjectIds for the features in the layer/table that you want to query. (Added at v2.0)
One or more field names that will be used to order the query results. Specifiy ASC (ascending) or DESC (descending) after the field name to control the order. The default order is ASC. orderByFields
is only supported on dynamic layers and tables where supportsAdvancedQueries
is true. As of version 3.16, standard SQL expressions may also be used in place of field names when ordering by fields in statistic queries on hosted feature services.
query.orderByFields = ["STATE_NAME DESC"];
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.
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.
Sample:query.outFields = ["NAME", "STATE_ABBR", "POP04"];
The definitions for one or more field-based statistic to be calculated. outStatistics
is only supported on layers/tables where supportsStatistics
is true. If outStatistics
is specified then only a subset of query parameters are supported. The supported parameters depends on the version of your service. See the ArcGIS REST API documentation for details on which query parameters are supported at each version.
require([ "esri/tasks/query", "esri/tasks/StatisticDefinition", ... ], function(Query, StatisticDefinition, ... ) { var query = new Query(); var statisticDefinition = new StatisticDefinition(); statisticDefinition.statisticType = "sum"; statisticDefinition.onStatisticField = "POP2000"; statisticDefinition.outStatisticFieldName = "TotalPop"; query.outStatistics = [statisticDefinition]; ... });
Specify the pixel level to be identified on the x and y axis. Defaults to the base resolution of the dataset if not specified. Applicable only to Image Service layers. (Added at v3.5)
Used to project the geometry onto a virtual grid, likely representing pixels on the screen.
:
Quantizationparameter only works with ArcGIS Online hosted services.
See the object specifications table below for the structure of the quantizationParameters object.
(Added at v3.12) Object Specifications:<quantizationParameters
>
Extent
> extent Required An extent defining the quantization grid bounds. Its SpatialReference
matches the input geometry spatial reference if one is specified for the query. Otherwise, the extent will be in the layer's spatial reference. <String
> mode Required Available value: "view
". Geometry coordinates are optimized for viewing and displaying of data. <String
> originPosition Required Available value: "upperLeft
" or "lowerLeft
". Integer's coordinates will be returned relative to the origin position defined by this property value. Default is upperLeft
origin position. <Number
> tolerance Required The tolerance
is the size of one pixel in the outSpatialReference
units, this number is used to convert the coordinates to integers by building a grid with resolution matching the tolerance
. Each coordinate is then snapped to one pixel on the grid. Consecutive coordinates snapped to the same pixel are removed for reducing the overall response size. The tolerance
is in the units of outSpatialReference
. If outSpatialReference
is not specified, then tolerance
is assumed to be in the unit of the spatial reference of the layer. If the tolerance
is not specified, the maxAllowableOffset
is used. If the tolerance
and maxAllowableOffset
are not specified, a default 10,000 * 10,000 grid is used. Sample:
var query = new Query(); query.quantizationParameters = { mode: "view", originPosition: "upperLeft", tolerance: 4820, extent: layer.fullExtent };
The 'Shape Comparison Language' string to evaluate. Examples of valid strings are:
RELATE(G1,G2,"FFFTTT***)
dim (g1.boundary,g2.boundary) = linear
dim (g1.exterior, g2.boundary)= linear
The string describes the spatial relationship to be tested when the spatial relationship is esriSpatialRelRelation The Shape Comparison Language EDN topic has additional details.
If true then returns distinct values based on the fields specified in the
outFields
. This parameter applies only if
supportsAdvancedQueriesproperty of the layer is true. Requires ArcGIS Server 10.1 Service Pack 1 or later.
(Added at v3.11)Known values: true | false
Default value: false
If "true", each feature in the
FeatureSetincludes 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
The spatial relationship to be applied on the input geometry while performing the query. The valid values are listed in the
Constantstable.
Default value: SPATIAL_REL_INTERSECTS
require([ "esri/tasks/query", ... ], function(Query, ... ) { var query = new Query(); query.spatialRelationship = Query.SPATIAL_REL_CONTAINS; ... });
Zero-based index indicating where to begin retrieving features. Should be used in conjunction with
query.num. Use this to implement paging and retrieve "pages" of results when querying. Features are sorted ascending by their object ID field by default. This can be used with
hosted features servicesin addition to map and feature services hosted by ArcGIS for Server that support pagination (versions 10.3.1 or higher).
(Added at v3.9)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.
Sample:query.text = stateName;
Specify a time extent for the query. (Added at v2.0)
Sample:require([ "esri/layers/FeatureLayer", "esri/TimeExtent", "esri/tasks/query", ... ], function(FeatureLayer, TimeExtent, Query, ... ) { var layer = new FeatureLayer( ... ); var timeExtent = new TimeExtent( ... ); var timeQuery = new Query(); timeQuery.timeExtent = timeExtent; layer.queryFeatures(timeQuery,function(featureSet) {}); ... });
The unit for calculating the buffer distance. if unit is not specified, the unit is derived from the geometry spatial reference. If the geometry spatial reference is not specified, the unit is derived from the feature service spatial reference. This parameter only applies if
FeatureLayer.supportsQueryWithDistanceis true. It can be used with
hosted features servicesin addition to map and feature services hosted by ArcGIS for Server 10.31 onward. Optional.
(Added at v3.9)Known values: "feet" | "miles" | "nautical-miles" | "us-nautical-miles" | "meters" | "kilometers"
A where clause for the query. Any legal SQL where clause operating on the fields in the layer is allowed.
Sample:String 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;
RetroSearch is an open source project built by @garambo | Open a GitHub Issue
Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo
HTML:
3.2
| Encoding:
UTF-8
| Version:
0.7.4