We are going to Query our data, that is, let you select features in a View and records in a table that meet the criteria you specify in an equation, which is in the form of a logical statement. Querying is used to examine relationships between variables and finding locations that meet certain criteria. This will demonstrate how GIS incorporates several themes in analyses to help solve real world problems.
Return to our View1.
Uncheck the boxes next to all the themes. Display only the theme "Shambas.shp." (This theme has information about parcels with crops. If you deleted this theme before, add it again to our Table of Contents.) Also, drag the theme name "Shambas.shp" to the top of the Table of Contents. Make "Shambas.shp" active and zoom to the active theme.Create a map of "Shambas.shp" with a "Unique Value" legend type using the field "Maincrops." This field has information about the major crops planted in a parcel of land.

As the map legend in the Table of Contents indicates, there are four different types of main crops, with "bean-maize" being the most frequently found.
Change the name of the theme to reflect the current map. Remember that you need to click on the Theme Properties button in the top row of buttons at the top of the screen to open the Theme Properties dialog box to change the theme name.

Change the name of the theme in the Table of Contents from "Shambas.shp" to "Main Crops."

We are concerned with explaining the distribution of a pest in beans--the bean fly. In particular, we want to know what types of conditions are most likely associated with bean fly populations of greater than 100 in a parcel of land.
We want to know if an important cause of high bean fly populations (greater than 100) is the nature of the crops grown in a parcel of land. That is, are bean fly populations of greater than 100 found when beans are intercropped with bananas or when beans are planted with maize?
To answer this question we can query the data in the Query Builder. That is, we can create a logical expression to tell ArcView to only display in our map parcels of land with bean fly populations of greater than 100. In essence, we create a "filter."
Click on the Theme Properties button again to bring up the Theme Properties dialog box.

NOTE: If anything appears in the large box in the middle of the dialog box below the Clear button on the right, you need to remove it first by clicking on the Clear button.
Now click on the Query Builder button in the dialog box, which
has a hammer and "?" in it
,
which brings up the Query Builder dialog box.

What does the Query Builder do? It allows us to create an equation to examine a particular variable (or field) in a theme, such as "Beanflynum" (the number of bean flies we have caught in our pest traps in each parcel of land), showing on the map only those parcels that meet our criterion. Any parcels that do not meet our criterion will not be displayed on the map.
We will create an equation to ask the Query Builder to display only those parcels with bean fly populations of greater than 100. Because we are already displaying information on the main crops, we can then examine those parcels still displayed after using the Query Builder to see what types of crop combinations in parcels remain on our map.Let us examine the "Query Builder" dialog box. In the upper left is a list of the different "Fields" or variables for our active theme that we can select. In the center are numerous buttons with mathematical operators, such as "less than," "equal to," "greater than or equal to," etc. In the upper right, all the unique "Values" for a selected "field" (variable) will be listed. In the bottom left of the dialog box is the "equation box" where we will create an equation to specify what we want the map to display. Right now only a left and right parenthesis sign are there.
It is crucial that you adhere to the following steps precisely or you will create an equation with an invalid syntax. If you create an invalid expression, ArcView will not be able to perform the desired task.
Basically, a query takes the format in the following example:
( [area] = 1500 ).
That is, the entire query is enclosed in parentheses, the field name appears first, always enclosed in square brackets, followed by a mathematical operator, and then the value that you specify.(A "value" can be a category such as "yes" or "no," "crop type," etc., or a number such as "15200", etc.) In the above equation, you are telling ArcView to display only those areas that have values equal to 1500. (Note: queries can, in fact, be much longer and much more complex.)
First, from the list of "Fields" select "[Beanflynum]". (Sometimes you have to scroll down to find a field.) This field contains the data on the number of bean flies we have caught in our pest traps in each parcel.
Double click on [Beanflynum] and it will appear in the "equation box" in between the left and right parenthesis signs. Note also that in the "Values" list on the right of the dialog box, all the values for [Beanflynum] for the parcels have just appeared. (Note: when the value "-99" appears, it means that no data are available for a particular feature in a field.)

Then click on the "greater than" button
in the upper middle of the dialog box
and the specified operator will also appear in the equation box below to
the right of [Beanflynum].

Now we have to add in the value that we want for the bean fly population into the equation box. In the "Values" section on the right of the dialog box, scroll down to find a number that we can use that will have the effect of displaying parcels with bean fly populations of greater than 100. Note that there is no value of 100 in the "Values" section. But we could use the value of "94" for our equation because if we tell ArcView to display parcels with pest populations of greater that 94, ArcView in this case will display parcels with pest populations of greater than 100 because the next highest pest population value after 94 is 112.
Thus, in the list below the category "Values" in the upper right of the Query Builder dialog box, double-click on "94" which will now appear in the equation box.
(Note: you can also type the value directly into the equation box instead of double-clicking on it, but we will not do that here.)
Make sure that your equation is exactly the same as this one. Now click on the OK button and the query builder equation that we created will appear in the Theme Properties dialog box.

If your equation is correct, click on the OK button. (If your equation is incorrect, click on the Clear button to erase your equation and start over by clicking on the "Query Builder" button again and going back to the Query Builder dialog box to create a new equation.)
Now our map will be redrawn so that only parcels meeting our criterion of having bean fly populations of greater than 100 will be displayed; the other parcels with smaller pest populations will not be displayed. Because we previously classified parcels according to their main crop combinations, we can visually examine those remaining to answer our question.

It appears that we do not have a conclusive answer from our query. High bean fly populations are found in both crop combinations. There are eleven parcels with "bean-banana" and nine parcels with "bean-maize."
Thus, crop combination alone does not help to explain high pest incidence.
But in a GIS, we do not stop here. Rather, we can ask additional questions to find relevant spatial patterns in relation to our query. One of the benefits of ArcView is that it allows you to examine the spatial patterns of more than one variable at a time. Let us suppose that based on our review of the literature, we also want to explore whether soil type plays a role in influencing the spatial distribution of high bean fly populations.We can display our map of soil types beneath our current queried theme to examine if soil type influences the distribution of high pest populations. Display the theme "Uga_soil.shp" and create a unique value legend map of the field "Type."

Does soil type appear to influence high pest incidence? If so, which soil types are associated with high bean fly incidence?
If soil type is associated with high pest populations, there are other related factors that may be important to consider, such as drainage or moisture. Here we will examine the influence of proximity to rivers, which is relevant to moisture conditions.
Drag the theme "Iganga-river_50000.shp" to the top of the Table of Contents. Display the theme in our View.
We can see the importance of proximity to rivers as an influence on high bean fly populations. But its importance appears particularly significant in relation to high bean fly populations in bean-maize parcels. While parcels with bean-maize have high bean fly populations only near rivers, those with bean-bananas have high incidence elsewhere.
We can thus see how visually examining spatial patterns revealed in a GIS helps to illuminate significant influences.
Here we combined querying the data with theme overlays to explore our question. Such perspectives gained from a visual analysis of spatial patterns are not often possible from statistical analyses alone.They also help to generate new hypotheses for further testing in research.
Note that we can have numerous types of queries. For example, we could create queries that display: only parcels of a certain size, cropping density, or fallow period; households of a certain type (for example, based on a certain income level or gender of household head); livestock found below a specified elevation; or parcels where particular IPM strategies are employed. We want to remove the query equation so that all our parcels reappear on the map.First, make sure that the theme "Main Crops" is active.
To remove the changes that we made to the map, simply bring up the Theme Properties dialog box again, click on the Clear button to delete the equation that we created, and then click on the OK button. Our original map is redrawn.When we created our query, we used a simple query with one criterion and a numerical value as the criterion. You can also use categories as the criteria and also create more complex queries.
Let us say that we have a research project focusing on bananas in agriculture. We are interested in examining how high rates of soil drainage affect banana production. Thus, we are only concerned with parcels that meet our research interests.
We want to display a map that contains only parcels with bananas and a high rate ("H") of soil drainage. We want to include parcels that have as their main crops both "bananas" and "beans-bananas," because both types of parcels have bananas. Uncheck the boxes next to the themes "Uga_soil.shp" and "Iganga-river_50000.shp" in the Table of Contents so that they are no longer displayed in our map. Change "Uga_soil.shp" to a "Single Symbol" legend type so that it takes up less space in our Table of Contents. Make sure that the theme "Main Crops" is active. Open up the Theme Properties dialog box and then open the Query Builder dialog box. Under the "Fields" section, double-click on [Maincrops], then click on the "equal to"
sign, and then in the "Values" section double-click on "Banana." Your dialog box should look like this:

So far, our equation tells ArcView to display only parcels with "bananas" as the main crop. But we need to tell ArcView to also display parcels with the main crops "beans-bananas."
To create this more complex query, click on the operator "or"
button in the upper middle of the Query Builder dialog box.

Note also that there are parentheses to the right of this operator. Here we can insert another query.
Under the "Fields" section, double-click on [Maincrops] again, then click on the "equal to"
sign, and then in the "Values" section double-click on "Bean-Banana." Your dialog box should look like this:

Now we are telling ArcView to display both types of parcels.
But we also have one more criterion--high rate of soil drainage.
To add this additional query, click on the operator "and"
button in the upper middle of the Query Builder dialog box. It appears to the right of our complex equation.

Note again that there are parentheses to the right of this new operator. Here we can insert another query.
Under the "Fields" section, double-click on [Drainage], then click on the "equal to"
sign, and then in the "Values" section double-click on "H" (for high rate of drainage). Your dialog box should look like this:

Click on the OK button to close the Query Builder dialog box. Then, if the equation appears correct in the Theme Properties dialog box, click on the OK button to close the Theme Properties dialog box.
Your map should look like this, displaying only parcels with either "Banana" or "Bean-Banana" and having soils with a high rate of drainage.

You now know the location of such parcels. You could also examine their characteristics in relation to other themes, as we have done previously. We can thus create more complex queries. For example, we could tell ArcView to display only parcels owned by female-headed households and whose female owners adopted a particular IPM package and did not own more than one acre of land. We could then examine a variety of characteristics of these plots and compare such characteristics to those of other queries that we create. Before going on to the next Step, remove the query so that all parcels are displayed in our map. (Click on the Clear button in the Theme Properties dialog box and then click on the OK button.)