Vous êtes sur la page 1sur 43

Beginning QGIS

Chapter 1 The Basics of Quantum GIS


Introduction
By now you are probably comfortable adding information to OpenStreetMap. And you may be starting to wonder how you can use all the data youve collected. Luckily there are many great tools for analyzing data and designing maps. In this tutorial we will learn how to use Quantum GIS, or QGIS, a free, open-source application for working with geographic data. In this chapter, we will go through the steps necessary to download and install QGIS. Youll learn the basics of different types of data formats, and how to start navigating around your maps. In later chapters, well discuss some of the more advanced features of Quantum GIS. By the end of the tutorial, we hope youll have a good understanding of how to: 1. 2. 3. 4. 5. 6. 7. Get Data Add Data to QGIS Examine the Attributes of Your Geographic Data Join Files Together to Attach Private Data to Public Add Styles and Change the Design of Your Map Print Your Map Link Images to Your Geodata

1. Get Quantum GIS If you have the Quantum GIS installation file on a USB drive or DVD you can skip ahead to Section 2 - Install Quantum GIS If you dont have QGIS already, or want the newest version, open your web browser - this may be Firefox, Chrome, Opera, or Internet Explorer. In the address bar at the top of the window, enter the following text and press Enter: http://qgis.org/ The website should look something like this:

Click Download Now Free!

If you are using Windows click on 1.1 Standalone Installer (recommended for new users).

If you are not using Windows, select your Operating System from the menu. Click on Download QGIS 1.7.0 (the numbers may be different if there is a newer version)

When the file is downloaded, run it and follow the instructions to install Quantum GIS.

2. Install Quantum GIS Find the QGIS installation file on your computer, and double-click it to begin setup.

Follow the installation instructions. Click Next, I Agree, Next, and Install.

QGIS will begin to install. It may take a few minutes to complete.

Click Finish to complete the installation. You can now open QGIS from your Start Menu.

Quantum GIS should look something like this:

3. Download and Open Shapefiles in QGIS The first step to making your own map is to get all of the data that you will need. In this tutorial, we will see how to access OpenStreetMap data and open it in QGIS. There are several ways to do this, but for our purposes we will download what are called extracts. Extracts are files created for different areas of the world by cutting the geodata from that area and putting it into a single file. Its much easier to work with a small file with only the data that we need, rather than trying to work with much larger files. One of the most common file formats are shapefiles. Shapefiles are a common type of file for geodata, and are commonly used with GIS applications like Quantum GIS. We will download our extracts in shapefile format, since it is the most convenient format to use. In your web browser go to http://download.geofabrik.de/osm. The shapefiles are organized by continent and by country. Navigate to a country that you are interested in, and click on any file that ends in shp.zip. In this example we will use the geodata from Indonesia, which can be downloaded at http://download.geofabrik.de/osm/asia/indonesia.shp.zip

When the download has completed, find the file on your computer. Right-click and choose Extract All... This should unzip the files so that they are ready to be opened in QGIS.

Return to Quantum GIS. Since you have just downloaded a group of shapefiles, you are now able to add these to your map and view them. When you add a single shapefile to QGIS, it becomes what is called a layer. When you add multiple files, you will have multiple layers. You can then order these layers so that certain layers appear in front of others. For example, you would probably want your layer of roads to appear in front of your layer of rivers, since roads generally go over rivers. Lets start by adding our shapefiles into QGIS as layers. Click on the Add Vector Layer button in QGIS, which looks like this: A dialog box will appear that allows you to choose files to add into your QGIS project.

Click Browse and navigate to the shapefiles that you downloaded and extracted. You can select multiple shapefiles to load by holding control on your keyboard and clicking on different files. As you might expect, the file named roads.shp contains all the roads, natural.shp contains natural features such as forests and lakes, and so forth.

After you select the shapefiles that you would like to view, Click Open. Click Open again on the Add vector layer dialog. You should now see your layers listed on the left, and you will see the data shown in the main window on the right. If you would like to follow along with this example, open the files buildings, natural, points, and roads.

4. Look at the Data Now lets see how we can navigate our data and examine the attributes. It is important to know that each layer that is open contains many features. A feature is an object that is saved in the layer. For example, every point that is saved in the points layer is an individual feature. Every road or part of a road that is saved in the roads layer is also a feature. Each feature has a group of attributes, such as its name and type. In the buildings layer, every individual building is a feature and has its own attributes, and we will be able to click on any building feature on the map and see its attributes. 4.1 Navigate the Map Before we examine the attributes of individual features, lets take a quick look at how to navigate the map. The main controls for moving the map around and zooming in and out are by default on the panels at the top of QGIS.

When you click on one of these buttons, it changes what you can do with your mouse in the main map window. Select the first button that looks like a hand. Now hold your left mouse button down and drag your mouse in the map window. This allows you to pan the map, or move it around. The second button, which has a plus sign below a magnifying glass, allows you to zoom in on the map. Select this button. Using your mouse, draw a box around an area that you want to zoom in on, and release your mouse. The third button, which has a minus sign below a magnifying glass, allows you to zoom out on the map. Select this button and click on the map. This allows you to zoom out. The button that looks like a magnifying glass with red arrows pointing away from it lets you zoom to the full extent of your map. When you click this button, you will be able to see all of the data that you have loaded in your project.

4.2 Inspect Features Using the Zoom Button, zoom in somewhere on the map where you can see many features.

In this image, we can see a close-up look of the map. On the left panel are a list of the layers that we have loaded. Beneath each layer name is an icon that tells us how the features in that layer are displayed on the map. In this example, the yellow square beneath the buildings layer indicates that these features are polygons, or shapes, and that they are colored yellow on the map. Similarly, features in the natural layer are also polygons, and they are colored purple. The features in the points layer are displayed as points, not polygons, and they are represented by green dots. Lastly,

the roads layer is neither polygons nor points, but rather lines. The roads are represented on our map by thin purple lines.

You can see that each layer has many different features displayed on our map. There are many different purple lines, for example, each representing a different road. Each purple dot represents a different feature in the points layer, that is, a different place on the map. Now lets see how we can inspect these features. To see the attributes of a single feature, we simply need to select the layer that we want on the left, and then click on an object using the Identify Features tool. Click on roads on the layers panel on the left. Then on the top panel of QGIS, click on the Identify Features tool, which looks like this:

Now click on any road feature on the map. When you click on a road a window will pop up and display the attributes for that feature.

In this example, we can see that there is a list of attributes for this road. We can see that the name is Ciputat Raya, the type is primary, and the ID number from OpenStreetMap is 32122647. Practice clicking on different features in different layers and examining their attributes.

4.3 Attribute Table Examining individual features is very useful, but what if we want to see the attributes of ALL the features in a layer? Fortunately, there is a way to do just this. On the layers panel on the left side of QGIS, right-click on any of the layers and click Open attribute table. In this example we will look at the points layer.

You should see a window open that looks a lot like a spreadsheet. This is a list of all the features contained in the layer, along with all of their attributes.

At the top of the window you can see the attributes that features in this layer contain. They are osm_id, timestamp, name, and type.

Summary
Whew! That was a lot to take in! Take a deep breath and relax. By now you should have a good understanding of the basic operations of QGIS, and you can start playing with it and practicing these techniques. In the next chapter we will look more in depth at the attribute table and how you can manipulate it to find, analyze, and select features in your data. Well also learn how to add additional data to your shapefiles and how to create your own layers and save your own shapefiles.

Beginning QGIS
Chapter 2 Managing Your Data
Introduction
In the previous chapter you got started with QGIS, learning how to install it on your computer and how to open and explore your first data files. In this chapter well move ahead, taking a longer look at the attribute table and its uses. We will learn how to join a CSV file to a shapefile so that we can analyze additional data in QGIS. Finally, well learn how to create our own layers and shapefiles.

1. Get the Sample Data In Chapter 1 we downloaded real data from OpenStreetMap as a shapefile extract and opened it in QGIS. While this will probably be your normal way of getting your data files, for the remainder of this tutorial we will be using sample data files to demonstrate operations in QGIS. To follow along with us, open your browser to http://www.learnosm.org/files/. Click on beginningqgis-samples.zip to download the sample data. When the download has completed, find the file on your computer. Right-click and choose Extract All... This should unzip the files so that they are ready to be opened in QGIS. Go back to QGIS. If you still have layers open from the previous chapter, remove them now. To remove a layer, right click on the layer in panel on the left side and click Remove

Now lets add the sample shapefiles that we just downloaded. Click on the Add Vector Layer button in QGIS. Click Browse and navigate to the sample files that you downloaded and extracted.

Open building.shp. This file contains all of the sample building features.

NOTE: These sample files are real data extracted from OpenStreetMap. Some of the data contained within them, however, is falsified for the purposes of this tutorial and for the privacy of the areas inhabitants. 2. Managing the Attribute Table At the end of the previous chapter we opened up the attribute table for one of our layers. Lets open it now for the buildings layer we just added, and examine the attributes of our features. As you did before, right click on the buildings layer and click Open attribute table. You should see this:

The attribute table shows you all the data in whatever file you are looking at. Each line, or row, represents a different feature, which corresponds to a feature on the map. In this example, each building that you see on the map has its own row in the attribute table. The attribute table has multiple columns, which each contain a certain attribute. The attribute table is similar to an Excel spreadsheet or a chart. The attribute table is very useful for sorting your data based on its attributes, selecting specific objects, and finding objects you are looking for. 2.1 Sorting the Data At the top of each column youll see the name of the attributes that are contained in that column. In this file they are name, use, structure, walls, roof, levels, user, timestamp, and id. Using the attribute table we can sort the features according to any of these columns. With your mouse click the top of the column where it says walls. You will see the list is now sorted alphabetically by this category.

Clicking walls a second time will again sort the list by that column, but will reverse the order. Try clicking on other column headings to see how it sorts the data. Note that fields marked as NULL are empty. This means that data was never collected for this feature and added to OpenStreetMap. By sorting the attribute table this way it makes it easier to find the features you are looking for. For example, if you want all the houses that have roofs made of tin, you can sort by roof and then select those listed as tin, as well demonstrate next.

2.2 Selecting Features You can select features in numerous ways, both via the map and via the attribute table. First lets look at how we can select them using the attribute table. Looking at the attribute table, you should see that each row has a number to the left of the row. If you click on one of these numbers, you will select that feature. Try it now.

Now select multiple entries by holding the SHIFT key on your keyboard, and clicking on another row number. By doing this you will select all of the rows between your two clicks. If you want to add rows one by one, hold the CONTROL key and click on all the row numbers that you want.

What if we want to find all the features that have a roof made out of tin? Of course, we could sort the attribute table by the roof category and then select all the entries that say tin, but there is an easier way. Look at the bottom of the attribute table. You should see the words Look for and an empty box. Click in the empty box and type tin (without the quotes). Then to the right of the box, select roof from the menu. Click the Search button, and all the features that have the word tin in the roof column will be automatically selected.

2.3 Other Operations Now lets see how we can go look at a feature after selecting it in the attribute table. First, lets clear the selection so that nothing is selected. In the bottom left corner of the attribute table click on the button that says Unselect all. It looks like this: Now select one feature by clicking on one of the row numbers. Click the button at the bottom that looks like a magnifying glass. This button will zoom your map to the selected feature. Minimize the attribute table by clicking in the upper right corner.

You probably see a big rectangle now on your map. This is because you have zoomed in to see the outline of the single building that you selected. Select the Zoom Out tool and click several times on the map to see more of the neighboring buildings.

You can see that one of them is a different color than the others. This is because it is currently selected.

While we are looking at the map, lets see how to select features from the map. Click on the following button located just above the map window. This is the Select Tool. Now you can click on buildings to select them.

To select many features at once, click on the down arrow next to the button and click on Select features by rectangle. Now you can draw a box around many buildings and select them all. After you have selected them, you will be able to see them selected when you look at your attribute table.

3. Joining a CSV to a Shapefile Table You may have data that is supposed to be connected, but you have it in two separate files. This may be because one of the files contains private data, such as health information and the other contains public data, such as building locations. Its easy to connect two files such as these in QGIS. In this section well look at how to connect two different attribute tables using one shared attribute. This is a called a join. 3.1 Loading a CSV into Quantum GIS CSV stands for comma separated value, which is a kind of file that stores data in a simple text file where each value is separated from the next by a comma. For example, a csv file storing information on people might look something like this:

This is a simple way to store data and it does contain any information about the geographic location of places. However, when one of the columns in our shapefiles matches a column in a CSV file, we are able to join the two together. In the sample folder there is a file called sample_join.csv. We are able to join this to our building layer because both files have a column with the OpenStreetMap ID number of the feature. You can see here that sample_join.csv contains three columns - id, well_access, and favorite animal. This is a data table that ties some fictional information to real features in our buildings layer.

Even though CSV files are very different from Shapefiles, we can open them the same way in QGIS. The only difference is that the CSV file wont show up on the map, because it doesnt have any geographic information in it. However, we will be able to see it in our Layers panel. Open the CSV file by clicking on the Add Vector Layer button at the top of QGIS. When trying to locate the file you may not see it if QGIS is set to only display the Shapefiles. Click in the box at the bottom and find the one that reads Comma Separated Value, as shown below:

Open the file. You should now see it in your Layers panel.

3.2 Joining the Files Together Right-click on the the building layer and open the Properties menu.

Find the tab on the top that says Joins.

Click the + button to add a new join. Choose the following settings:

This means that you want to join the file named sample_join, using the column named id in that file, and the column named id in the building file. Click OK. Click OK again to exit the Properties menu.

3.3 Examining the Attributes Now open the attribute table again for the building layer. Note that if you already had it open, you need to close it and re-open it again. You should now see the data from the sample_join.csv file in your attribute table. It has been successfully joined to your shapefile. The new columns you will see are id, well_access, and favorite_animal. These are the three columns that were in the CSV file and are now joined to your shapefile.

4. Create Separate Layers The last thing we will discuss in this chapter is how to create separate layers. Lets say, for example, that we have a layer called points that has many features covering an entire country, but we only want to work with the points in a certain area, and we want dont want all the features outside of our area on our map. Or we want to create a file with only buildings where the roof is made out of tin. To do this, we can select the features that we are interested in from a layer, and save them as a new shapefile. First lets select the features in a certain area. To do this click the drop down box next to the Select Tool and click Select features by rectangle.

Make sure that the layer that you want to save features from is selected in the layers panel. Use your mouse and draw a rectangle around the area you want to select. This will select all features in that area from the layer that is selected. In this example we will select the building layer and draw a box to select all the buildings in a certain area. After you have selected the buildings, right-click on building in the Layers panel. Click Save selection as...

In the dialog that appears, you will be able to change the file type of the new layer, as well as the filename.

You can see that by default the file will be saved as a shapefile, which is the same file format that we opened at the start of this tutorial. Next to Save as, click Browse and find a location to save your shapefile. Name the file building-my-area. Click OK. Open your new shapefile, building-my-area.shp, the same way you opened shapefiles previously. You will see it appear in the layers panel.

Hide the other layers by clicking the boxes next to each layer that are marked with an X. Zoom out, and you will see that the building-my-area layer only contains the buildings that you saved from your area.

Summary
Congratulations! Youve taken another big step in becoming proficient with Quantum GIS. You know how to navigate the attribute table, how to select features, how to join a CSV file to a Shapefile, and how to export new files based on your selections. In the next chapter we dive into the fun stuff. We will learn how to change the colors of our map, and add layers and symbols to it as well.

Beginning QGIS
Chapter 3 Adding Labels to Your Maps
Introduction
In the previous chapter you learned a bit more about how to manage your data and how to join multiple layers together. In the next two chapters, well take a good look at how you can change the styling of your data, editing colors, placing symbols, and adding labels to features. Using this we can make our data look however we want, and once we can do this, we will be ready to print our freshly designed map. This chapter will deal with how to add labels to your features. Its quite simple to add labels, but the more you would like to customize them, the more advanced some of the techniques become. If youve been following along successfully so far, you shouldnt have a problem learning these techniques. We will only note that section 5. Advanced Labeling takes a few big steps at once. If you dont quite understand it, dont worry - youll understand the basics by then and you can always return later when you have a more thorough understanding of QGIS.

1. Load the Data Before we label and style our data, lets make sure we have all the files open that we will be working with. If you still have the files open from the previous chapter, go ahead and close building-myarea.shp. Open all the shapefiles from the sample directoy, and make sure that you have joined the attributes of building.shp with sample_join.csv. Your layers panel will looks something like this:

Rearrange the layers so that those that should appear below other layers are lower on the list. For example, waterways should be displayed underneath roads, but above landuse. You can drag the layers up or down by clicking on them with your mouse, holding your mouse button down, and dragging them where they belong. When the layers are in the proper order they should look something like this:

Typically its best to have large polygon features shown below lines, and points on the top. This way if a road and a forest intersect the road will be shown above the forest, rather than being covered up by it.

2. Adding Labels When we look at our map, it is nice to see the points, lines, and shapes of our objects, but it might be nice to identify what they are without needing to select each one and look at its attributes. For this we can add labels to our map. Labels can be turned on for as many layers as we like, and we can choose any attribute to be displayed next to the feature on the map. Lets begin by adding labels to the layer points. Each feature in points has an attribute called name, which we will use as our label. Go the the Layers menu at the top of QGIS and click Labeling or click on the Labeling button on the toolbar, which looks like this:

You should see a window open like this:

Click the box next to the words Label this layer. Next to Field with labels, choose name.

Click the Apply button in the bottom right of the window, and you will see labels added to all the points on your map that have a name.

3. Styling Labels Our labels are good now, and they are useful, but we may want to make them look different by styling them. Lets edit how the words are displayed to make our labels look nicer.

By changing the different options on the Label Settings tab (shown above), we can change the way the label is displayed. Lets walk through the different options: Font - Click on this button to change the font, that is, the style of text shown in the label. There are many different font options here with different types of text. Color - Click this button to change the color of the text. Size - Change the size of the text. In points / In map units - If you choose In points from the box next to the font size, your labels will appear at the same size no matter how closely you are zoomed in on your map or how far you are zoomed out. If you choose In map units the size of your labels are relative to the map, and will appear smaller the further you zoom out. Buffer - Check this box to buffer the label with a colored background. This can make your labels more noticeable, but may also cause more clutter on your map. Look below at the difference between a label with a buffer and one without.

Scale-based visibility - This allows you to enter a range at which the labels will be visible. For example, if you dont want all the labels for your points displaying when you are zoomed out very far from them, you can edit this section. Notice at the very bottom of QGIS there is written the word Scale, followed by the number 1, a colon, and another number.

The second number represents the scale of the map, which is related to how far zoomed in or out you are. If you zoom out, the number will get larger; zoom in and it gets smaller. Well, when you are adding labels, the fields in scale-based visibility tell QGIS at what scale, or what zoom level you want the label to be visible at. If the scale of our map is 1:712 and we change the minimum value to 1000, we will no longer see the labels until we zoom out.

Practice editing these settings and see how they affect your map. When you want to apply your changes to the map, click Apply or OK.

4. Positioning Labels Now that we can add and style our labels, its time to look at an important piece of making our maps look good - positioning the labels. We want to be able to display our labels in ways that make sense for the people looking at our map. Our labels should be clear and legible, and put the most emphasis on those features that our audience will most want to see.

Click on the Advanced tab at the top of the window. Edit the Placement settings to change where the label is in relation to the feature. For our points layer we can choose to place the labels around point or over point. The first places the label to the size of the point, and second places it right on top. If you choose around point, you can specify the distance away from the point in the Label distance field on the right. Try editing these settings, clicking Apply, and seeing how they affect your label placement. Under Priority there is a slider bar that you can set anywhere on the scale from Low to High. If you set it high, this means that the labels from this layer will take priority over labels from other layers. So if two layers overlap and have labels in the same area, the layer with a higher setting here will take precedence.

The Advanced tab of the labeling window is a little bit different when you want to label line and polygon features. This is because labels are customarily shown in other ways for roads and shapes. With a road, for

example, we probably want the label to follow the contours of the line. With a building, we may want the label to appear in the middle of the building, so that it is clear what the label refers to. Lets take a look at the labeling of lines and shapes. First we will try labeling the roads layer. Close the labeling window if you havent already. Select the roads layer from the layers panel and open the labeler again. Check Label this layer and choose name as the field. Click Apply. On the map you will see any roads that have name have it now showing along the line of the street.

You can edit the font, color, size, and buffer of the labels the same as you did with the points layer. But for now, switch to the Advanced tab. Youll notice that it is a little bit different than it was for the points.

Notice that there are now three option for placement of the labels - parallel, curved, and horizontal. parallel - draws the labels in a straight line, but along the same path as the feature curved - draws the labels in a curved line along the feature. This is a good option for dealing with very curved features like rivers or windy roads horizontal - draws the labels straight across horizontally, same as the points On the right are several more placement options: above line - places the label above the line on line - places the label directly in the middle of the line below line - places the label below the line If you choose above line or below line, you can set the distance from the line in the Label distance field.

Now lets see the difference when labeling the building layer.

Close the labeling window if you havent already. Select the building layer from the layers panel and open the labeler again. Check Label this layer and choose roof as the field. Click Apply. On the map you will see any buildings that have the roof attribute are now showing it. Weve zoomed in the the image below to give a closer look.

You can edit the font, color, size, and buffer of the labels the same as you did with the points layer. But for now, switch to the Advanced tab. The labels that we just added are all over the place, and nobody would be able to make sense of it by looking at them. Click on horizontal (slow) and Apply to display the labels in a more sensible location. Feel free to experiment with the other options.

5. Advanced Labeling All of the options discussed so far for labeling are great, but there will sometimes be cases when you want even more control over your labels. In this case you have the option of setting some (or as many as you like) of your labels manually. This means that for any individual label you can move, rotate, and edit the settings of the label. Well warn you now that this involves some tricks that you havent dealt with yet. Still its not too difficult, so even if it doesnt quite make sense, you should be able to understand the basic process. In order to allow our features to have labels that we can individually control, we first must add columns to our attribute table to hold the information associated with the labels. At a minimum we will need new

attribute table columns for the x and y position of the label and one column for the rotation of the label. Once our table has these fields, we will be able to move or rotate any label manually. Its also possible to add a number of other columns to hold information such as font, size, and buffer, which can then be edited manually, but in this section we will only worry about how we can move and rotate our labels manually. 5.1 Adding Columns to the Attribute Table Close the labeling window if you have it open. Open the attribute table for the points layer. In order to add columns to our table, we will need to switch into editing mode. Click the Toggle editing mode button at the bottom of the attribute table

Youll see that some of the adjacent buttons are no longer grayed out. Click the one marked New column.

In the Name field, type x. Choose Decimal number (real) under Type, and set the width to 10.

Click OK. Youll see a new column named x appear, with NULL entered for every feature.

Repeat the same process and add columns named y and rotation. Your attribute table will look something like this:

Now we must tell the labeling engine about our new fields. Close the attribute table and open the labeling window again. Click on the tab Data defined settings. Scroll to the bottom and choose x, y, and rotation as shown below:

Click OK.

5.2 Moving & Rotating Labels Now we can manually move and rotate our labels in the points layer. To move a label, click on the Move Label button next to the Labeling button. You may notice that this button was grayed out before, but now it is active because you have added the x and y fields and because you are in editing mode.

Click and drag any label to another location. Remember you can only move the points labels, not labels from other layers. If you open the attribute table again you will see that the x and y fields for one of your labels have numbers in them. Features that have numbers in these fields are features that you have manually moved. Features that have NULL in these fields have not been set manually, and will be set according to your default label settings. Rotate labels the same way, except instead of the Move Label button click on the Rotate Label button.

The fourth and final label button, Change Label, allows you to change any attributes of the label at one time. Here you can change the font, size, and so on, but remember that you need to identify fields for this data in the attribute table first.

Summary
Great! Weve stepped into the wonderful world of labeling, from the very basics to the most detailed. Youll be creating beautiful, clean and crisp maps in no time! In the next chapter we do a bit more with style, editing colors and symbols of our features. Take a deep breath!

Beginning QGIS
Chapter 4 Adding Style to Your Maps
Introduction
In the previous chapter you took a crash course in labeling your features. In this section, well continue to improve the styling of our data, this time editing colors and placing symbols, further customizing the look of our map. Well also see how its possible to import custom symbols into QGIS, and provide some tips on how you can even make your own.

1. Changing Styles Aside from adding labels, we can also change the way the features themselves look on our map. This means changing colors for shapes and colors and thickness for line features. For points, we can change color, size, and even the icon representing the feature. First lets look at how we can change the colors of our features. 1.1 Changing a Line Layer Lets look at how we can change the colors of our roads layer. Since our roads are made up of lines, we will be able to change the color and the thickness of the lines. Right-click on roads in the layers panel, and open the Properties window. Click on the tab that says Style.

To change the color of the roads, click on the button that says Change and select a new color for the roads. When youve selected a color click OK. Now lets change the width of the road lines. Click on the up arrow in the box next to the word Width and increase the width of the roads a little bit.

Click Apply at the bottom of the Properties window. You should now see your changes reflected on the map.

Look again at the Style tab. Notice at the bottom there are many existing styles that are already available within QGIS. Using these styles can help us make our map looks very nice.

Try making changes to the building and points layers. Notice the different options that are available with shapes, lines and points.

Note: You may have noticed in the Properties window that there is a tab called Labels. This is a different way to label features from the way we explored in chapter 3. The labeler in the properties window, however, is less refined and has fewer options, so while it is still possible to use, the aforementioned method is preferable. 1.2 Applying Different Styles Based on Attributes Often we will want to change the style of our features based on their different attributes. In this example, we will see how we can change the style of our roads based on the type of each road. We can change the style based on any attributes in a layer, and make them appear differently on the map. Right-click on roads in the layers panel, and open the Properties window. Click on the tab that says Style. In the upper left corner of the window, click where it says Single Symbol and change this to Categorized.

In the box next to the word Column, choose type. At the bottom left of the window, click Classify. You will now see a list of all possible values that are contained in the type field of the roads layer. In the column labelled Symbol, you can see the style associated with those features. Double click on the line next to word primary.

In the window that pops up we can change the color and thickness of only the roads that are of the type primary. Change the color and the width to be thicker.

Repeat this for other categories in the list so that your Symbols look different.

When you are satisfied click OK. You should now see your roads appear with different styles.

Try changing the other layers that you have loaded. Can you make the buildings different colors based on their attributes?

2. Changing Icons 2.1 Changing the Icon for Points The default icon for out points layer is a circle, but we can easily change this too. Open the Layer Properties for your points layer. On the Style tab, click the button that says Change...

Here you can change the size and color of the icon, and you can also choose a different shape.

2.2 Using Your Own Icons It is also possible to use your own icons, so you wont be limited by the icons provided by QGIS. You may be able to find icons for use on the internet, or you can even design your own. We wont cover how to create and find icons in this tutorial, bit if you have icons in the .svg format you will be able to add them to QGIS. To enable additional icons, click Settings on the top menu and then Options...

On the Rendering tab, scroll to the bottom to the section labelled SVG paths. Click Add. You can now select a folder on your computer that contains .svg files that you want to use. Click OK and your icons will now be available when you are editing your style.

3. Exporting Your Map as an Image In the next chapter, we will learn how to design and print our map. But what if we want to quickly export an image of our map? Go to File -> Save as Image...

Enter a name for the image file, select a location, and click Save. Its that simple! Youll now be able to open the image file on your computer.

Summary
In this section we covered how to change the styles and symbols of our map. In the next chapter we will learn how to finish preparing our map, and get it ready for printing.

Beginning QGIS
Chapter 5 Printing Your Map
Introduction
In the previous chapter you learned how you can style your data to make it look more attractive and to highlight the things that you want to show. We explored changing the colors, labels, and icons of features, and concluded by exporting an image of our map. Now that you have practiced making your maps look good, lets take the next step and see how we can prepare our maps for printing.

1. Finish Styling Your Map Before preparing your map for printing, you should finish styling it the way you want. Weve gone ahead and made some stylistic changes to our sample map from the previous chapter, as shown below. We wont go through all the steps necessary to reach this point, but with the methods you learned you should be able to style your map similarly. In case you are interested, weve edited the points layer to show different symbols for mosques, hospitals, and fuel points, and the roads and landuse layers based on the type field. We will use this map to highlight which houses are constructed in which way, hence we have styled the buildings layer to show different colors based on the type of construction. In our final printed map, we want something that not only looks pretty, but shows our information in a meaningful way.

2. Open the Print Composer and Add Your Map Once we have our map looking pretty good, we are ready to prepare it for printing. To do this, we will open the Print Composer function in QGIS, which provides us with a simple interface for preparing our printout. Go to the menu at the top of QGIS labeled File and select New Print Composer.

On the right side you will see a section labeled Paper and quality. Here you can select the size and orientation of the paper you will print on. For this exercise we will choose A4 size paper in a landscape orientation. The left size of the print composer represents the paper you will be printing on. We will learn how to add several things to our page, but first we need to place our map. To do so, click the Add new map button, which looks like this:

Draw a rectangle on the page by clicking with the left mouse button, dragging the mouse over, and releasing the mouse. This will place your map on the page. You can edit the size and shape of your rectangle by dragging the corners after you have placed it.

By default, the map shown in the rectangle you draw is the same that was shown in main program window. To move the map that is on display, click Move item content button and drag the map

from within the rectangle. To zoom further in or out, scroll your mouse while the pointer is above the map rectangle. Unfortunately, there is no easy way to change the zoom using a laptop touchpad so its better to set the necessary zoom before opening the print composer.

3. Add Additional Elements Next to the map you may want to add some additional elements to provide more information, such as a map legend and title. Lets add a few more features to our printout to make it nice and more informative. 3.1 Adding a Title (or other text) Click on the Add new label button at the top of the Print Composer.

Click at the top of the page above the map. This will create a text field that you can edit to say whatever you want. You can expand the size of the box by dragging the corners. On the panel to the right of the page, click on the tab labeled Item.

You can edit the text here, as well as the font and font color. Lets edit our text to say Our Building Map, and edit the font to be a little more obvious. After increasing the size of the text, we may need to make the text box larger in order to see it.

3.2 Adding a Legend Click on the Add new vect legend button at the top of the Print Composer.

Click in an empty space on the page to create the legend. On the panel to the right of the page, click on the tab labeled Item.

You can edit some various settings here, including the text at the top of the legend and the font, but lets focus on editing what is shown on the legend. Click Legend items at the bottom of the panel.

Now we can edit what information is shown on our legend. When designing the legend, its important to ask, what information will somebody need to make sense of this map? Our map has different icons, buildings sorted by color, and roads identified by different colors and thicknesses. Since the main information we want to convey is which buildings are confined masonry and which are unreinforced masonry, it will be best to put that at the top of the legend, with the points and roads below. We see under legend items a list that looks like this:

This list shows how the legend will look on our page. If you look closely you can see that the legend on the page reflects what is shown here. First we want to put the information about buildings first, so lets move buildings above points. To do so, click on buildings, and then click on the blue arrow pointing up. Now our buildings layer is at the top of the list, and we should see this change reflected in the legend. Since we dont need to show information about the waterways, natural, and landuse layers, lets remove them from the legend. Click on each item in the list and then click on the minus button. By clicking on the + button next to each item on the list, we can look at a list of all the items shown on the legend within that section. Well use the minus button again to remove some of the entries that dont appear on the map we are printing. After all this our map looks like so:

If youd like to change the color of the legends frame or its background, you can do so by clicking on the Item options sub-tab at the bottom of the window. Note that these options are available to all the objects on your page, but may be available under General options instead. Try editing the colors and see how it spices up your map! Heres an example:

3.3 Adding an Image You can also add an image to your map page, such as your organizational logo. To do so, click the Add image button and click somewhere on the page.

Click the ... button next to Load at the bottom of the Item tab.

Navigate to your image and add it to the map.

4. Print and Save Now were ready to print our map. But first, since weve done so much work to style the page and make it look nice, lets save it so that we can use the same settings later when we want to print a map again. 4.1 Save the Template Click on the Save as Template button in the upper right.

Navigate to a location to save the file and give it a name. Click Save. Next time you want to print a map that with a similar legend, logo, and title, you can can load this template and save yourself plenty of time. To load a template, use the Load From template button.

4.2 Print To print your map, simply connect your computer to a printer and click the Print button.

You can also export the map as a PDF file or an image file. For these exports use the buttons for Export as Image and Export as PDF. Its possible to export as an SVG file, although this may not be fully working, so if you need an image its better to use Export as Image.

Summary
Excellent! Hopefully you now have a good idea of how to prepare your map for printing, making it look good, and printing it. In the next chapter well get away from styling our map and take a look at one of the plugins we can add to provide additional functionality to QGIS. In this case, we will set up a feature that will allow us to attach photos to our data.

Beginning QGIS
Chapter 6 Attaching Photos to Your Maps
Introduction
In the previous chapter we saw how to print out a good looking map. In this section, we will discuss how to add plugins to QGIS. A plugin is an additional feature that doesnt come with the QGIS software, but that we can easily add. Once we learn how to add plugins to QGIS, well focus on one in particular, called eVIS. Using this added feature, well be able to link our data with photographs, so that we can attach images to any piece of data we collect.

1. Install the eVis Plugin 8. The first thing we need to do is install a plugin to extend the functionality of QGIS. To do this, go to the top menu and click Plugins -> Manage Plugins.

Youll see a window appear with a list of different plugins that you can activate. If you type eVis into the Filter box, you should see the plugin that we are going to use.

Check the box next to the plugin to activate it, and click OK.

A quick word about what the eVis plugin does. Youre aware now that each of your data layers has an attribute table, and that attribute table has a number of columns with different information in them. Well, its possible for us to add another column to our table, and the location of a file that we want to associate with any object. We can then use the eVis plugin to access that file. This means that we can attach photos on our computer to points on our map, and we can use the eVis plugin to look at the photos. 2. Add a Column and Enter Links for Images Since we are mostly using OpenStreetMap data in these tutorials, its not usually a good idea to make edits to the data in QGIS, since the edits wont be synchronized with OSM. However, for this exercise well make a few small edits to our buildings layer. Well add a column in the attribute table for our photo locations, and then add photos in for some of the buildings. 2.1 Add a Column Open the buildings file if you dont still have it open, and open the attributes table. Do this by rightclicking on the layer and clicking Open attribute table. In order to add information to our table, we will need to switch into editing mode. Click the Toggle editing mode button at the bottom of the attribute table.

Youll see that some of the adjacent buttons are no longer grayed out. Click the one marked New column.

In the Name field, type file. Choose Text (string) under Type, and set the width to 100.

Click OK. Youll see a new column named file appear, with NULL entered for every feature.

2.2 Add Links for the Photos Now lets add the link for a photo. Double-click in the first row where it says NULL. This allows us to edit the field.

We need to add the location of the photo we want to link on our computer. In the sample directory, the photos are in a folder named bld-pics, so to add the first photo to the first feature, we simply type bld-pics/DSC_0551 into the field.

Enter bld-pics/DSC_0552 and bld-pics/DSC_0553 for the following features. When you are finished, click the Toggle editing mode button again.

A dialog will appear asking whether you want to save the changes. Click Save. Close the attribute table.

Note that weve put the location of the photos as what are called relative locations, meaning that the location of the photos is relative to the location of the buildings file. So, if we were to move either the photos or the buildings file to another place on the hard drive, they may no longer be linked properly, unless they are moved together. 3. Setup eVis Now we are ready to use eVis to view the photos associated with our features. But eVis needs to know a couple of things first. It needs to know which column we are using to link to our photos, and it needs to know what type of links we are using. In our case, we are using relative links. On the top menu of QGIS go to Plugins -> eVis -> eVis Event Browser. Click the Options tab at the top. Under the File path section, the first field indicates which column will be used to link the photo. Change this to file, which is the name of the column we just created. Check the box next to Path is relative.

4. Viewing the Photos Click the Display tab at the top of the eVis Event Browser window. You should see the attributes for the first feature in the buildings layer, along with the photo that we attached.

Click Next and you will move to the next feature. Since weve only attached photos to three of our features, the fourth will not show a photo.

5. The eVis Event Id Tool An more convenient tool to look at photos is available. On the top menu go to Plugins -> eVis -> eVis Event Id Tool. The mouse cursor will change to a pointer with an i next to it. Using this tool you can click on a feature on the map, and the event browser will come up showing the features data and the attached photograph. In our example case its unlikely that we can click on a random building and find one with a photograph, but if you saved photos for all the features in a layer this would be a convenient way to access the information.

Summary
You should have a good understanding now of how you can link photographs to your data. Taking this further, it is also possible to link to photos saved on the internet, so that more than one person can access the same images in their data. There are many possibilities, and we hope youll be able to use this to help make finding information easier.

Vous aimerez peut-être aussi