Asking the Right Questions
Getting started using queries
By Monica Pratt, ArcUser Editor
One of the defining characteristics of GIS is the ability to ask questions (and get answers) in a spatial context. These questions or queries are requests for information that are posed in a specific fashion. Queries are expressed in a formal way using Structured Query Language (SQL). This language is composed of a set of commands and rules that are used to ask questions of a database. SQL, which has been implemented for nearly every DBMS, comes in many subtly different "flavors" depending on the database being queried. However, the details of these differences are not a concern when using the ArcMap application in ArcGIS Desktop. The software detects the characteristics of the underlying database being queried and modifies the interface so SQL statements will be created using the appropriate search terms and information. The user is not required to understand the SQL format for the specific database being queried. There are two types of queries: attribute and location. Attribute queries ask for information from the tables associated with features or from stand alone tables associated with the GIS. Attributes can be numeric values, text strings, Boolean values (i.e., true or false), or dates. This kind of query is similar to a query made to any database; however, when using a GIS, the answers (i.e., the features related to the records selected by the process) are highlighted on the map as well as in the table. The answers to spatial queries are derived directly from the location of features on a map. Information about the proximity of one parcel to other parcels or other kinds of features, such as roads, is not contained in an attribute table but is easily learned using a spatial query. For example, you could ask if one or more features are located within a certain distance of other features, are contained by another feature, intersect other features, or possess another of the relationships defined by spatial operators. GIS is powerful because it can use both attribute and spatial queries to get answers with far less effort or answer questions that would not be practical to answer using any other method.
The Select by Attributes dialog box in ArcMap helps build queries by presenting the values and SQL operators available in the underlying database. This query uses LIKE to capture all the records with an OWNER_NAME that contains the string `CHAVEZ'. Building a Basic Query All basic queries have three parts: a source, a filter, and a relationship. This is true of both attribute and spatial queries. The source can be a table or feature class. The filter can be an attribute value or a shape or feature. The relationship between the source and the filter is based on logical, comparison, or spatial operators. When creating a query, identify which table or feature class will contain the information that answers your question. If the question is, What parcels have a specific commercial zoning? an attribute table for parcel features that contains a field for zoning would likely be a source. The filter identifies what is different about the desired items, whether those items are table records or features. In the commercial zoning example, that characteristic would be the code C-3, which identifies the commercial zone of interest. The relationship between the source and filter does the work of finding the record or features. Continuing with the example, the relationship would be that the zoning field contains the value C-3 so the relationship would be "equals" or =. Relationships are defined using operators. Comparison and logical operators are applied to attribute queries. Comparison operators include =, <>, >, >=, <, and <=. LIKE, AND, OR, and NOT are logical operators. In contrast to the relatively short list of operators for attribute queries, there are more than a dozen types of spatial operators. Intersect, Are Within a Distance Of, Contain, and Are Contained By are some of the most common and useful ones. Spatial queries performed using Select by Location deal with vector data and use a shape as a filter and its relationship with features in the source layer to answer a question.
www.esri.com
56 ArcUser Spring 2009