6.1 How Can Data Be Retrieved From a GIS for Analysis?

query the conditions used to retrieve data from a database

One type of analysis is to find which areas or locations meet particular criteria—for instance, to take a map of U.S. Congressional Districts and identify which districts have a Democratic representative and which have a Republican representative. Alternatively, you might have a map of all residential parcels, and you might want to be able to see which houses have been sold in the last month. In both of these examples, you would perform a database query to select only those records from the attribute table (see Chapter 5) that reflect the qualities of the objects you want to work with.

In other cases, before beginning the analysis, you might only want to utilize a subset of your GIS data. For instance, rather than dealing with all Congressional Districts in the entire United States, you might want to examine only those in Ohio. Or in the housing example, if you have a dataset of all residential parcels in a county (which is likely thousands of parcels), you might only want to do analysis related to one (or a handful) of the parcels, rather than examining all of them. You’d want to go into the dataset and select only those parcels required for your study. Again, in these cases, the query would only select the records you want to deal with.

160

SQL the Structured Query Language—a formal setup for building queries

In GIS, queries are composed in the Structured Query Language (SQL) format, like a mathematical function. SQL is a specific format that is used for querying a layer or database to find what attributes meet certain conditions. For example, a layer made up of points representing cities in Ohio also has a number of fields representing its attributes, such as city name, population, and average income. If you just wanted to do analysis with one of these records (the city called “Boardman,” let’s say), then a query could be built to find all records where the field called CITY_NAME contained the characters of ‘Boardman’ as: CITY_NAME = ‘Boardman’. This should return one record for you to use in your analysis. Another example would be to select all cities in Ohio with a population greater than or equal to 50,000 persons. The attribute table has a field called POP2010 (representing the 2010 city population) that contains this information. Thus, a query of POP2010 >= 50000 could be built, and all records with a population field containing a value of greater than or equal to the number 50,000 would be selected for your use (see Figure 6.2 for an example of a query in GIS).

FIGURE 6.2 A database query for Ohio cities returning multiple records (selected records and their corresponding cities are in cyan).(Source: Esri)

relational operator one of the six connectors (=, < >, <, >, >=, or =<) used to build a query

A query will use one of the following relational operators:

compound query a query that contains more than one operator

Boolean operator one of the four connectors (AND, OR, NOT, XOR) used in building a compound query

AND the Boolean operation that corresponds with an Intersection operation

intersection the operation wherein the chosen features are those that meet both criteria in the query

OR the Boolean operator that corresponds with a Union operation

union the operation wherein the chosen features are all that meet the first criterion as well as all that meet the second criterion in the query

NOT the Boolean operator that corresponds with a Negation operation

negation the operation wherein the chosen features are those that meet all of the first criteria and none of the second criteria (including where the two criteria overlap) in the query

XOR the Boolean operator that corresponds with an Exclusive Or operation

exclusive or the operation wherein the chosen features are all of those that meet the first criterion as well as all of those that meet the second criterion, except for the features that have both criteria in common in the query

While a simple query only uses one operator and one field, a compound query enables you to make selections using multiple criteria. There are different ways of linking multiple criteria together for creating one of these compound queries, each using a different option of querying (referred to as a Boolean operator):

162

Compound queries can use multiple operations to select multiple records by adhering to an order of operations, such as: (POP2010>=50000 AND AVERAGEHI > 30000) OR CITY_NAME = ‘Boardman’. This will select cities that meet both the population and the income requirement, and would select cities named ‘Boardman’ as well. The result of a query will be a subset of the records that are chosen, and then those records can be used for analysis, rather than the whole data layer. Selected records can also be exported to their own dataset. For instance, the results of the previous query could be extracted to compose a new GIS layer, made up of only those records (and their corresponding spatial objects) that meet the query’s criteria. Once you have your selected records or new feature layers, you can start to work with them in GIS (see Hands-on Application 6.1: Building SQL Queries in GIS for an example of doing queries with online GIS utility).

!geo! HANDS-ON APPLICATION 6.1

Building SQL Queries in GIS

Durham, North Carolina, has an online GIS Spatial Data Explorer utility that allows the user to do a variety of spatial analyses with the city’s data, including performing queries. To work with this tool, open your Web browser and go to http://gisweb.durhamnc.gov/gomaps/map/index.cfm. In the upper left-hand corner there are several tools (such as zooming and panning) to get oriented to the GIS data. The tool with the hammer icon allows you to build SQL queries of the data. Click on this icon and a new set of options will appear on the right—these will allow you to construct simple queries of the GIS. First, select an available layer (for instance, select 2000 Census Block Groups). Second, select an attribute to query (for instance, choose “Housing Units”). Third, select an operator (for instance, choose the greater than “>” symbol). Click on the “add to query” button and you’ll see the SQL statement appear. To finish the query, type a value (for instance, type 1000), and press the “Send the Query” button. All records meeting your query will be retrieved (in this case, all Census block groups with more than 1000 housing units in them). The selected block groups will be highlighted on the map, while the records (and the attributes that go along with them) will be displayed in a spreadsheet at the bottom of the screen. Investigate some of the other available data layers and the types of queries that can be built with them.

Expansion Questions:

  • Question

    yL81qXWQZ18UEpBaJH/eMQdQRf6zbW/bj6+fBGNnVaGfMogriV9lqOc36ku9jwVmFuGq6c38Fx0noW++d/HhhN/Mp5UGy/aEPGNl8Y0kGsjbZUYsRNlOAmAhxcc=
  • Question

    eWjBQwMv6wB373seUb5YoBzTQWhtd94GmOnDj9izQwC0ck46T1CKg8jOg7/SJbAiTHeafUNEO95kOimrK53MduLeK5Ihgja98f+dSzP3/OP0nc7vmfoOkO/yDZsP6AwS4JTWVw==
  • Question

    eDyyqk0tv8JxUXz5D2xKjjBeR7e0+P6Ow3Yd0h4vfM+/1pOxEFKjrV+gTYf/WGDmdclTuurlOLAelpVLYaKPm6WSb0bWgaRvVLkmj3r09HA5/HdbVqu0qLhGN+4M3UPxcfgZueE092gAfEgzsHUO0QVwYcCe6zAjlY1/PEEn8UYqq8qFOcjN4xk15dmHOypWv+BnZOLgGy0kEASgqz8D2c1x2KqLV3szWmHtokbk88Rved0Qrn3QQfHz9iU=

163