0% found this document useful (0 votes)
10 views

Exercise4 Database

Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
10 views

Exercise4 Database

Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 16

4 DATABASES AND ATTRIBUTE DATA

4.1 PURPOSE
The aim of the exercise is to deepen your knowledge on attribute tables. You will learn to
type in new data in an existing table, import data from an Excel worksheet, join two tables
together, convert a list of coordinates to a shapefile, and create simple SQL-queries.

4.2 DATA
The files needed for this exercise are:
srilanka (“shapefile”: 3 files)
ham_districts (“shapefile”: 3 files)
gamdiv.shp (“shapefile”: 3 files)
windpower.xls (a spreadsheet)
un_employ.dbf (a table)
gampop94-97.dbf
Copy the file DATA4_Databases to your computer.
- Create a folder in your local working directory called 4_Database_attribute_data.
(Remember to keep an organized data structure in your computer Ex:
C:\GIS\4_Database_attribute_data)
- Copy all the required data files for this exercise in your newly created folder.

4.3 ANSWERS TO BE SENT TO TEACHERS


All students have to send a document with the maps and answers to the questions 4.1- 4.3
by e-mail to the teachers as indicated in the document “Sending Answers to Teachers”.

4.4 GETTING STARTED


Start ArcCatalog and Connect to the 4_Databases_attribute_data folder. Get an overview
of the data files you downloaded for this exercise using the Preview and Metadata tabs.
When looking at shapefiles, both the map and table can be previewed. Under the
contents window there is a dropdown list where the Preview can be altered between
Geography and Table.

1
Go to ArcMap by clicking , open A new empty map and add srilanka.shp by clicking

.
Save your project (map document) as Sri_lanka_attributes.

Close ArcCatalog

4.5 METHOD

4.5.1 Typing data into 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 in txt- or dbf-format, or by typing in
new data in the table itself. You will try both methods in this exercise.
You have the following data about the income in Sri Lanka that you would like to visualize
on a map:
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 districts the income
will be put to 0.
Open the attribute table in ArcMap. Right-click srilanka in the Table of Contents and
choose Open attributetable.
Move a field in the attribute table. Select the field named District by clicking the header
of the field (the field turns turquoise). Use the mouse to drag and drop it so it appears
as the field furthest to the right in the attribute table.
Sort data in a field. Right-click on the header of the District field and choose Sort
Ascending. The names in the field now appear in alphabetical order.
Add a new field to the attribute table. Click Options in the top-left corner of the
Attribute Table and choose Add Field and the Add field dialog box appears. Name the
field INCOME and choose Short Integer as data Type. Do NOT change the Field
Properties i.e. let the Precision be 0.
Type data into the new Field. Make the table editable by clicking Editor > Start Editing
(if you do not see the Editing toolbar, activate it through View > Toolbars) . Click in
the second cell from the top in the INCOME Field, which corresponds to the district
Anuradhapura. Type in the numbers for Average monthly income (listed in the table
above) in the INCOME Field. Press Enter to move to the cell below. When finished,
save your edits through Editor > Stop Editing and Save Edits. Check that the values

2
are correct and that all of them have been added. If not, go back (Editor > Start Editing)
and fill in the missing values. Close the Attribute Table.

Visualize the annual income on the map. Right-click srilanka in the Table of Contents
and choose Properties. Click the Symbology tab and a new dialog box appears. Make
the following changes: Choose to Show: Quantities in Graduated colors, Fields >
Value: INCOME, change the Color Ramp to yellow-green-blue. Click Apply and OK.
The map now shows the variation in income in the different districts of Sri Lanka. The
districts where income data is missing and therefore set to 0 are shown in yellow.

3
You will now produce a layout map with title, legend, scale bar and north arrow and
export it as a JPEG file that can be imported in a Word document to be sent to
teachers together with the answers to the questions.

Produce a layout map. Check that the unit settings for the coordinates are set to meters.
Do this by selecting Data Frame Properties from the View drop-down list and then
choose the General tab and check that Map Units as well as Display units are defined as
meters. Then, click on View in the menu and then on Layout view. The Layout toolbar
will appear and the display changes to show the page layout. Click Insert > Legend
in the main menu and the window Legend Wizard appears. Check that the layer
srilanka has been added to the Legend Items box. Click Next several times to step
though the wizard accepting the default legend parameters, and click Finish when done.
Resize, and move the legend so it is nicely displayed on the map.

Insert a scale bar, north arrow and a title. To insert a scale bar select Scale Bar from
the Insert drop-down list and then click the Properties button in the Scale Bar Selector
window. In the window Scale Bar, set Division Units to kilometres and click OK.
Select Alternating Scale Bar 2 and click OK. Move the scale bar so it is nicely
displayed on the map. To insert a north arrow simply select North Arrow from the
Insert drop-down list and in the window North Arrow Selector choose a north arrow
you like. Finally, in order to insert a title, click Insert > Title and write a suitable title
for your map. Click Insert> Dynamic Text > Coordinate System to insert
Coordinate System.

Export your layout by clicking File > Export Map in the main menu. Choose JPEG as
File type and name the file Srilanka_Income.jpg and save it in your working directory
together with the rest of your data.

4
Insert the JPEG file in a MS Word document. Start MSWord. Click Insert > Picture >
From file. Navigate to your working directory and choose Srilanka_Income.jpg. Save
the Word document in your folder and close MS Word.
To return to the data view back in ArcMap select Data View in the View drop-down list.

4.5.2 Importing a table


Create a new data frame in ArcMap through Insert > New Data Frame
Rename and set map units to the new data frame. Right-click the New Data Frame in
the Table of Contents and the Data Frame Properties dialog box appears. Click the
General tab and make the following changes; Name: Windpower in Hambantota,
Units > Map: Meters, Units > Display: Meters. Click Apply and OK.

5
Add layers to the data frame. Right-click the Windpower in Hambantota data frame and
choose to Activate it. The name of the Data Frame will then appear in bold text. Click

and add the srilanka and ham_districts layers to the Windpower in Hambantota
Data Frame.
Change the order and color of the layers. In the Table of Contents, move the
ham_districts layer above the srilanka by using the mouse to “drag and drop”. To
change color, click the symbol and the Symbol Selector will appear. Choose a color
you like.
You have been given the assignment to make a map over the location of ten suggested new
wind power stations in the Hambantota district. Their names should be printed on the map and
the map should be stored as a “JPEG” image, so it can be inserted into a Word document. To
accomplish this assignment; you have the two themes you just added in ArcMap, and the table
below:
ID Name X Y
1 Dangalle-1 207755 94721
2 Dangalle-2 210831 96259
3 Dangalle-3 205295 94414
4 Hamba01 249581 108253
5 DrPetter-aa 265265 115788
6 DrPetter-bb 287254 131934
7 DrPetter-cc 288177 132856
8 Tissama29 286947 133317
9 Sama1 290022 134240
10 Sama2 279412 126244

Type the data into a table format that ArcGIS can handle. This can either be done
directly in ArcGIS or, even easier when there are a lot of data, in Microsoft Excel.
Here you will do it in Excel, and as a matter of fact, someone has done the main job
for you already!
Open Excel and open the file Windpower.xls. Study the file contents and the structure of
rows and columns including column headings. It should look like below. Save the table
through File > Save As. Change the file format to: DBF (*.dbf, dBaseIV) and name
6
your file windpower.dbf in your working folder. Click OK in the dialog window that
follows. Close Excel.

ArcGIS can handle different types of tabular data formats. One is text (*.txt), a text file, and
another is dBase (*.dbf). The dBase files relate to the file format used in the dBase program,
which is a Relational Database Management System (RDBMS).
Add a table in dbase format to ArcMap. Go back to ArcMap and the
Sri_lanka_attributes map document.
Activate the Windpower in Hambanota data frame.

Add windpower.dbf by clicking .


At the moment, it is just a table, not yet linked to a layer. That means you cannot display its
contents as a “map”. If you want to be able to show the wind power station on the map in the
Data Frame, each feature must be connected to a geographic feature.

4.5.3 Create features from table data with X, Y coordinates


Every wind power station has an x and y
coordinate. In ArcMap, you can easily create
a point layer from these coordinates listed in
the table (windpower.dbf). This option is very
useful when working with point data, for
example, taken with a GPS.
Add XY data to a map in the Data
Frame.
Right click on the windpower data and
Choose Display X-Y coordinates.
Display XY Data dialogue box
appears. Make the following changes
in the scroll down windows: Choose a
table from the map or browse to
another table: windpower.dbf; Specify
the fields for the X and Y
coordinates: X field: X; Y Field:
Y. Import the Spatial Reference from
the srilanka.shp (Edit > Import ).
Check the Show details box and click
OK.

7
Check the added XY data in ArcMap. A new layer, windpower.dbf Events, has been
added to the Table of Contents. Select it and check that your wind power stations are

at the right place. Use the tool, click on the points in the map, to see if they have
the same coordinates on the map as in the table. (You might have to zoom quite a lot
to get accurate results with the info tool).

Convert point data to Shapefile. To turn this theme into a real shapefile and not just a
“temporarily” layer as it is now, it must be converted to shape format. Right-click the
windpower.dbf Events in the Table of Contents and choose Data…>Export Data and
an Export Data dialog box will appear. Choose to Export: All Features and name the
Output shapefile, windpoint.shp and save in the in your working folder with the rest of
your data. Click OK. A new layer will be created and saved. When you are asked: Do
you want to add the exported data as a layer? click Yes.

Remove layer. There are now two layers with the same features in your Table of
Contents. Remove the old one (windpower.dbf), which is not needed anymore. Right-
click the layer and choose to remove.
Zoom to active layer. Activate the windpoint.shp layer. Zoom in on the active layer by
Right-clicking and choosing Zoom To Layer.
Make point features more visible on the map. Change the appearance of the point
features in the layer to make them more easily visible on the map. Click on the symbol
in the Table of Contents so the Symbol selector appears. Change to a suitable color
(e.g. red) and increase the size (e.g. 14). Click Apply.
Open the attribute table. Open the Attribute table of the windpoint layer, to see if it really
is connected to the map. Yes? Close the table.
Label the point features. Right-click the windpoint layer and choose Properties and then
click the Label tab. Check the box for Label Features in this layer. Choose to Label
all the features in the same way. Set the Text String Label Field: Name.
Edit labels. You have several possibilities to change the appearance of the labels from the
Layer properties dialog window (Right-click layer in TOC). Click the buttons Symbol,
Label Styles and Label Placement Options to set the following appearance of the
labels: Select Arial Narrow, Style: Bold and Size: 14. Offset the label horizontally
around the point. Click Apply and OK.

Export layers in data frame to a JPEG file. When you are satisfied with the layout of
the layers in the Windpower in Hambantota Data frame, export the map to a JPEG file
(*.jpg) by choosing File > Export Map. Name the file Windpower_Hambantota and
save it in your working folder with the rest of your data.
Delete data frame from map document. Finally, delete the Windpowerin Hambantota
data frame from the map document, as you will not need it anymore. To do this, right-
click and choose Remove. Save.
Insert the JPEG file in your MS Word document. Start MSWord and open your Word
document. Go to Insert > Picture > From file. Navigate to your working directory and
select Windpower_Hambantota.jpg and click OK in order to add it to your Word
document together with your Sri Lanka income map and your answers to the questions
below. Give the picture a title and a brief explanation text. Save the document and close
MS Word.

4.5.4 Joining an external table to a layer’s attribute table


Add table in ArcMap. Add the table un_employ.dbf to the map document, and open it to
study its contents. The table contains five columns: OID, Distcode, District,
Employment and Unemployed. Reflect on what these columns could represent. Close
the table.
In order to use the data in this table, you will join it to a theme. You can join a table to the active
table based on the values of a common field found in both tables. Join establishes a
one-to-one or many-to-one relationship between the destination table (the active table) and the
source table (the table you are joining into the active table). Typically, the source table contains
descriptive attributes of features that you wish to join into a theme’s table so that you can
symbolize, label, query and analyze the features in the theme using the data from your source
table.
Select common attribute fields in the destination and source tables. Open the tables
for srilanka.shp (destination table) and un_employ.dbf (source table). Move the table
windows so you can see both of them simultaneously. Both tables have a numeric field
with common records and, therefore, they can be joined together. However, the names
of these fields are different. In srilanka it is called slhe4_id and in un_emply it is
distcode.
Select both of these fields by clicking in the headings (they become turquoise).

Join attributes to a destination table


from a source table. In the Table of
Contents, right-click on srilanka.shp
(destination table) and choose Join
and Relates > Join, and the Join Data
dialog box appears. Make the
following input: Join Attributes from
a table; 1. Choose the field in this
layer that the join will be based on:
SLHE4_ID; 2. Choose the table to
join this layer, or load the table from
disk: un_employ; 3. Choose the field
in the table to base the join on:
DISTCODE. Click About joining
data… to learn more about the Join
function. Click OK.
Check the new records in the Destination Table. Now look in the attribute table of
srilanka.shp (destination table). Two things are different: 1) Fields have been added to
the table. 2) The file names of the original table have been added to the header names.
Move the field, srilanka. SLHE4_ID, next to the field, un_employ.DISTCODE to
compare the records.

4.5.5 Storing a joined table


The join you have just created is only “temporary” in the memory of the computer. To
permanently store the joined data, you have to export it and save it either as a dbf file or a new
shapefile. This is necessary if you want to use the joined table in other applications.
Export the joined destination table. In the Attributes of srilanka (joined destination
table) window, click Options > Export… and a Export Data dialog box appear.
Choose to export all records and save it as, srilanka_unemploy.dbf in your working
folder. Add it again to the map document look in the new table to see how many fields
are listed. Note that the names no longer contain the original table file names.
Export the layer as a new Shapefile. If you, on the other hand, want the joined data to be
permanently linked to a map, you have to export the layer as a new shapefile. Right-
click the srilanka layer in the Table of Contents and choose Data > Export Data.
Choose to export all features and save it as, unemployed.shp in your working folder.
Add it to the Map document.

4.5.6 Queries (SQL)


SQL (Structured Query Language) is a query language to select and retrieve data from an
attribute table. SQL in ArcGIS is done with the Select By Attributes Option.
In the Select By Attributes dialog box you can easily find features or make selections from an
attribute table. You will now use this function to find out how many districts in Sri Lanka have
an employment rate over 90%.
Open Select By Attribute dialog box . You open the Select By Attribut dialog box in the
main ArcMap window from Selection > Select By Attributes or from the attribute
table by clicking the Options button >Select By Attributes.
Structure a query by choosing a field,
operator and value. In the Select By
Attribute dialog box, there is a SQL
window where you structure your query
selecting a field, an operator and a value.
In the Field: scroll down the list, double-
click on the field: EMPLOYMENT and it
appears in the SQL window. Then click
“larger than/equal to” operator button,
and it also appears in the SQL window.
Finally, type in directly in the query
window 90 (for 90%). Click Apply.

Show selected attributes only. In the attribute table, you can choose to see only the
selected records by clicking in the button Selected at the bottom of the table. By
thereafter clicking All, you come back to the original table.
Question 4.1:
Name the districts have an employment larger than 90%?
Question 4.2:
Name the districts have an employment less than 85% (do not include district with
zero values i.e missing values)?

4.5.7 Generating statistics of a field


The statistics option allows you to obtain basic descriptive statistics for a field in the table, but
remember that you can only perform statistics on numeric field.
You will now look a bit more closely at some of the options ArcMap offers regarding
thematic mapping. You will use population data from 1994 and 1997 for the district
of Gampaha and display these data in different ways on a map.
First of all, you need to type in the following data in Excel and save it as a dbase file named:
Again, someone has done this work for you! Study the file.
gampop94_97.dbf (Note: no gmp11).
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 data frame in ArcMap and add the new dbf table. Create a new data
frame in the Map document, and name it: Thematic mapping – Gampaha. Add the
table gampop94-97.
Join the new table with an existing layer. Before the data can be displayed in the data
frame, you have to join it to a layer. Add the layer gamdiv.shp. Open the attribute tables
of gampop94-97 and gamdiv.shp. Join the tables by using the Id field in gamdiv and the
Div_id in gampop94-97. Export the gamdiv layer with the joined table as a new
shapefile, save it as gampop. Add it to the data frame: Thematic mapping – Gampaha
and delete the old shapefile gamdiv.

Generate statistics. You are now going to generate population statistics in Gampaha for
1994 and 1997. Open the attribute table of gampop, right-click on the heading
Pop1994 choose Statistics. A window named Statistics for Pop1994 field will appear.
Generate the statistics of population in 1997 in the same way.

4.5.8 Calculate values of a new field


If you want to display which division had the largest increase in population from 1994 to1997,
you have to add a new field in the table and then calculate the difference for each division.
Add new field in attribute table: Add a new field in the table gampop by clicking on
Options > Add Field. Name the new field popdif and choose Long Integer as the Type.
Using the field calculator. Using the field calculator, you can calculate values of the new
field popdif based on already available data. Start by activating the “Editing mode”
(Editor > Start editing). Then, right-click the heading popdif and choose Field
Calculator. You can now build an expression in the expression text box (above which
you find “popdif =”) by double-clicking on the fields and operators and/or typing in
values. Calculate [Pop1997]-[Pop1994], and Save your edits.
Display the Calculated Values on the Map. Use the Layer Properties dialog box and
Symbology tab to display the changes in population between 1994 and 1997 on a map.
Below you see an example of what such a map can look like.

Question 4.3:
Which three district had the largest population increase between 1994 and 1997,
name the districts and their population increase?
4.5.9 Summarizing a field
You can get more statistical information for all records in a table or just selected records by
using the Summarize option. Summarize creates a separate table that contains the statistics
for a field by unique value or category.
Open Attribute Table. Open the attribute table of the Srilanka layer. You are going to
summarize income and area according to province.
Clear selections. Make sure no records are selected by clicking Options > Clear
selections.
Summarize records in a field. Select the srilanka. Province field, right-click and choose
Summarize and the Summarize dialog box appears. Select to summarize the srilanka.
Province field. Then select the statistics that will be included in the output table;
Sum of AREA,
Min. PERIMETER
Max. PERIMETER
AveragePERIMETER
.
Finally, name the output table “Sum_area_perimeter”. Click the More about Summarize…
button and an informative text appears if you want to learn more about this function. Click
OK. Choose to add the table to the Map document
Look in the new table. In the resulting table, you can now easily see statistics regarding
perimeter and area per province.

End of exercise 4
⇒ Send the maps you produced and the answers to the teacher as instructed.

4.5.10 Theoretical questions exc. 4


T 4.1 Describe the differences between the hybrid and the integrated database systems.
T 4.2 It is important to have a standard semantic language for objects in a database.
Give three examples (not a road) of objects that you think people can interpret
differently depending on who they are.
T 4.3 Describe the hierarchical and the relational database structures.
T 4.4 What is redundancy, and why should you avoid it in a geographical database?

You might also like