You are on page 1of 19

Practical Exercise 4

Databases and Attributes

Department of Physical Geography and Ecosystems


Analysis, and GIS Centre at Lund University, Sweden

Introduction to Geographical Information Systems

GISA01
Databases and Attributes

4 Databases and Attributes

4.1. Purpose
The aim of this exercise is to provide you with an introduction to databases and how to
handle and query attributes in ArcGIS. More specifically, you will learn the following:
- How to add data to an already existing attribute table.
- How to import data from Excel.
- How to join two tables together.
- How to convert fields containing coordinates to a shapefile
- How to structure simple SQL-queries.

4.2. Data
In Moodle, you can find a zip-file with the name DATA4_Databases. Download and save
the file to your computer and use WinZip to unzip the files. The unzipped file contain the
following data:
Srilanka Shapefile: .shp, .dbf, .sbn, .sbx, .shx.
Gamdiv Shapefile: .shp, .dbf, .sbn, .sbx, .shx.
Ham_districts Shapefile: .shp, .dbf, .sbn, .sbx, .shx.
Hambantota_wind Excel file: .xls.
Gampop94-97 Excel file: .xls.
Un_employ dBase: .dbf.
Create a folder in your local working directory with the name 4_Databases (e.g.
C:\GISA01\Practical\4_Databases). It is recommended that you keep an organized file
structure on your computer.

4.3. Answers to be sent to teachers


All students have to send in one document containing two maps and the answers for
questions 4.1 4.3 by email to the teachers as indicated in the document Sending

14-01-2010 Copyright 2010. Lund University GIS Centre. All rights reserved. 1
Databases and Attributes

Answers to Teachers available in the section Course Information on the course


homepage.

4.4. Method

4.4.1. Exploring and viewing the data


- Start ArcCatalog and navigate to or create a folder connection to the folder
containing the data for this exercise.
- Explore the data for this exercise by using the Preview and Metadata tabs.
When looking at shapefiles, both the map and the attribute table can be previewed. In the
display window there is a dropdown list Preview at the bottom where the preview can be
altered between Geography and Table.

- Start ArcMap in ArcCatalog by clicking in the Standard toolbar. Choose to


open A new empty map.
- Save your empty map document (File > Save as) as sri_lanka_attributes
together with the other data for this exercise.
- Add the shapefile Srilanka by clicking . Ignore the message notifying you
that the layer is missing spatial reference information by simply clicking Ok.
- Close ArcCatalog.

14-01-2010 Copyright 2010. Lund University GIS Centre. All rights reserved. 2
Databases and Attributes

4.4.2. Adding data to an attribute table


You often need to add new attribute data or tables to a map. In ArcGIS, this is easily
accomplished either by importing an existing table saved as .txt, .xls or .dbf, or by typing in
new data in the table itself. You will do both in this exercise.
At your disposal, you have the following data on the average monthly income for a couple of
districts in Sri Lanka that you would like to thematically visualize.

District Average monthly District Average monthly


income income
Anuradhapura 1451 Kurunegala 1789

Badulla 1371 Matale 1673

Colombo 2904 Matara 1495

Galle 1756 Monaragala 1915

Gampaha 2189 Nuwaraeliya 1271

Hambantota 1218 Polonnaruwa 1613

Kalutara 1624 Puttalam 1716

Kandy 1467 Ratnapura 1245

Kegalle 1413

Unfortunately there are data missing for the districts of Ampara, Batticaloa, Jaffna,
Kilinochchi, Mannar, Mullaitivu, Trincomalee, and Vavuniya. For these the average
income will be set to 0.
- Right click Srilanka in the Table of Contents (TOC) and select Open Attribute
Table from the context menu.
- Make sure the field named DISTRICT is placed furthest to the right in the
attribute table. If not, select the field by clicking its header (the field turns light
blue). Then click the header again and drag it so that the field is placed furthest
to the right in the table.
- Right click on the header of DISTRICT and select Sort Ascending. The names
of the districts should now appear in alphabetical order.
- Click Options in the lower right corner in Attributes of srilanka choose Add
Field. The Add field dialog window should appear.
- Name the field INCOME and choose Short Integer as Type. Leave all other
parameter settings as-is.

14-01-2010 Copyright 2010. Lund University GIS Centre. All rights reserved. 3
Databases and Attributes

Now, type the data from the table with average monthly income values for the districts in
the field INCOME.
- Start editing Attributes of srilanka by clicking Editor > Start Editing in the
Editor toolbar.
Remember that you can activate the Editor toolbar through clicking View > Toolbars if it
is not visible.
- Type in the average monthly income values for each of the districts in the field
INCOME. Press Enter to move to the cell below.
- When finished with the typing, save your edits by clicking Editor > Stop
Editing and Editor > Save Edits.
Check that the values are correct and that all of them have been added. If not, fill in the
missing values.
- Close Attributes of srilanka.

4.4.3. Visualizing monthly average income


When you add a shapefile in ArcMap it draws all the features using the same color.
However, many attribute values can reflect a range of measurements or quantities that
can be classified. You will now classify the data and depict the different classes in your
map.
- Right click Srilanka in the TOC and choose Properties. In the dialog window
Data Frame Properties that appears click the Symbology tab.
- In the box Show, to the left, click Quantities and then Graduated colors.

14-01-2010 Copyright 2010. Lund University GIS Centre. All rights reserved. 4
Databases and Attributes

- In the Value drop down menu in Fields select INCOME.


- Right click the drop down menu Color Ramp and uncheck Graphic View. Color
ramps should now appear as text instead of graphics.
- Select the color ramp Yellow-Green-Blue or Yellow to Green to Dark Blue in
the drop down menu and then click Apply and OK.

The map now shows the variation in income in the different districts of Sri Lanka. The
colors of districts where income data is missing or set to 0 are shown in yellow.

You will now produce a layout map with a title, legend, scale bar and north arrow and
export it as a .jpg image file.

14-01-2010 Copyright 2010. Lund University GIS Centre. All rights reserved. 5
Databases and Attributes

4.4.4. Producing a layout map


Map elements such as north arrows, scale bars, scale text and legend are related to the
data in the data frame. So before inserting a scale bar we need to change the unit settings
so it is in meters.
- Right click the data frame Layers in the TOC and select Data Frame
Properties. Click the tab General and in the Map drop down list in Units select
Meters. Click OK to Apply.
- Go to Layout View by clicking View > Layout View.
Now lets insert a scale bar, north arrow and a title.
- Click Insert > Scale Bar in the main menu. The Scale Bar Selector dialog
window will appear. Select Alternating Scale Bar 1 and then click Properties to
open the Scale bar properties window. Set Division Units to Kilometers, leave
all other settings as is and click OK twice to apply.
A scale bar should have appeared in Layout View. Make sure that you have zoomed to
Full Extent and move the scale bar so that it is placed in the lower left corner of the
layout page.
- To insert a north arrow simply click Insert > North Arrow in the main menu.
Select ESRI North 2 in the North Arrow Selector and click OK. Move it so that
it is placed just above the scale bar in the lower left corner.
- Insert a title by clicking Insert > Title in the main menu. Right click the title
and select Properties. In the Text box write Average Monthly Income by District
and click OK. Move the title box so that it is placed just above the data frame
border.
Finally, insert a legend.
- Click Insert > Legend in the main menu. The Legend Wizard appears. Check
that the layer Srilanka has been added in Legend Items and click Next once.
- In the box Legend Title, name the legend Average Monthly Income.
- Click Next several times to step through the wizard accepting the default legend
parameters, and finalize by clicking Finish. Move the legend and place it in the
upper right corner.
The legend might look ok as it is, however, lets remove the layer and heading names
from it as the title really says it all.
- Right click the legend in Layout View. In the Legend Properties dialog window
click the tab Items and then click Style to open the Legend Item selector.

14-01-2010 Copyright 2010. Lund University GIS Centre. All rights reserved. 6
Databases and Attributes

- In the Legend Item selector dialog window click Properties. In the tab General
uncheck Show Layer Name and Show Heading and click OK thrice to apply.

- Finally, export your layout by clicking File > Export Map in the main menu
when in Layout View. Choose .jpg as file type and name the file
Srilanka_Income and save it in your working directory together with the rest of
your data.
- Insert the map in a Word document using Insert > Picture > From File. As you
will later have to add another map and answers to a couple of questions, prepare
the document by adding your name and all other student info as well.
- Return to ArcMap and save your map document.

4.4.5. Adding a table


- Create a new blank map document in ArcMap by clicking File > New in the
main menu.
- Right click the data frame in the TOC and click Properties. In the Data Frame
Properties dialog window click the General tab and rename the data frame to
Wind power in Hambantota. Set map and display units in Units to Meters and
click OK to apply.
- Add the layers the Srilanka and Ham_districts. Ignore the message notifying
you that the layers are missing spatial reference information by simply clicking
Ok.

14-01-2010 Copyright 2010. Lund University GIS Centre. All rights reserved. 7
Databases and Attributes

- Change the drawing order and color of the layers. In the TOC, drag the layer
Ham_districts and place it at the top, above Srilanka. Click the symbol for a
layer in the TOC to open the Symbol Selector dialog window. Choose an
appropriate color for each of the layers.
Imagine that you have been given an assignment to construct a map showing the
suggested locations for ten new wind power stations in the Hambantota district. The
names of the wind power stations should be labeled on the map. At your disposal, you
have the two layers Ham_districts and Srilanka and an Excel table (Hambantota_wind)
containing the names and locations of the ten planned wind power stations in
Hambantota.

ID NAME X Y

1 Dangalle_1 207755 94721

2 Dangalle_2 210831 96259

3 Dangalle_3 205295 94414

4 Hambantota_1 249581 108253

5 Petter_1 265265 115788

6 Petter_2 287254 131934

7 Petter_3 288177 132856

8 Tissa_1 286947 133317

9 Tissa_2 290022 134240

10 Tissa_3 279412 126244

ArcGIS can handle a number of types of tabular data formats including text files (.txt),
Microsoft Excel files (.xls) and of course dBase files (.dbf). All of these data formats can
be added to ArcMap, previewed in ArcCatalog, and used as inputs in various
geoprocessing tools. Now, before we add the Excel table with wind power stations to
ArcMap lets go through some of the basics.
Excel files and other tabular data formats are added to ArcMap just like shapefiles, by
clicking Add Data. As you most probably know an Excel file is made up of a workbook
containing one or several worksheets or arrays (three is the default number of worksheets
in a workbook). When you add an Excel file in ArcMap or preview it in ArcCatalog a
worksheet is shown with a $ at the end of its file name. Once the worksheet has been
added to ArcMap it can be accessed from the tab Source at the bottom in the TOC. A
worksheet is read only in ArcGIS, meaning that it is not possible to edit or export it.

Note: You can read more about Excel files and other tabular data sources
supported in ArcGIS in ArcGIS Desktop Help.

14-01-2010 Copyright 2010. Lund University GIS Centre. All rights reserved. 8
Databases and Attributes

- Add the Excel file Hambantota_wind to ArcMap by clicking . In the Add


Data dialog window double click Hambantota_wind, select the worksheet
wind_power_stations$ and click Add.
ArcMap usually switches over to the tab Source automatically whenever tabular data is
added. If you are not able to see the file in the TOC it is most probably because the TOC
is set to Display. Just change tab to Source at the bottom of the TOC, then right click the
table and select Open to view it.

4.4.6. Creating features from tabular data


Every wind power station in Hambantota_wind has an x and y coordinate. In ArcMap,
you can easily create a point layer by using the fields containing the coordinates. This
option is very useful when working with point locations, for instance captured using a
GPS receiver.
- Click Tools > Add XY Data in the main menu. The Add XY Data dialog box
appears.
- Make sure that wind_power_stations$ is the chosen table, that the fields x and y
are selected in the X and Y Field drop down menus and click OK. If you get a
message telling you that the table does not have an object-id field just click OK.
A new event layer, wind_power_stations$ Events, has been added to the TOC and is
displayed in the map window. Open the event layers attribute table and compare it with
the original table.
The event layer you just created is a temporary layer. You can decide its appearance, its
colors and so on, however, it is not possible to perform certain tasks such as selecting or
editing features. In order to perform these tasks, the layer has to be exported as a
permanent shapefile. This is easily done through the Export Data dialog window.
- Right click wind_power_stations$ Events in the TOC and choose Data >
Export Data. In the Export Data dialog window choose to export All Features,
name the output shapefile windpoint.shp and make sure you save the file in the
folder containing the other data for this exercise. Click OK and then Yes when
asked if you want to add the exported data to the map
You now have two layers with the same features. Remove the table
wind_power_stations$ and the event layer wind_power_stations$ Events from the TOC
as you dont need them anymore (right click and choose Remove).
- Right click Windpoint in the TOC and select Zoom To Layer.
Change the appearance of all of the layers to appropriate colors and symbols in order to
make the wind power station points more easily distinguishable on the map.

14-01-2010 Copyright 2010. Lund University GIS Centre. All rights reserved. 9
Databases and Attributes

4.4.7. Labelling features


Now, lets label the wind power stations with their respective names on the map.
- Right click Windpoint and choose Properties and then click the tab Label.
Check the box for Label features in this layer. Choose to label all the features in
the same way and make sure Label Field is Name.
- Click Symbol and Label Placement Options or Placement Properties to change
the appearance and placement of the labels. Make sure that all labels are visible,
readable and distinguishable on the map.
- Switch to Layout View and spend some time to try to produce an attractive
layout map. Dont forget to add a legend, a scale bar, a north arrow and a title.
Consult previous instructions or ArcGIS Desktop Help if you feel a bit lost.

Tip: You can change the names of the layers in the legend to something more
appropriate by simply right clicking the layer in the TOC and in the tab General
specifying another name in the box Layer Name.

- When you are satisfied with your layout, export your map as a .jpg image file
by clicking File > Export Map when in Layout View. Save it as
Windpower_Hambantota, insert the .jpg image file in the document containing
the Sri Lanka income map and save it.

4.4.8. Joining a tabular data source to a layers attribute table


- Save your map document and choose to create a new blank map document by
clicking File > New.

14-01-2010 Copyright 2010. Lund University GIS Centre. All rights reserved. 10
Databases and Attributes

- Add the layer Srilanka and the .dbf file Un_employ to your newly created map
document.
- Open the attribute table for Un_employ and explore its contents. The table
should contain five fields or columns: OID, DISTCODE, DISTRICT,
EMPLOYMENT and UNEMPLOYED. Reflect on what these columns could
represent and then close Attributes of un_employ.
We will now join the data in Un_employ to the shapefile layer Srilanka. In ArcGIS, you
can join tabular data based on a common field. A tabular data source might for instance
contain descriptive attributes on features and by joining tables together you can
symbolize, label, query and analyze features using the data from the tabular data source.
- Open the table for Srilanka (destination table) and Un_employ (source table).
Move the table windows so you can view both of them simultaneously.
Both tables have a field with common records. The name or heading of these fields are
however different. In Srilanka it is called SLHE4_ID and in Un_employ it is called
DISTCODE.
- Right click Srilanka in the TOC and select Join and Relates > Join. The Join
Data dialog box appears.
- Select to Join attributes from a table. In drop down menu 1 select SLHE4_ID as
the field that the join will be based on. At 2 choose the table Un_employ and at
3 choose DISTCODE as the field to base the join. Choose to keep all records
and then click OK (you can click About Joining Data to learn more).

14-01-2010 Copyright 2010. Lund University GIS Centre. All rights reserved. 11
Databases and Attributes

Now take a look at the attribute table of Srilanka. The fields from Un_employ should
have been joined to the table.
- In Attributes of srilanka select the field SLHE4_ID and then click and drag it so
that it is placed next to DISTCODE. Compare the records in both fields to
ensure that they match.

4.4.8.1. Saving a join


The join you have just performed is only temporary. When a map document containing
joins are saved, only the definition of how the two attribute tables are linked are saved
and not the linked data itself. To permanently store the joined data, you have to export it.
A table is easily exported through the Export Data dialog window.
- In Attributes of srilanka click Options > Export. The Export Data dialog box
appears. Choose to export all records and save the file as srilanka_unemploy.dbf
together with the other data.
- Also, choose to export the data as a shapefile. Right click Srilanka in the TOC
and point to Data > Export Data. Name the file unemployed.shp and chose add
it to the map.

14-01-2010 Copyright 2010. Lund University GIS Centre. All rights reserved. 12
Databases and Attributes

4.4.9. Structuring SQL-queries


Structured Query Language (SQL) is a standard computer language that is used to access
and manipulate databases. In ArcMap, one of the ways you can use it is to select features
based on the information in the attribute table. You structure SQL-queries in ArcGIS in
the Select by Attributes dialog box, which can be either accessed from the main menu
(Selection > Select by Attributes) or from the attribute table (Options > Select by
Attributes). The table below contains descriptions of some of the more commonly used
operators available in the Select by Attributes dialog window.

Operator Description

= Equal

> Larger than

< Less than

<> Not equal

Larger than or equal

Less than or equal

() Parenthesis are used for grouping expressions

AND AND logical conjunction to combine expressions

OR OR logical conjunction to combine expressions

You will now use Select by Attributes to structure a simple WHERE clause to find out
which districts in Sri Lanka that have an employment rate of 90% or more.
- In the main menu click Selection > Select by Attributes. The Select by
Attributes dialog window appears. Make sure Unemployed is selected in the
drop down menu Layers.

14-01-2010 Copyright 2010. Lund University GIS Centre. All rights reserved. 13
Databases and Attributes

Just above the query box at the bottom of the window, the first part of the SQL
expression, SELECT * FROM, is supplied. This part of the SQL query is hardcoded. The
SELECT statement is used to select data and the asterisk (*) indicates that all columns
will be selected from the table. The WHERE clause allows you select records that fulfill a
specified criteria. Lets structure a simple query.
- In the Select by Attribute dialog box, make sure Unemployed is selected in the
drop down menu Layers.
- Right click in the field box listing all of the fields in the attribute table of
Unemployed and select Sort Ascending. Double click the field EMPLOYMENT
to add the field to the query box. Click the larger than/equal to operator button
and type in 90 (for 90%) in the query box and finally click Apply.
- Open the attribute table of Unemployed. In the attribute table, you can choose to
list selected records by clicking the button Selected at the bottom of the table.
You can revert to show all by clicking All.

Question 4.1: Name the districts that have an employment larger than 90%?

Question 4.2: Name the districts have an employment less than 85% (do not include
districts with zero values)?

14-01-2010 Copyright 2010. Lund University GIS Centre. All rights reserved. 14
Databases and Attributes

4.4.10. Generating statistics


The Excel file Gampop94-97 is provided. It contains population values from 1994 and
1997 for the Gampaha district in Sri Lanka.

Division Div_id Pop1994 Pop1997

Attanagalla gmp01 128183 157114

Biyagama gmp02 111728 142623

Divulapitiya gmp03 104631 127993

Gampaha gmp04 143688 167009

Ja-Ela gmp05 142779 185129

Katana gmp06 172425 197672

Kelaniya gmp07 129204 143851

Mahara gmp08 129621 166906

Mirigama gmp09 131128 149839

Minuwangoda gmp10 125867 147579

Wattala gmp12 128719 145739

Weke/Dompe gmp13 113949 130003

- Open a new map document and add the Excel file Gampop94-97 and the
shapefile Gamdiv.
- Right click Gamdiv and join the two tables using the Join Data dialog box.
Base the join on the field ID in Gamdiv and the field Div_id in Gampop94-97.
- Save the join as a new shapefile. Name it gampop.shp, add it to ArcMap and
delete the layer Gamdiv.
When exploring a table, you can get statistics describing the values in numeric fields.
You can see how many values the field has as well as the sum, minimum, mean,
maximum, and standard deviation of the values in a field.

14-01-2010 Copyright 2010. Lund University GIS Centre. All rights reserved. 15
Databases and Attributes

- Open the attribute table of Gampop, right click the heading of the field named
Pop1994 and click Statistics. A window named Statistics of gampop appears.
- Click the drop down menu Field and choose Pop1997 to generate statistics for
the population values from 1997 in the same way.

4.4.10.1. Field calculations


If you want to perform mathematical calculations involving one or several existing fields
for one or several existing records you can use the Field Calculator. By using the Field
Calculator you can perform simple and advanced calculations on all or selected records.
Lets use the Field Calculator to see which of the divisions that had the largest increase
in population from 1994 to 1997.
- Open the attribute table for the layer Gampop. Add a new field in the attribute
table by clicking Options > Add Field. Name the new field Popdiff and choose
Long Integer as data type.
- In the Editor toolbar click Editor > Start Editing.
- Right click the heading of the field Popdiff and select Field Calculator. The
Field Calculator dialog window appears.

Note: It is possible to perform calculations without clicking Editor > Start


Editing. However, in that case, there is no way to undo the results.

The hardcoded text Popdiff = just above the text area in the Field Calculator indicates
that it is the result field. You can use the list Fields and the functions and/or you can type
to build a calculation expression in the text area.
- Use the Field Calculator functions to create the expression [Pop1997]-
[Pop1994]. Click OK to perform calculations and make sure to click Editor >
Save Edits and Editor > Stop Editing when done.

14-01-2010 Copyright 2010. Lund University GIS Centre. All rights reserved. 16
Databases and Attributes

Question 4.3: Which three districts had the largest population increase between
1994 and 1997 (give the name of the districts and their population increase)?

4.4.10.2. Summarizing a field


You can get more statistical information for all records in a table or just selected records
by using the Summarize dialog window. Summarize creates a separate table that contains
the statistics for a field by a unique value or a category.
- Add the shapefile Srilanka to ArcMap and open its attribute table.
- Make sure no records are selected by clicking Options > Clear selections. If
any records are selected, then your summary table will contain records for only
the ones that are selected.
- Right click the header of the field Province and choose Summarize. The
Summarize dialog box appears.
- In the middle box choose the following statistics to be included in output table:
AREA Sum, INCOME Minimum, INCOME Maximum, and INCOME Average.

14-01-2010 Copyright 2010. Lund University GIS Centre. All rights reserved. 17
Databases and Attributes

- Name the output table stat_area_income.dbf. Click OK, add the table to the
map document and then open it.
The resulting table should contain five fields with the statistics you specified for each of
the provinces.

End of Practical Exercise 4

Send your answers to the teacher as instructed

14-01-2010 Copyright 2010. Lund University GIS Centre. All rights reserved. 1

You might also like