Tutorial 1 - First Steps with a GIS

Transcription

Tutorial 1 - First Steps with a GIS
Page 1 of 15
First Steps with a GIS – Using QGIS
Introduction
There are six parts to a modern geographic information system (GIS): hardware, software, data, methods,
users and network. This tutorial will introduce you to the software and data portion of a GIS.
In this tutorial, you will complete four tasks:
1.
2.
3.
4.
Obtain and install QGIS, a free, open-source GIS software package.
View data in QGIS to learn about the different spatial data models.
Convert spatial data sets to different data formats.
Learn how to deal with different coordinate in a single project.
Part 1 – Obtain and Install QGIS
There are many GIS software packages available; some free and some for a fee. Each software package
will offer different user experiences and functionality depending on the software vendor. Even with the
potential for vast differences in the software packages, most GIS software offer a similar set of base
functionality.
Since this is an introductory tutorial to GIS, you will be introduced to a free GIS software package called
“Quantum GIS”, or, QGIS for short. QGIS is an official project of the Open Source Geospatial
Foundation and is available for free. QGIS runs on all of the modern operating systems, such as
Windows, Linux, Mac OS X and Unix and supports much of the base functionality as other GIS software
packages. Thus, QGIS is a good GIS software package for you to learn the basics on with no investment.
Should you continue to use QGIS and would like to contribute, they do take donations and sponsorships.
QGIS is easy to download and install. This tutorial will show how to install for Windows. Installation
for Mac OS X will be similar, however if you choose to install on Linux or Unix, you will need to read
the installation instructions provided on the QGIS website to install.
To download and install QGIS 1.8, follow these steps:
1)
2)
Open a web browser and navigate to: http://www.qgis.org/
Under the main menu, click the “Download” link, or, press the “Download Now Free!” button.
Page 2 of 15
3)
On the Download page, choose the operating system that you will install QGIS on. If you are going
to use Windows or Mac OS X, it is recommended that you download the “Standalone Installer”.
4)
Download the installer to your local hard disk and then double-click the downloaded file to begin
installation. You will be greeted by the installation wizard.
Page 3 of 15
5)
Click Next to view the License Agreement. If you agree, click I Agree.
6)
Choose a Destination Folder for the QGIS program files to be installed into by clicking Browse.
Once you have chosen the installation folder, click Next.
7)
If you choose to install any of the QGIS sample datasets, check the associated boxes. This tutorial
does not require any of the QGIS sample datasets. Click Install to begin the installation.
Optional
Page 4 of 15
8)
When QGIS is finished installing, select Reboot now, then click Finish to close the install wizard
and reboot your computer.
9)
On Windows, a new Start menu group will be created. Start QGIS by clicking Start => Programs
=> Quantum GIS Lisboa => Quantum GIS Desktop (1.8.0)
Part 2 – View Data in QGIS
QGIS is a capable GIS software package that will allow you to view data in many different formats. This
section of the tutorial will introduce you to the QGIS interface, teach you how to add data to QGIS, and
show you how to navigate the data.
2.1 – The QGIS Interface
QGIS has a number of buttons and menu items to learn. At first, it may seem overwhelming, but with
practice, you will quickly become fluent with the QGIS interface. First, let’s take an overall look at the
interface.
Menu Bar
Tool Bars
Map Legend
a.k.a.
Map View
Table of
Contents
Status Bar
Page 5 of 15
1. Menu Bar – The menu bar provides access to many QGIS functions using a pull-down menu
system.
2. Tool Bar – The tool bar provides easy access to the most popular of the functions available in the
Menu Bar. If you hover your mouse over a button on the tool bar, a tool tip will appear which
will provide a short description of the purpose of the button.
3. Map Legend – The map legend shows the layers of the data added the map. The map legend is
used to access the properties of each data layer and set the drawing order of the data layers.
4. Map View - The map view shows the data graphically as a map. The map view displays all of
the data layers listed in the map legend. You can interact with the map view to zoom in closer
and further away from the data, pan around the data and select information on the map among
many other operations.
5. Status Bar – The status bar displays the current position of your mouse cursor in map
coordinates. The status bar will also display the progress of rendering layers in the map view and
other operations.
2.2 – Adding and Displaying Data in QGIS
Now that you know the basic parts of QGIS, let’s dive in to learn the basics of adding and viewing data.
1) Download Tutorial 1 Data.zip from the course website. Save this file to your local hard drive.
Extract the contents into a folder that you can locate. This tutorial will refer to this folder as the
“Tutorial Folder”.
2) Open QGIS if it is not already open.
QGIS is boring without any data, so let’s add a simple vector data layer of Nueces County, Texas.
3) In the Menu Bar, click Layer => Add Vector Layer.
Optionally, you may click the Add Vector Layer Button on the Tool Bar.
4) On the “Add vector layer” dialog. Make sure that “File” is checked.
5) Click Browse and navigate to the “Nueces County Boundary.shp” file in the Tutorial Folder.
6) Once the file is selected, click Open to add it to QGIS.
Page 6 of 15
7) Repeat steps 3-6 to add the vector file “Selected Nueces County Roads.shp” in the Tutorial Folder.
After adding the Roads, you should see the following in QGIS. Note: The colors of the data layers
may be different than what you have. This is because colors are randomly assigned when vector
layers are added to the map.
Now that we have added some vector layers to the map, let’s change the colors to make the map more
cartographically pleasing.
8) In the Map Legend, right-click on Selected Nueces County Roads then
choose Properties from the contextual menu. This will display
the “Layer Properties” dialog.
9) In the “Layer Properties” dialog, select “Style” tab.
10) The Style panel allows you to change the outline, fill, width, color, transparency and texture of the
data layer. We will change the color of the roads to black and the outline width to 0.10 for now. To
do this, change the “Width” to 0.10 then click the button with a solid color and word “Change”.
Note: Again, your box may have a different color.
11) On the “Select Color” dialog, choose the black color in the “Basic colors” section. This is the top-left
color. With black selected, click OK to close the “Select Color” dialog then click OK on the “Layer
Properties” dialog to see the changes on the map.
Page 7 of 15
Now we will change the color of the Nueces County boundary.
12) Open the “Layer Properties” dialog for the “Nueces County Boundary” data layer (see step 8 above).
13) Select the “Style” tab (see step 9 above).
Previously, we changed the outline color for the roads, but we ignored the fill options. This is because a
line vector file does not have an interior area. A polygon vector file, like “Nueces County Boundary”,
does have an interior area and an outline. Therefore, we can change both the fill options and outline
options for this data layer. Let’s do this now.
14) Under the preview of the layer, click the “Change” button with the wrench. This will open the
symbol properties dialog box.
15) Click on the top button with the solid color and word “Change” to change the fill color. On the
“Select Color Dialog”, set the following values:
a) Red: 160
b) Green: 220
c) Blue: 150
16) Similar to Step 15, change the “Border Color” to the following values:
a) Hue: 111
b) Sat: 81
c) Value: 73
17) Change the “Border Style” to “Dash Line”.
18) Change the “Border Width” to “0.5”.
19) Click OK to all open dialogs to view the map. It should look similar to this:
Page 8 of 15
20) Using what you have learned so far, add “Cities in Nueces County.shp” to the map and change the
style to whatever you’d like:
At this point, you should have a general map of Nueces County, Texas. Let’s add an aerial photo to the
map now. An aerial photo is of data type raster, so there will be some differences in how we add the data
to the map and prepare it for display.
21) In the Menu Bar, click Layer => Add Raster Layer.
Optionally, you may click the Add Raster Layer Button on the Tool Bar.
22) In the Open File dialog, change the file type to: “[GDAL] GeoTIFF (*.tif *.tiff *.TIF *.TIFF). Doing
this will filter the file types so it will be easier to find TIFF files. Select “Corpus Christi SQ
DOQQ.tif” then click Open to add the raster to the map.
You should see the aerial photo on the map now, however, it is a bit small to see clearly. We will now
use the zoom and pan functionality to get a closer look at the aerial photo.
23) On the Menu Bar, click View => Zoom In.
Optionally, you may click the Zoom In button on the Tool Bar.
24) With the “Zoom In” tool selected, you have two ways to zoom into the map:
a) Click once on the location you would like to zoom to. The map view will zoom in one level to
that location.
b) Click and drag a box around the area you wish to zoom to. Release the mouse button to execute
the zoom.
c) Note: You can also use the scroll wheel on your mouse to zoom in or out at any time.
25) Using either of the two methods, zoom in until you see the entire aerial photo.
a) If you zoomed in too far, select the “Zoom Out” tool by clicking View => Zoom Out on the
Menu Bar, or by clicking the Zoom Out button on the Tool Bar.
Page 9 of 15
b) If you get lost, you can zoom to the full extent of the data layers by clicking View => Zoom Full
or by clicking the Zoom Full button on the Tool Bar.
c) An even quicker way to zoom to the extent of the aerial photo is to select “Corpus Christi SE
DOQQ” in the Map Legend and then click Layer => Zoom to Layer Extent, or the Zoom to
Layer button on the Tool bar.
Now that you are zoomed into the aerial photo, note that the aerial photo may be on top of the roads and
boundary layers; obscuring our view of them. This is because the aerial photo has a higher draw order
than the other layers. You can tell this because the aerial photo is the top layer (or near the top) listed in
the Map Legend.
To have the aerial photo draw below the other layers, we need to reduce the draw order. To accomplish
this:
26) Click on, and then drag “Corpus Christi SE DOQQ” below “Selected Nueces County Roads” and
then release the mouse button. If you were successful, the aerial photo will now be drawn below
the roads. Feel free to change the draw order of the Cities layer if you wish.
The next thing you might notice about the aerial photo are the long black triangles running the length of
the edges. These are areas of “No Data”. This happens because a raster must be a rectangle, but an aerial
photo might need to be rotated slightly to align with the Earth. Because the aerial photo is rotated, it no
longer matches the rectangle of the raster, and thus, creates areas of “No Data”. Luckily, we can remove
these “No Data” areas to create a better looking map.
27) Open the properties dialog of the “Corpus Christi SE DOQQ” data layer.
28) In the “Layer Properties” dialog, select the “Transparency” tab.
29) In the “Transparency” window, in the “No data value” frame, enter 0, then click OK. This will make
the “No Data” areas of the raster fully transparent.
Page 10 of 15
Sometimes we want to temporarily turn off the visibility of a layer, but not remove it from the Map
Legend. We can do this by turning off the data layer’s visibility.
30) To turn off a data layer’s visibility, in the Map Legend, click the box next to the data layer name to
clear the “x” and turn off the data layer’s visibility.
31) To turn on a data layer’s visibility, in the Map Legend, click the box next to the data layer name to
add the “x” and turn on the data layer’s visibility.
2.3 – Viewing Attributes in QGIS
All vector files have an associated attribute table. The attribute table holds attributes that describe a
geometric representation (point/line/polygon) on the map. Being able to link attribute information to a
geometric representation placed at a position on Earth is a truly powerful feature of GIS. Often, attributes
are used to select, calculate and transform information stored in data sets. Let’s look at the attribute tables
located on our map.
1) Right-click on “Cities in Nueces County” and then choose Open Attribute Table from the
contextual menu. This will open the attribute table for the data layer.
The attribute table is organized into a series of rows and columns. Each column represents an attribute
used to describe an object represented by the geometric representations (point/line/polygon). Each row
represents a single record (object) in the vector data set.
So, for instance, the data layer “Cities in Nueces County” has 7 records since there are 7 cities in Nueces
County. This means that there are 7 geometric representations (points) on the map. This also means that
for each point on the map, there is an associated row in the attribute table that holds the descriptive
attributes about that city.
Each column has a name to document what part of the object it is describing. For instance, in the table
above, the second column, “NAME”, holds the names of the cities in Nueces County. The “SOURCE”
column holds the name of the agency that supplied the information; in this case, it was the Coastal Bend
Council of Governments (CBCOG). In this case, we are lucky that the column names are clear enough to
Page 11 of 15
understand, but, unfortunately, some column names are not as descriptive. If the column names are not
clear, you would need to read the documentation that came with the data (metadata), or contact the author.
2) Close the attribute table.
3) Open the attribute table of the “Selected Nueces County Roads”.
You should notice that there are many more columns for this data layer. We can use these columns to
search for a specific street. We will look for “River Ranch” road.
4) With the “Selected Nueces County Roads” attribute table open…
a) in the “Look for” text box, enter “River Ranch” (without quotes).
b) in the “in” dropdown box, choose “ST_NM”.
c) press Search.
d) click the box next to “Show selected only” to have the attribute table only display the records that
match. The attribute table should now only be showing two records.
Having QGIS search for the records saves us the time of having to manually scroll down the rows until
we find the records we want. What is even better is that now we can have QGIS zoom to the selected
features on the map so we can see where they are.
5) With the two roads still selected, click the Zoom map to the selected rows button.
6) Close the attribute table (it may have hidden itself behind QGIS, so you may need to switch to the
attribute table window to close it).
7) The map will now be zoomed into River Ranch road and the road will be highlighted with a yellow
color.
8) To de-select the records, on the Tool Bar, click Delselect features from all layers button.
9) Zoom to the full extent of the map.
Part 3 – Labeling Features on the Map
Showing the cities on the map, without labeling them, might confuse the map reader as to what the circles
represent. To clear this up, let’s label the points.
1.
2.
3.
4.
Open the properties dialog of the “Cities in Nueces County” data layer.
Click the ‘Labels’ tab.
Check the box next to ‘Display labels’ to enable the label properties.
In the ‘Basic label options’ section, set the following:
Page 12 of 15
a. Field containing label: NAME
b. Font size: 16 – In points
c. Color: White
5. Click OK to set the label properties.
You should now see the names of the cities overlaid on the map in large, white text. While the text looks
good, there are a few problems that we need to address.



Corpus Christi is labeled in the middle of Corpus Christi Bay.
Agua Dulce (West edge of the county) has the ‘A’ of its name beyond the county boundary, and,
since it is white text on a white background, the ‘A’ cannot be seen.
The circles representing the cities do a poor job of representing the boundaries of the cities, but
do provide an anchor for placing the labels. Perhaps we could use the circles as label anchors, but
not for representing the boundaries of the cities.
We can address these issues by editing the location and style of the cities data layer. We will do this in
the next section.
Part 4 – Editing Data
You ended part 3 with labeled cities, but with a few problems that need addressing. We can move the
location of the circles representing the cities, thereby changing the location where the labels are placed.
We accomplish this by editing the cities data set. It is important to note that when we edit the placement
of the circles, it permanently changes the data set. Therefore, if you want to preserve the original file, you
would want to make a backup copy of it now.
In order to change the location of the circles, we follow this five-step process:
1.
2.
3.
4.
5.
Select the data set you wish to edit in the Table of Contents.
Turn on Editing Mode.
Edit the data.
Save the edits.
Turn off Editing Mode.
We will follow these four steps to move the circles for both Corpus Christi and Agua Dulce.
1. In the Table of Contents, Click the ‘Cities in Nueces County’ once to select it.
Page 13 of 15
2. On the menu bar, Click Layer  Toggle Editing, or click the ‘Toggle Editing’ button on the
‘Digitizing’ toolbar.
3. Turn on the ‘Digitizing’ toolbar if it is not visible.
a. To turn on a toolbar, click View  Toolbars and check the box next to the name of the
toolbar you wish to turn on.
4. On the ‘Digitizing’ toolbar, click ‘Move Feature(s).
5. Click on the circle representing Corpus Christi on the map and drag it on to Corpus Christi.
a. To clarify, you will click the circle, and while holding down the mouse button, drag the
circle. As you drag, a red square will appear under your mouse cursor while you are
dragging. Release the mouse button to place the circle in its new location.
6. The circle and label will now be located where you stopped dragging the circle. It should look
something like the map below. (Map is cropped to just Corpus Christi area)
7. Repeat Step 5 to move the circle representing Agua Dulce slightly to the East until you can see
the entire label.
8. Click ‘Save Edits’ button on the ‘Digitizing’ toolbar to make the changes permanent to the data
set.
a. Note that there is also a second save icon on the ‘File’ toolbar. Make sure to only press
the save button next to the ‘Toggle Editing’ button on the ‘Digitizing’ toolbar!
9. Click ‘Toggle Editing’ button on the ‘Digitizing’ toolbar to turn off editing.
You have successfully editing your first geospatial data set. Note that there are other buttons on the
‘Digitizing’ toolbar that let you add new features, delete existing features, copy features, and so on. Let’s
add a missing city to the map using the ‘Add Feature’ button.
1. With the cities layer selected in the Table of Contents, turn on Editing Mode.
2. Click ‘Add Feature’ button on the ‘Digitizing’ toolbar.
Page 14 of 15
3. Click on the small grouping of roads between Robstown and Agua Dulce on the map to add the
city of ‘Banquete’. Reference the map below to see where the city is located.
4. When you click the map, you will be prompted to fill out the attributes. Enter the following:
a. SOURCE: <your name>
b. NAME: Banquete
c. DATE_PUBLI: <today’s date>
d. SOURCE_LEV: NULL
e. CALSSIFA: City
5. Click OK to save the attributes. The city should now be shown on the map with the city name’s
label.
6. Save your edits.
7. Turn off Editing Mode.
Now that we have all of the cities labeled, let’s make the circles invisible so we just see the labels.
1.
2.
3.
4.
Open the properties dialog of the “Cities in Nueces County” data layer.
Click ‘Style’ tab.
Change Size to 0.00
Click OK to accept the style changes.
You now have a basic map of Nueces County using freely available GIS data. There is much, much more
you can do, but this will do for now.
Part 5 – Saving the Project File
Now that you have composed a map in QGIS, you will want to save your work so you can share it or
open it at a later time. To accomplish this, you will save the Project to disk. The Project file saves the
list of data layers, the symbology choices, and customizations that you have made to the software.
1) To save the current project, on the Menu Bar, click File  Save Project.
2) Choose a location to save the Project file. It is recommended that you save the Project file in a folder
close in the hierarchy to the data on the map if possible.
a) For instance, if I have the lab folder in C:\Lab 3\ on my hard disk, then I would make a new
directory C:\Lab 3\Map Documents\ to store my Project file. I would then save the Project file
into C:\Lab 3\Map Documents\ so it is close to the data layers.
3) Name your Project file then click Save. QGIS project files have the extension .qgs.
Page 15 of 15
Important Note! The data layers are not saved in the Project file. The Project file simply links to the
data layers stored on disk. Because of this, it is imperative that you
1) keep the same folder structure if you choose to move the project to another location on your
disk, or to another computer
2) save the project with relative path names.
There are two types of paths that you can store with your project: absolute and relative.


Absolute path names store the entire path to a file on a specific computer. For instance, on my
computer, my project would be stored at: C:\Lab 3\Map Documents\Tutorial Map.qgs
Relative path names store the path to a file from the Project file. For instance, on my computer,
my project file would point to the aerial photo in this way: ..\Corpus Christi SE DOQQ.tif
o Note that it does not specify the drive (C:\) even the name of the parent directory. It
simply knows that it needs to navigate up one directory (..\) to find the aerial photo.
To set relative or absolute path names for your Project file, do the following:
1) On the Menu Bar, click Settings => Project Properties then select the General tab.
2) For the “Save paths” option, select “relative”.
3) Click OK and then save your project.
With relative path names set and the Project file saved in a folder in the same folder hierarchy as the data
layers, you can safely move the folders containing the data layers and project file to a new computer or
disk drive and not break any data links. If you open a project and the data links were broken due to
movement of the project files, QGIS will prompt you to show it where each data layer is located. Follow
the prompts to reconnect the data to the Project file.
Part 6 – Closing Remarks
This tutorial showed the basic operations of a GIS: display of geographic information, accessing of the
associated attribute information, labeling features, and editing data. As you have probably guessed, there
are many more capabilities to be explored in future tutorials, but for now, you have the basics to get you
started. The quickest way to become fluent in GIS software, such as QGIS, is to experiment and explore
the software. Make a copy of your data and experiment with the copy of the data. If you are unsure as to
what a function does, read the QGIS 1.8.0 manual.