QGIS Tutorial 2 - Adding Vector Layers

Jeremy M. Mikecz

2019

498 Home Syllabus Schedule Mikecz Home Tutorials

In this tutorial, you will begin working with a vector layer of international boundaries. By the end of this tutorial you should be able to create a map that looks like this:

per capita GDP, Atlantic region
per capita GDP, Atlantic region
Same map layer, zoomed in. Notice country layers now appear at this scale. Also note, the transparency of the gdppc layer allows the visibility of the topography and major water bodies in this region.
Same map layer, zoomed in. Notice country layers now appear at this scale. Also note, the transparency of the gdppc layer allows the visibility of the topography and major water bodies in this region.

Download and Import Country Borders

  1. From the #datasets thread in Slack, download the country borders folder (“ne_50m_admin_0_countries”). Unzip it. Copy and paste this folder into a logical folder (i.e. Documents/QGIS/countries).

  2. From QGIS, import this layer:
    1. Layer–>Add Layer–>Add Vector Layer
    2. Set encoding to “UTF-8”
    3. Next to the “Vector Dataset(s)” bar select the ellipses (…) to find and import your countries datafile (from the “ne_50m_admin_0_countries” folder open the shapefile [.shp]: “ne_50m_admin_0_countries.shp”).
  3. You should now see the new countries layer in your QGIS project. If you cannot see it on the map, take a look at the Layers panel to make sure it is on top. If not use the up-arrow symbol to move your new countries layer to the top of the list. Your map view should now look something like this:

with the countries layer
with the countries layer

Working with Vector Layers / shapefiles

  1. We now have our vector layer of country boundaries.

Exploring a shapefile’s attributes.

To view the attributes (data fields / variables and their values) for the new countries layer, right-click the countries map layer and select Open Attribute Table. Examine what data is available for each country in this geospatial dataset.

Add a new variable or attribute

  1. With the Attribute table for the Countries shapefile open, click the pencil to enter Edit Mode.

    Create new attribute
    Create new attribute
  2. Next, select the New Field symbol (with a small yellow star). Name the new field “gdppc” (for GDP per capita) and fill out the rest of the fields for the attribute as follows:

    1. Type is the type of variable (integer, number, text, etc.)
    Set attributes
    Set attributes
    1. For real numbers, length is the maximum length of characters and precision is the number of decimals. For example, if you choose a field length of 10 and a field precision of 3, it means you have 6 digits before the dot, then the dot and another 3 digits for the precision.

    2. press OK

    3. Select your new “gdppc” column and select the field calculator symbol (looks like an abacus). Then fill out the Field Calculator as follows:

    Field Calculator
    Field Calculator
    1. Note: you can select attributes (variables) in the country shapefile from the menu in the center. To calculate per capita GDP we need to divide GDP by the population. However, the GDP_MD_EST is an estimate of GDP in millions of dollars. Hence, to calculate per capita GDP we divide GDP by population and then multiply by 1,000,000.
  3. Now that we have created a new per capita GDP attribute, we want to display this data on our map. We can do so by doing the following:

Fill and Outline Color

  1. Let’s start by removing the fill color and only preserving the outlines of the countries:

    1. Open the Symbology window for your new layer (right click on the countries layer in the Layer panel –> Properties –> Symbology tab)

    2. From the Fill Style menu select “no brush” to remove the fill.

    3. You may now change the color and width of the country outlines by changing the settings on the stroke style and stroke width menus.

    4. Click Apply when you have finished your changes. Close the window and return to your map to see the results.

Display labels

  1. First, we want to add labels to our countries.

    1. Open the Symbology window again for the countries layer.

    2. Select the Labels tab.

    3. From the drop-down menu select single labels.

    4. We need to choose the variable from the Countries shapefile dataset to display as the label. In this case we will choose “Admin” from the Label with menu.

    5. Choose an appropriate font, font size, and font color to display your labels. Click Apply when done to view the results.

    6. Close the Symbology window to see the results.

  2. Second, let’s change the settings of the labels so they only appear when zoomed in beyond a certain point. To do so, we must do the following:

    1. Open the Symbology window again for the Countries layer.

    2. Open the Labels tab.

    3. Select Rendering from the menu of options

    4. Enable Scale dependent visibility. In the zoom out box (magnifying glass with minus ‘-’) type “1:10000000” (1 to 10 million)

    Setting scale dependent rendering for country labels
    Setting scale dependent rendering for country labels
    1. Select OK.

    2. Review the map now by zooming in and out to different scales. You should not be able to see the country labels until you have zoomed in to 1:10,000,000. You can see the scale at the bottom of the map window.

    QGIS map at approx. 1:19M scale (note the country labels now appear again).
    QGIS map at approx. 1:19M scale (note the country labels now appear again).
  3. In addition, you may want to change the placement of labels. From the same Labels tab, click on Placement in the center menu. I used the Free (slow) selection which allowed for the placement of labels on diagonals, among other things. Choose the setting you prefer.

Set Country Fill Colors by Attribute

  1. For the Countries layer, open the Symbology tab in the Properties window.

  2. Fill out the settings as follows:

    1. In the top menu, select Graduated.

    2. Select a monochrome color ramp (i.e. “Greens” or “Reds”)

    3. Experiment with different ways to assign class breaks. For example, you can choose between different modes of class breaks (Equal Interval, Quantile, Natural Breaks, Pretty Breaks, etc.) and different numbers of classes (click here for more on data classification methods). You may also view the histograms of this data (click load values to load histograms) to manually set class breaks.

    My preliminary choices to classify and map GDP, per capita
    My preliminary choices to classify and map GDP, per capita
    1. Press Apply to see the results of your different choices. When you have decided on the proper setting, press OK.

Change transparency of top layer

  1. To increase the transparency of your top map layer (GDP, per capita) in order to also view the ESRI shaded relief layer, open the Symbology window (remember, to do so, right-click the map layer, select Properties –> symbology tab).

  2. Select the arrow next to Layer rendering in the symbology window. Experiment with different opacity levels (opacity is the inverse of transparency; 70% transparent = 30% opaque) until finding a setting that still clearly shows global differences in GDP yet also allows some of the relief map layer to appear beneath. Your final result should look something like the maps at the top of the page (but with your choice of colors / transparency / label settings).

  3. Per capita GDP is an indicator of the prosperity of an economy. Thus, much of this map may not be a surprise. North America and Europe are relatively prosperous and Africa is not (according to this measure). But, do you notice any patterns that surprise you?

Assignment:

After completing your new map of global GDP, per capita, export the map (Project–>Import/Export–>Export Map to Image). Submit this to your instructor.