Making a Map with Vector Data
In this module, you will create a basic map which will be used later as a basis for further demonstrations of QGIS functionality.
Objectives
- Add layers and start building an example map.
- Navigate the Map Canvas.
- Understand symbology.
Vector Data
What is vector data? Vector data provide a way to represent real world features within the GIS environment. Vector features have attributes (stored in attribute tables), which consist of text or numerical information that describe the features. A vector feature has its shape represented using a geometry. The geometry is made up of one or more interconnected vertices. The organization of the vertices determines the type of vector that we are working with: point, line, or polygon. A vertex describes a position in space using an X, Y and an optional Z axis. The X and Y values will depend on the Coordinate Reference System (CRS) being used. A CRS is a way to accurately describe where a particular place is on the earth’s surface. One of the most common reference systems is the WGS84 longitude and latitude framework. Lines of longitude run from the North Pole to the South Pole. Lines of latitude run from the East to West. You can describe precisely where you are at any place on the earth by giving someone your longitude (X) and latitude (Y). You can transform data from one CRS to another to maintain continuity between data sets, which is important for analysis.
Vector Data Format
Vector data can come in many different formats. For this workshop, we will use the Shapefile format (.shp
) that stores the geographic coordinates of each vertex in the vector, as well as metadata including:
- Extent: the spatial extent of the shapefile (i.e. geographic area that the shapefile covers). The spatial extent for a shapefile represents the combined extent for all spatial objects in the shapefile.
- Object type: whether the shapefile includes points, lines, or polygons.
- Coordinate reference system (CRS)
- Other attributes: for example, a line shapefile that contains the locations of streams might contain the name of each stream.
Because the structure of points, lines, and polygons are different, each individual shapefile can only contain one vector type (all points, all lines or all polygons). You will not find a mixture of point, line and polygon objects in a single shapefile.
[IMAGE points lines polygons]
Exercise 1.1. Initialize the study area map.
For this exercise, we will make a study area map of the island of Puerto Rico. You can skip step 1 - that part was already done for you! It is written out for your reference on how to collect data.
- You can skip this step. Go to the DIVA-GIS website and search for
Puerto Rico
.- Download administrative boundaries, rivers (inland water), roads, population, and elevation.
- Extract the zip files to the data folder stored in your training directory.
- Open QGIS and start a new project. You will have a new, blank map. Save the project in the
intro-gis-data/analysis
folder and name itpr-study-area-map
. - The Data Source Manager dialog allows you to choose the data to load depending on the data type. We’ll use it to load our dataset: click the [IMAGE data source button]
Open Data Source Manager
button. - Load in the initial vector data.
- In the
Data Source Manager
window, select theVector
tab. - Select
File
as theSource Type
. - Press the
...
button next toVector Dataset(s)
. - Navigate to
intro-gis-data/PRI_adm
and select thePRI_adm0.shp
file. ClickOpen
. The file should now be loaded in theData Manager
window. [IMAGE loaded vector file] - Press
Add
. Now repeat steps 3 and 4 to load in thePRI_adm1.shp
file. Once you have added both files, pressClose
to close the window. Save the project. [IMAGE loaded adm layers]
- In the
Databases allow you to store a large volume of associated data in one file. You may already be familiar with a database management system (DBMS) such as Libreoffice Base or MS Access. GIS applications can also make use of databases. The GeoPackage
open format is a container that allows you to store GIS data (layers) in a single file (e.g. ESRI Shapefile format). A single .gpkg
file can contain various data (both vector and raster data) in different coordinate reference systems, as well as tables without spatial information; all these features allow you to share data easily and avoid file duplication.
Exercise 1.2.
In order to load a layer from a GeoPackage, you will first need to create the connection to it:
- Open the
Data Source Manager
. - On the left, click on the
GeoPackage
tab. - Click on the
New
button and browse to thepr-cities-towns.gpkg
file in theintro-gis-data
folder. - Select the file and press Open. The file path is now added to the Geopackage connections list, and appears in the drop-down menu.
Now that you have established a connection to the file, you can add the layer to the map canvas.
- Press
Connect
. In the central part of the window you should now see the list of all the layers contained in the GeoPackage file. - Select the
pr_large_cities
layer and pressAdd
. The selected layer is added to the Layers panel with features displayed on the map canvas. - Press
Close
to close the window. Save the project.
[IMAGE added geopackage]
There are other types of data layers that you can add to the QGIS map canvas, as evidenced by the different tabs in the Data Source Manager
. Learn more about these types in the QGIS User Manual.
You can choose to turn layers on and off by clicking on the checkbox next to the layer name, or reorder the layers by dragging the name to your desired spot. The layers are displayed in the order that they are listed (i.e., top of the list of layers displayed on top and vice versa).
Symbology
The symbology of a layer is its visual appearance on the map. The basic strength of GIS over other ways of representing data with spatial aspects is that with GIS, you have a dynamic visual representation of the data you’re working with. The end user of the maps you produce should easily understand what the map represents.
Exercise 1.3. Customize the study area map.
Before we customize the colors and structures, let’s add a bit more context to the map.
- Follow the instructions from Exercise 1.1 to add
intro-gis-data/PRI_wat/PRI_water_lines_dcw.shp
andintro-gis-data/PRI_rds/PRI_roads.shp
to the map canvas. [IMAGE rivers roads]
To change a layer’s symbology, open its Layer Properties
. Let’s begin by changing the color of the PR_adm0
layer.
- First, turn off the
PR_adm1
layer by unchecking the box next to its name. - Right-click on the
PR_adm0
in the layers list. - Select the
Properties...
option in the menu that appears. Alternatively, you could also access a layer’s properties by double-clicking on the layer in the Layers list. - In the
Layer Properties
window, select theSymbology
tab. Click on the elementSimple Fill
below theFill
dropdown at the top of the window. - Next to
Fill Color
, select a color to fill in the Puerto Rico boundary layer. [IMAGE color customization] - You can press
Apply
to test out the color you chose, or else just pressOK
to save the customization. - Repeat steps 3-7 to change the colors for the
pr_large_cities
,PRI_roads
, andPRI_water_lines_dcw
layers.
You can also change the structure of a layer, i.e., how the layer object appears. Next, let’s change the appearance of the PRI_roads
layer.
- Follow steps 3-5 to open the
Symbology
tab for thePRI_roads
layer. - Click on the dropdown menu next to the
Stroke Style
field and choose theDash Dot Line
option. PressOK
. Save the project.
Finally, let’s add labels to the cities layer so it’s easier to read the map.
- Right-click on
pr_large_cities
and chooseProperties...
. - Click on the
Labels
tab. - Click on the dropdown menu at the top of the window and choose the
Single Labels
option. - Next to the
Value
field, choosename
. - In the
Text
tab option, set10.0
as the font size. - Click on the
Placement
tab within theLabels
window and increase theDistance
field to0.1000
. PressOK
.
Now that you’ve got a map, you need to be able to print it or to export it to a document. Both exporting and printing is handled via the Print Layout. QGIS allows you to create multiple maps using the same map file. For this reason, it has a tool called the Layout Manager.
Exercise 1.4. Generate a printable map layout and export as a PDF.
- Click on the
Project > Layout Manager...
menu entry to open the tool. You’ll see a blank Layout manager dialog appear. [IMAGE blank layout manager] - Under
New from Template
, selectEmpty layout
and press theCreate...
button. You could also create this new layout via theProject > New Print Layout...
menu. - Name the new layout
pr-study-area-map
and clickOK
. - You will now see the Print Layout window: [IMAGE blank print layout window]
- Right-click on the sheet in the central part of the layout window and choose
Page properties...
in the context menu. - Check that the values in the
Item Properties
tab are set to the following:- Size: A4
- Orientation: Landscape.
- Now you’ve got the page layout the way you wanted it, but this page is still blank. It clearly lacks a map.
- Click on the
Add Map
button. With this tool activated, you will be able to place a map on the page. - Click and drag a box on the blank page. The map will appear on the page.
- Go to the
Layout > Save Project
. This is a convenient shortcut to the one in the main dialog.
Now, add the title.
- Click on the
Add Label
button. - Click on the page, above the map, accept the suggested values in the
New Item Properties
dialog, and a label will appear at the top of the map. - Resize it and place it in the top center of the page. It can be resized and moved in the same way that you resized and moved the map. However, there is also an
Alignment
tool in theActions Toolbar
to help position the title relative to the map (not the page). - Select the label by clicking on it.
- Click on the Item Properties tab in the side panel of the layout window.
- Change the text of the label to Puerto Rico Rivers, Roads, and Major Cities.
- Use this interface to set the font and alignment options under the
Appearance
section.
Next, add a legend.
- Click on the
Add Legend
button. - Click on the page to place the legend, accept the suggested values in the
New Item Properties
dialog. - A legend is added to the layout page, showing layers symbology as set in the main dialog. As usual, you can click and move the item to where you want it.
- In the
Item Properties
tab, you’ll find theLegend Items
group. - Uncheck the
Auto update
box, allowing you to directly modify the legend items. Remove thePR_adm1
layer from the legend by clicking the red minus sign. - You can also rename items. Select a layer from the same list. Double-click on the layer. Rename the layers to Land, Roads and Streets, Surface Water, Rivers, etc.
Finally, add a north arrow and scale bar.
- Click on the
Add North Arrow
button. - Drag a box where you want the north arrow to appear.
- Click on the
Add Scale Bar
button. - Drag a box where you want the scale bar to appear.
Finally, the map is ready to export! Click on the Export as PDF
button and save the file in intro-gis-data/outputs
as pr-study-area-map
. Click Save
if a pop-up box appears. Close the window.