Join the tables

advertisement
LAB 5 -- WORKING WITH TABLES
In this lab we will be working with attribute tables. For part 1, you will use the
California project in your student files. For part 2, you will use a dataset that examines
Grizzly Bear habitat in the northwestern continental US.
Part I
We will start Part I by opening the groundwater basins file you created for the query lab
in ArcMap. Next, download the files for lab 5. In it you will find a table called
basins.dbf. Add this to your table of contents—using ArcCatalog you can drag and drop
it into the table of contents. The basins.dbf file is a table which contains the ID number
for each of the groundwater basins on last class’ map. It also has a field that contains the
name of each of the basins.
Let’s create a field in the groundwater basins attribute table which shows the area of each
basin in acres.
Begin by opening the project you created in your Query lab that shows the groundwater
basins of California. Open the attribute table for the groundwater basins theme. Under
the Options pulldown menu choose “Add Field”.
The Add field dialog box appears. We want to name the new field acres. It will be a
Double with a precision of 20 (maximum number of digits) with a scale of 2 decimal
places.
Click OK. The new field is added as the final field in the table. Now we want to fill the
new field with values that indicate the area of each basin in square miles. To do this we
will use the field calculator.
To edit a table, go to the editor toolbar dropdown menu and choose “Start Editing” (Note:
if the Editor toolbar is not visible, go to the View menu and click on Toolbars and select
the Editor toolbar so that it has a check in front of it)
A small yellow pencil appears at the bottom of the table.
Now right click on the header box for your new field in the attribute table and, from the
drop down menu, select “Field calculator”.
We will use the field calculator to convert the numbers in the “area_sq_mi” field to acres
and fill our new field with these values. Develop a mathematical equation to convert
square miles to acres (there are 43, 560 square feet in an acre).
Double click on the area_sq_mi field to enter it into the “acres =’ field in the lower part
of the calculator. Single click the operator (‘+’, ‘-‘, ‘*’, ‘/’) and type in the number(s)
you will use to convert sq. miles to acres.
Click OK. The new field will fill with values. Each value is the approximate area in
square miles.
Now, from the Editor toolbar, choose Stop Editing from the dropdown menu. Click Yes
to save your edits. Now you could perform queries that will highlight (for example) all
groundwater basins larger than 10000 acres!
But the table is still ugly. It has a lot of fields that seem meaningless. We can hide these
fields. Open the Layer Properties dialog box for the Groundwater basins layer and select
the Fields tab. If you click on each field title, will see each field listed along with a check
mark in a box labeled Visible.
The check mark indicates that the field is visible. We want to hide all but the following
fields: Kbge_id, Unit, Rockdesc, Area_sq_mi and our new acres field. Do this by
selecting each of the other fields and removing the check mark next in the visible box.
You are not deleting the fields only making them invisible (you can make them visible
again by rechecking the Visible box. Click OK. Note how the appearance of your table
has changed!
Save a copy of the table to hand in.
However, we would still like to know what the name of each basin is. To do this we will
join the Basins.dbf table to the attribute table for the groundwater basins theme. This
table contains names for most of the groundwater basins. First add the Basins.dbf table
to ArcMap using ArcCatalog (drag and drop) or the Add Data button in ArcMap. It
should show up at the bottom of the table of contents. Right click on the basins.dbf table
and select Open from the dropdown menu. Also open the attribute table for the
Groundwater basins layer. Move the tables so that you can see them both at the same
time. We want to examine the tables.
Do you see a common field that we can use for the join (remember that the name of the
field does not have to be the same in both tables for the field to act as a common field)?
Also notice that there are 73 records in each table—this suggests that there is probably a
one-to-one relationship between the tables (then again, you should always check).
Join the tables
Right click on the groundwater basins layer and select Joins and relates from the
dropdown menu. Select Join (since we have a one-to-one relationship).
You get the Join data dialog box. In the “What do you want to join to this layer?” box,
select “Join attributes from a table”. In the drop down boxes below, first select the field
in the Groundwater basins table that will be used as a common field for the join. In the
next box, select the table you will join to the attribute table of the groundwater basins
layer (in this case, basins.dbf). Finally, choose the field in common from the basins.dbf
table. The dialog box should look like this:
Click OK (if it asks you to create an index, say OK). Examine the attribute table for the
ground water basins layer.
The table should contain a field called Names that lists the name of each groundwater
basin. Right click the name of the groundwater basins layer in the Table of Contents and
select Joins and Relates > Remove joins and notice that BASINS appears in the drop
down menu. (DO NOT REMOVE THE JOIN—just back out. I only wanted you to see
how you would tell if a table had a Join).
You can now label the groundwater basins with their names. Open the Properties dialog
box for the groundwater basins layer. Select the Labels tab. In the Label Field drop
down menu select NAME. Close the Properties dialog box. Then right click the
groundwater basins layer in the Table of Contents and select Label Features.
This is a good time to print out a copy of your labeled map to turn in for lab.
We joined the attribute table for groundwater basins and the Basins.dbf file because they
had a one-to-one relationship. But what if we have a pair of tables with a one-to-many
relationship? In this case, the tables must be related. We are going to relate the
california_counties attribute table to a table called rec.dbf. The rec.dbf table is available
on the website (Lab 5 folder). Make a new map and add the California_counties layer.
Open the attribute table for California counties layer and then add the rec.dbf table to
your map and open it. Position the 2 tables so that you can view them side by side. The
rec.dbf table contains a list of recreation areas in California. It includes a field with the
county names, however, most of the counties contain more than one recreation area.
Therefore, this is not a one-to-one relationship but a one (counties layer) to many
(recreation areas layer) relationship. We will have to relate the tables. We also see that
there is a field we can use as a common field for the relate—the NAME field in the
counties layer and the CNTY_NAME field in rec.dbf.
Right click on the counties layer and choose Joins and Relates, then click Relates.
The Relate dialog box appears. In box no. 1, we have to choose the field in the
CA_counties layer that the relate will be based upon. Scroll down and choose name (the
fields are listed alphabetically). In box no. 2, we need to specify the table we wish to
relate to the counties layer. Select rec.dbf. Now, in box no. 3, tell the program which
field of rec.dbf is the common field to use in relating to NAME in the counties layer.
Choose CNTY_NAME. Finally, in box no. 4, give the table a name. I called mine
CA_rec_areas_relate.
Click OK. Nothing impressive appears to happen.
Now open the counties attribute table and select the record for Kern County by clicking
the gray box to the left of the record for Kern County. It should highlight in blue.
Next, click the Options menu at the bottom of the table. Click Related tables, then click
CA-rec_areas relate:REC.
See the new table appear. Now, on the new table, right click on the CNTY_NAME field
header and select “Sort Ascending” to put the counties in alphabetical order. Scroll down
to Kern (it will be highlighted in blue). How many recreation areas are listed for Kern
County? What are they?
Part II
GRIZZLY BEAR HABITAT LAB
Open ArcCatalog and navigate to the Wildlife folder contained in the lab 5 folder. Open
the wildlife folder. Notice the data types (formats) contained in this folder.
Youo will find one or more non-spatial tables ( Type = dBASE). Of course, the
Grizzlies_no_1 is an ArcMap document and the last three on the list are shapefiles. In
between are some new formats you have not encountered yet. The icon that looks like
three yellow squares indicates an ArcInfo coverage. These can contain either polygon,
line or point features. Expand one in the ArcCatlog Table of Contents and select the
point, line or polygon file. Now select the Preview tab in the window to the right of the
Table of Contents to see what the features look like.
The three icons that look like grids are raster data—in this case photographs of grizzly
bears. Go ahead and preview them in ArcCatalog to see what they look like. Close
ArcCatalog.
A century and a half ago, nearly one hundred thousand grizzly bears roamed the
mountains and plains of the western United States. Today, fewer than a thousand remain.
The grizzly bear, Ursus arctos, is listed as a threatened species under the U.S.
Endangered Species Act, requiring that the federal government restore the bear's
population to a level that removes them from the threat of extinction. To do this, the U.S.
Fish and Wildlife Service has designated five recovery zones in the Northern Rockies of
Wyoming, Montana, Idaho, and northeastern Washington. A sixth is being considered in
the central Idaho-Bitterroot area. How to manage the land and increase bear numbers is
very controversial, and is the subject of dozens of court cases and legal appeals.
You will use ArcGIS to study the distribution of bears in the Northern Rockies. You will
examine the designated recovery zones, analyze the spatial relationships between
recovery zones and bear sightings, then examine bear sightings and habitat loss in a
single recovery zone over time. You might not become a grizzly bear expert, but you will
become familiar with several GIS techniques for managing wildlife.
In this exercise you will work with the attributes of grizzly bear recovery zones to learn
more about their characteristics. You will add acreage information for the recovery zones
by adding a new field, then calculating its values. You will add a table containing bear
counts and join it to the existing attribute table. Finally, you will make a dot density map
to show the relative number of bears in each recovery zone. I’ve found that this is a
really good exercise for familiarizing you with tables!
You will start by creating a new field for the acreage in each recovery zone. First open
the Grizzlies_no_1.mxd map in the Lab 5 folder. Be sure that the dataframe called
Grizzly bear recovery areas is the one shown in the map window (right click on the
dataframe layer and select Activate). Open the attribute table for the Grizzly Bear
recovery zones layer. From the Options menu at the bottom of the table, select Add
Field. The name for the field should be Acres and the type should be Float. Set the
number of digits (precision) to 12 and the number of decimal places (scale) to 2. Click
OK—you get a new field filled with zeros. Note: If you make a mistake, delete the field
and start again; you cannot edit the field definition within ArcGIS. To delete the field,
choose Stop Editing, then right click on the field header and choose Delete Field from the
pulldown menu.
Now we have to fill the new field with values.
Choose start Editing from the Editor pulldown menu. (Note, you can add data to a field
without going to Start Editing but, if you make a mistake, you won’t be able to change it
and will have to start over by deleting the field and re-adding it!).Notice that the field
headers for the editable fields turn from lt. gray to white (it’s subtle) when you are in edit
mode.
Calculate the Acreage in Each Recovery Zone.
Right click on the header for the acres field and select Field Calculator from the drop
down menu. The Field Calculator appears. The dialog box shows the first part of a
mathematical expression [Acres =]. Double-click on [Area] in the Fields list and the "*"
button (for multiplication) then type 0.0002471. (Be sure to add the "0" before the
decimal point, otherwise the calculation will not work.) This number is the conversion
factor for changing square meters (the values in the Area field) to acres. The Area field is
in square meters because of the projection the data is in (Albers Equal Area with map
units in meters). Click OK. ArcMap performs the calculation on each record and places
the result in the Acres field. Go to the Editor toolbar’s dropdown menu and choose Stop
Editing to save your edits.
Sort the Acres Field Values
Once the Acres field is populated with values, right click on the acres field header and
select Sort Descending to sort the recovery zones from largest to smallest. If the
calculation worked correctly, the table shows Greater Yellowstone as the largest recovery
zone, with 5,937,000 acres.
Statistically Analyze the Acres Field
Again, right click on the acres field header and select Statistics from the pulldown menu
to see the sum of the acres in the recovery zones. For an animal that used to roam the
entire western United States, 17.5 million acres is a small area in which to be confined!
Add the Table Griznum.dbf
Next you will look at the distribution of grizzly bears by recovery zone. Close the
Statistics window. From the ArcMap toolbar, click the Add Data icon, and select the
table, griznum.dbf, from the wildlife directory. (Of course you can also drag and drop it
in from Arc Catalog.). Open the griznum.dbf table and move it so that you can view both
it and the Grizzly Bear Recovery Zones attribute table.
The griznum.dbf table contains the estimated number of bears in each recovery zone.
Obtaining actual counts of grizzly bears presents special problems, not the least of which
is tracking one of North America's most secretive carnivores across remote mountainous
terrain. Note that grizzlies are numerous only in the larger recovery zones, the Northern
Continental Divide and the Greater Yellowstone. Grizzlies are not currently found in the
Bitterroot Mountains-Central Idaho area, where they were exterminated in the late 1950s.
The U.S. Fish and Wildlife Service is considering reintroducing them there.
Join the Tables
Notice that both tables contain a "Zone_name" field with similar values. The tables have
a one-to-one relationship. You will join the two tables using the Zone_name field as the
common field. Close the tables.
Right click on the Grizzly Bear Recovery zone layer in the table of contents and select
Joins and Relates > Join. The Join data dialog box appears. We want to Join attributes
from a table. In box no. 1 we will use the ZONE_NAME field from the recovery zones
table as our common field. In box no. 2, select the griznum.dbf table as the table to join
to this layer. In box no. 3 we will use the ZONE_NAME field of th griznum table as our
common field.
Click OK and watch the tables disappear. Now, when you open the attributes table for
the recovery zones layer, the table headers will be labeled as LAYER_NAME.FIELD
_HEADER indicating that the table is joined to another. You can tell what data came
from which table by looking at the field header names to see what layer is listed.
Calculate Bear Density
To get an idea of bear density, add a new field called "Acres_per " (for acres/bear—
acres_per_bear is too long and it won’t let you use the “/” sign! Be sure to use the
underline between words—when I didn’t do this, I crashed ArcMap and had to start all
over again—a good reason to save you work periodically!!!!!), and make it a Float field
with a precision of 12 characters wide with a scale of two decimal places.
Once you have added the new field, Select Start Editing from the Editor toolbar and right
click on the new field header to select Calculate Values. In the Field Calculator dialog
box, the expression starts with [Acres per bear] =. Double-click GRIZONE.Acres in the
Fields list, "/" for the operator, and double click GRIZNUM.Estimated (number of bears)
in the Fields list. Your field calculator should look like this:
Click OK. ArcGIS calculates the number of acres per bear for each zone and places these
values in the "Acres_per" field. If the calculation works correctly, Northern Continental
Divide should appear as the most densely populated recovery zone, as it has the smallest
area, 12,701 acres, for each bear.
Click Stop Editing on the editor toolbar and open the Properties dialog box for the
Grizzly Recovery Zone layer. Click on the Symbology tab and choose Quantities > Dot
Density. In the Field Selection Window choose ESTIMATED and click the ‘>’ arrow to
move it into the right hand window. I also had to change the background color so that the
recovery areas stood out against the backdrop of the northern Rocky Mountain states.
Now click OK. The dot density map draws slowly. Now, while getting ready to turn in
your map, label all the recovery zones with their zone names (i.e.Bitterroot Mountains,
etc.). Alternatively, you could also try labeling the recovery zones with the estimated
number of bears. (Note: to move the labels around, you first have to convert them to
annotation. Do this by right-clicking on the layer name and selecting “convert labels to
annotation”. I did not have a .prj file for this dataset. If it asks for units, right click on
the dataframe title (not the Layer) to bring up the dataframe properties dialog box. Click
on the General tab and change the Map and display units to meters and click OK. This
should allow you to convert the labels to annotation)
This is a good time save a copy of the map to turn in.
Now you will take a closer look at the Cabinet-Yaak grizzly recovery zone in
northwestern Montana and extreme northern Idaho. One way to evaluate whether a
recovery zone is effective is to determine the land use trends over time. This exercise
examines roadless areas in the recovery zone over three time periods. In the next lab, you
will use these same time periods to determine the relationship between grizzly bear
sightings and roadless areas.
The Cabinet-Yaak area will be used for two reasons. Unlike some of the other recovery
zones, the Cabinet-Yaak area has a unique record of grizzly sightings going back to the
early 1960s. Also, by examining historic forest service maps, you can see how much
wild, roadless public land there was at a given time. With these two pieces of
information, you can study land use trends and their relationship to grizzly bear sightings.
In the map window, open the Cabinet-Yaak Recovery Zone dataframe. You see three
similar themes representing northwest Montana public wildlands for three different years:
1940, 1975, and 1995.
Tip: To widen the table of contents, place the cursor on its right border until it changes to
a double-headed arrow. Then hold down the mouse button and drag to the right. Release
the mouse button.
You will start by symbolizing these three themes.
Open the Layer Properties dialog box for MT Wildlands in 1940 and select the
symbology tab. From the Show: window, choose Unique Values. In the Values Field,
choose Type and click on “Add all Values”. Look at the legend type and you’ll see a
value for W and one for r. "W" stands for Wilderness areas and "r" for roadless areas
(unprotected wildlands open to roading, logging, and mining). (Note: you may also see
an “S” field—for now, just delete the label in the symbology tab and choose an
“invisible” color for it so that it doesn’t show up).
Change the labels by clicking each entry under the Labels column and typing the
appropriate label into the Labels field (do NOT change the entry in the Values field of the
Legend Editor!). If desired, change the symbol colors by double-clicking each symbol
and choosing the Color Palette. Uncheck the box next to “All other values” so we won’t
have to look at it in the table of contents.
Do the same for the 1975 and 1995 wildland areas.
Create a Table to Store Analysis Results
New tables are created in ArcCatalog. Open ArcCatalog and right click on the folder you
want to create the new table in (Wildlife in this case). Select New > dBASE Table.
Change the table’s name to wildnums. Now drag it into the Table of Contents in
MapView.
Add Fields to the Table
Open the table by right clicking on it in the Table of Contents and bring up the Editor
toolbar (if it is not already open) but do NOT start editing yet. From the Options
pulldown menu at the bottom of the table, choose Add Field. Call the first new field
"Time" and make it a Text field 16 characters wide. Now right click on the header called
Field 1 and select Remove from the dropdown menu.
Create three more new fields (all of which will be Short Integer fields, 16 digits wide
with no decimal places). Name them "wild_acres", "Rdls_Site", and "NRdls_Site".
Add Records and Values to the Table
Start an Editing session. In the Time Period field, type 1940 and press Enter. A new
record appears. Click in the cell of the new record in the Time Period field and type 1975
<Enter>. Do the same to type in 1995. Press Enter after your last entry. Stop editing
and save your edits.
Save a copy of the screen showing your new table and the edits you’ve performed.
Save the project. We will use it again in the next lab.
Download