GIS Cookbook: Getting Started - Performing an Attribute Query
|Keywords: query, attribute, select, tabular, SQL|
Software: ArcGIS 8/9.x
Problem: You want to select map features that have certain tabular attributes.
Description: One of the most common functions in a GIS is the ability to ask the software to display all of the geographic features that meet some criteria. These criteria may be based on information stored in a layer’s attribute table (an attribute query) or they may involve desired spatial relationships between features in different geographic data layers (a spatial query). This recipe will focus on building an attribute query.
Assuming you have ArcMap open and have added all of the desired data layers, you can build an attribute query as follows:
1. Click on Selection > Select By Attributes.
2. In the Select By Attributes dialog, be sure to select the Layer whose attribute table you’d like to query. Upon selecting a layer, you should see a list of its Fields (or columns) appear on the left side of the dialog.
3. In the Fields list, double-click on the desired field. Note that the name of the field is added to the large text box in the bottom half of the window.
4. Next, click on one of the logical operators in the middle of the dialog (such as =, >, ≥, etc.).
5. The last step in building the query expression is to enter a value that is appropriate for the field and that defines your selection criteria when combined with the chosen logical operator. You may place the cursor at the end of the expression and manually type the desired value, or you may click the Get Unique Values button to see a list of the unique values within the chosen field and then double-click on one of the values listed to insert it at the end of the expression.
6. When you’ve finished building the query expression, click the Apply button. ArcMap will highlight the features that meet your criteria in the selection color (cyan, by default).
See Pitfall 1
|Using the Select By Attributes dialog to select U.S. states with a population density greater than 75.|
1. One of the options in the Select By Attributes dialog is Method. This defaults to Create a new selection, which means that if there are already some features selected, that selection set will be wiped out. Other choices include: Add to current selection, Remove from current selection, and Select from current selection. These other selection methods may be used to evaluate multiple attribute criteria one at a time.
2. Another way to evaluate multiple selection criteria is to use the logical operators And and Or. For example, if you wanted to select states with a population density over 75 and at least 50000 farms, after entering the value 75 you could click the And operator, then begin the three-step process (field-operator-value) again to enter the second part of the compound expression.
3. If you open the layer’s attribute table, note that the tabular records associated with the selected map features are also shown in the selection color. In fact, it is possible to invoke this same Select By Attibutes dialog by clicking on the Options button in the lower right of an open attribute table window.
4. Besides simply seeing which map features meet some criteria, creating a selection set is an important step in performing a number of other GIS functions. These include:
- Using the selection set for further analysis (such as buffering the selected features)
- Using the selection set to select features in another layer
- Editing the selection set (either the geometries of the features or their attributes)
- Creating a new layer from the subset
- Calculating summary statistics for the selected features
- and more...
5. Using the Save and Load buttons in the Select By Attributes dialog, it is possible to store query expressions on disk and re-load them at a later time.
|Authored by: Jim Detwiler Modified: 3/6/05|
Copyright © 2002-2014 by Regents of University of California,
Cookbook: Ben Sprague, Ethan Sundilson, Carlin Wong, Sam Ying