Query Attributes task
The Query Attributes task helps users select or view certain data on the map based on that data's attributes. A Query Attributes task creates a single query on one map layer. However, the query can have compound criteria. For example, you can define a query on a cities layer that selects cities with a population greater than a value entered by the user and with a name that begins with a value entered by the user.
Additionally, the Query Attributes task supports relates and stand-alone tables. Relates simply define a relationship between two tables without appending the associated data in each table. In many cases, the relates point toward stand-alone tables, which lack geometry but often contain valuable attribute information. For example, if you published a map service that contained relates between city parcels and a stand-alone table of parcel owners, you could use the Query Attributes task to display the owners and location of the parcel in the query results.
When you configure the Query Attributes task, you create an easy-to-understand form that will guide the user through the process of making the query. This way, users of your application will not have to know the details about the dataset, nor will they have to construct a Structured Query Language (SQL) statement to query the data.
For example, suppose you wanted users to select U.S. counties by entering a state name and a minimum average household size. A SQL expression for this selection might look something like this: SELECT * FROM counties.sdc.counties WHERE: "STATE_NAME" = 'Idaho' AND "AVE_HH_SZ" > 3.0. The users of your Web application might not know the field names of your data or how to write a SQL statement. You can help them by using the Query Attributes task to create an easy-to-read form with text like the following: I want to select counties in the state of: (user picks a state from a drop-down list) whose average household size is greater than or equal to: (user types a number in a text box).
After adding a Query Attributes task to your application, click the Configure button to display the task configuration settings. You use this dialog box to build the query and to specify the wording that a user sees when the task is displayed. You can also adjust how the results will be displayed.
Choosing the text to appear in the task
The General tab allows you to fine-tune the wording that users will see when they run your task. You can change the following:
- The name of the task. This name appears along the top bar of the Web Mapping Application.
- The text on the button users will click to execute the task.
Building the query
Use the Settings tab to build your query. After selecting a map service and a layer to query, click the Add button to add a condition to your query. You can add multiple conditions to create a compound query. If you're new to SQL or you need a review, a good place to start is Building a query expression in the ArcGIS Desktop Help.
The example above shows a query condition allowing the user to enter a value and find counties with a population greater than that value.
Remember the following points when setting up a Query Attributes task:
- By default, the Query Attributes task limits results to 50. You can raise or lower this value on the Results tab of the task configuration dialog box in Manager.
-
By default, ArcGIS Server map services limit the number of records returned by a query to 1,000 records. You can raise this limit in the Service Properties dialog box. The limit is important to remember when configuring the task because if you click the Get Sample Values button, only the first 1,000 records will be scanned for unique values.
Resetting the limit to a very high value can degrade performance. For example, queries that return more than 2,000 records require the software to do extra work to create scratch workspaces in your system TEMP directory to manage the result records.
- When configuring the task with multiple query expressions, the expressions are joined using the and operator. The or operator is not supported in Manager.
- If your expression uses the like operator, the end user can use wildcard characters when typing in the string to match. % (percent sign) means that anything is acceptable in its place: one character, a hundred characters, or no character. Alternatively, _ (underscore) will match a single character. For example, the end user can type in _atherine to match both Catherine and Katherine.
- If you want to customize the query string beyond what you can do in Manager, you can open the application in an integrated development environment (IDE), such as Microsoft Visual Studio, and edit the task there. Choose the option to use a Custom Where Expression and enter the SQL expression for your query.
-
Constructing a SQL expression for date/time fields requires additional formatting depending on what database your data is stored in. For example, when your data is in a personal geodatabase, you need to enclose the date in # signs.
If you don't want users to have to enter the # sign or any other special formatting whenever they query dates, you can make the special formatting part of the expression. To do this, you need to edit the task in Visual Studio and choose the Custom Where Expression option. The following expression queries two date fields in a personal geodatabase, represented by {0} and {1}:
mydate >= #{0}# AND mydate <= #{1}#
Other databases do not require the # signs but require other special syntax. To make sure you've structured your expression correctly, see the Dates section of the topic SQL reference for query expressions used in ArcGIS.
- If you don't see a particular layer in the list of layers, it's because it can't be queried. For example, certain raster layers don't have any attributes and thus will not appear in the list. Additionally, certain map services don't support queries, such as WMS services.
- You may find it helpful to create a practice application to gain experience with creating queries in Manager. Before deploying any application, test your queries with known values to see if they yield the expected results.
Choosing how results will be displayed
Use the Results tab to configure how task results will appear. It's helpful to know the following:
- You can disable the default behaviors of grouping the results by layer and showing the attributes of the records returned by the search. You may want to test different settings to find which appearance best meets your needs.
- If you choose to enable MapTips, users can click result features to see an informational pop-up window. Result features will also be highlighted when users hover the mouse pointer over them.
- You can change how the results appear on the Results panel and in the MapTips by choosing Custom formatting. When you do this, additional tabs appear that allow you to change the color of the result features, the information to be included, and the text format.