Search icon CANCEL
Arrow left icon
Explore Products
Best Sellers
New Releases
Books
Videos
Audiobooks
Learning Hub
Conferences
Free Learning
Arrow right icon
Arrow up icon
GO TO TOP
QGIS:Becoming a GIS Power User

You're reading from   QGIS:Becoming a GIS Power User Master data management, visualization, and spatial analysis techniques in QGIS and become a GIS power user

Arrow left icon
Product type Course
Published in Feb 2017
Publisher Packt
ISBN-13 9781788299725
Length 819 pages
Edition 1st Edition
Languages
Tools
Arrow right icon
Authors (4):
Arrow left icon
Anita Graser Anita Graser
Author Profile Icon Anita Graser
Anita Graser
Víctor Olaya Ferrero Víctor Olaya Ferrero
Author Profile Icon Víctor Olaya Ferrero
Víctor Olaya Ferrero
Alex Mandel Alex Mandel
Author Profile Icon Alex Mandel
Alex Mandel
Ben Mearns Ben Mearns
Author Profile Icon Ben Mearns
Ben Mearns
Arrow right icon
View More author details
Toc

Chapter 2. Viewing Spatial Data

In this chapter, we will cover how to view spatial data from different data sources. QGIS supports many file and database formats as well as standardized Open Geospatial Consortium (OGC) Web Services. We will first cover how we can load layers from these different data sources. We will then look into the basics of styling both vector and raster layers and will create our first map, which you can see in the following screenshot:

Viewing Spatial Data

We will finish this chapter with an example of loading background maps from online services.

Note

For the examples in this chapter, we will use the sample data provided by the QGIS project, which is available for download from http://qgis.org/downloads/data/qgis_sample_data.zip (21 MB). Download and unzip it.

Loading vector data from files

In this section, we will talk about loading vector data from GIS file formats, such as shapefiles, as well as from text files.

We can load vector files by going to Layer | Add Layer | Add Vector Layer and also using the Add Vector Layer toolbar button. If you like shortcuts, use Ctrl + Shift + V. In the Add vector layer dialog, which is shown in the following screenshot, we find a drop-down list that allows us to specify the encoding of the input file. This option is important if we are dealing with files that contain special characters, such as German umlauts or letters from alphabets different from the default Latin ones.

Loading vector data from files

What we are most interested in now is the Browse button, which opens the file-opening dialog. Note the file type filter drop-down list in the bottom-right corner of the dialog. We can open it to see a list of supported vector file types. This filter is useful to find specific files faster by hiding all the files of a different type, but be aware that the filter settings are stored and will be applied again the next time you open the file opening dialog. This can be a source of confusion if you try to find a different file later and it happens to be hidden by the filter, so remember to check the filter settings if you are having trouble locating a file.

We can load more than one file in one go by selecting multiple files at once (holding down Ctrl on Windows/Ubuntu or cmd on Mac). Let's give it a try:

  1. First, we select alaska.shp and airports.shp from the shapefiles sample data folder.
  2. Next, we confirm our selection by clicking on Open, and we are taken back to the Add vector layer dialog.
  3. After we've clicked on Open once more, the selected files are loaded. You will notice that each vector layer is displayed in a random color, which is most likely different from the color that you see in the following screenshot. Don't worry about this now; we'll deal with layer styles later in this chapter.
    Loading vector data from files

Even without us using any spatial analysis tools, these simple steps of visualizing spatial datasets enable us to find, for example, the southernmost airport on the Alaskan mainland.

Tip

There are multiple tricks that make loading data even faster; for example, you can simply drag and drop files from the operating system's file browser into QGIS.

Another way to quickly access your spatial data is by using QGIS's built-in file browser. If you have set up QGIS as shown in Chapter 1, Getting Started with QGIS, you'll find the browser on the left-hand side, just below the layer list. Navigate to your data folder, and you can again drag and drop files from the browser to the map.

Additionally, you can mark a folder as favorite by right-clicking on it and selecting Add as a favorite. In this way, you can access your data folders even faster, because they are added in the Favorites section right at the top of the browser list.

Another popular source of spatial data is delimited text (CSV) files. QGIS can load CSV files using the Add Delimited Text Layer option available via the menu entry by going to Layer | Add Layer | Add Delimited Text Layer or the corresponding toolbar button. Click on Browse and select elevp.csv from the sample data. CSV files come with all kinds of delimiters. As you can see in the following screenshot, the plugin lets you choose from the most common ones (Comma, Tab, and so on), but you can also specify any other plain or regular-expression delimiter:

Loading vector data from files

If your CSV file contains quotation marks such as, " or ', you can use the Quote option to have them removed. The Number of header lines to discard option allows us to skip any potential extra lines at the beginning of the text file. The following Field options include functionality for trimming extra spaces from field values or redefine the decimal separator to a comma. The spatial information itself can be provided either in the two columns that contain the coordinates of points X and Y, or using the Well known text (WKT) format. A WKT field can contain points, lines, or polygons. For example, a point can be specified as POINT (30 10), a simple line with three nodes would be LINESTRING (30 10, 10 30, 40 40), and a polygon with four nodes would be POLYGON ((30 10, 40 40, 20 40, 10 20, 30 10)).

Note

Note that the first and last coordinate pair in a polygon has to be identical.

WKT is a very useful and flexible format. If you are unfamiliar with the concept, you can find a detailed introduction with examples at http://en.wikipedia.org/wiki/Well-known_text.

After we've clicked on OK, QGIS will prompt us to specify the layer's coordinate reference system (CRS). We will talk about handling CRS next.

Dealing with coordinate reference systems

Whenever we load a data source, QGIS looks for usable CRS information, for example, in the shapefile's .prj file. If QGIS cannot find any usable information, by default, it will ask you to specify the CRS manually. This behavior can be changed by going to Settings | Options | CRS to always use either the project CRS or a default CRS.

The QGIS Coordinate Reference System Selector offers a filter that makes finding a CRS easier. It can filter by name or ID (for example, the EPSG code). Just start typing and watch how the list of potential CRS gets shorter. There are actually two separate lists; the upper one contains the CRS that we recently used, while the lower list is much longer and contains all the available CRS. For the elevp.csv file, we select NAD27 / Alaska Albers. With the correct CRS, the elevp layer will be displayed as shown in this screenshot:

Dealing with coordinate reference systems

If we want to check a layer's CRS, we can find this information in the layer properties' General section, which can be accessed by going to Layer | Properties or by double-clicking on the layer name in the layer list. If you think that QGIS has picked the wrong CRS or if you have made a mistake in specifying the CRS, you can correct the CRS settings using Specify CRS. Note that this does not change the underlying data or reproject it. We'll talk about reprojecting vectors and raster files in Chapter 3, Data Creation and Editing.

In QGIS, we can create a map out of multiple layers even if each dataset is stored with a different CRS. QGIS handles the necessary reprojections automatically by enabling a mechanism called on the fly reprojection, which can be accessed by going to Project | Project Properties, as shown in the following screenshot. Alternatively, you can click on the CRS status button (with the globe symbol and the EPSG code right next to it) in the bottom-right corner of the QGIS window to open this dialog:

Dealing with coordinate reference systems

All layers are reprojected to the project CRS on the fly, which means that QGIS calculates these reprojections dynamically and only for the purpose of rendering the map. This also means that it can slow down your machine if you are working with big datasets that have to be reprojected. The underlying data is not changed and spatial analyses are not affected. For example, the following image shows Alaska in its default NAD27 / Alaska Albers projection (on the left-hand side), a reprojection on the fly to WGS84 EPSG:4326 (in the middle), and Web Mercator EPSG:3857 (on the right-hand side). Even though the map representation changes considerably, the analysis results for each version are identical since the on the fly reprojection feature does not change the data.

Dealing with coordinate reference systems

In some cases, you might have to specify a CRS that is not available in the QGIS CRS database. You can add CRS definitions by going to Settings | Custom CRS. Click on the Add new CRS button to create a new entry, type in a name for the new CRS, and paste the proj4 definition string in the Parameters input field. This definition string is used by the Proj4 projection engine to determine the correct coordinate transformation. Just close the dialog by clicking on OK when you are done.

Note

If you are looking for a specific projection proj4 definition, http://spatialreference.org is a good source for this kind of information.

Loading raster files

Loading raster files is not much different from loading vector files. Going to Layer | Add Layer | Add Raster Layer, clicking on the Add Raster Layer button, or pressing the Ctrl + Shift + R shortcut will take you directly to the file-opening dialog. Again, you can check the file type filter to see a list of supported file types.

Let's give it a try and load landcover.img from the raster sample data folder. Similarly to vector files, you can load rasters by dragging them into QGIS from the operating system or the built-in file browser. The following screenshot shows the loaded raster layer:

Loading raster files

Note

Support for all of these different vector and raster file types in QGIS is handled by the powerful GDAL/OGR package. You can check out the full list of supported formats at www.gdal.org/formats_list.html (for rasters) and http://www.gdal.org/ogr_formats.html (for vectors).

Georeferencing raster maps

Some raster data sources, such as simple scanned maps, lack proper spatial referencing, and we have to georeference them before we can use them in a GIS. In QGIS, we can georeference rasters using the Georeferencer GDAL plugin, which can be accessed by going to Raster | Georeferencer. (Enable it by going to Plugins | Manage and Install Plugins if you cannot find it in the Raster menu).

The Georeferencer plugin covers the following use cases:

  • We can create a world file for a raster file without altering the original raster.
  • If we have a map image that contains points with known coordinates, we can set ground control points (GCPs) and enter the known coordinates.
  • Finally, if we don't know the coordinates of any points on the map, we still have the chance to place GCPs manually using a second, and already georeferenced, map of the same area. We can use objects that are visible in both maps to pick points on the map that we want to georeference and work out their coordinates from the reference map.

After loading a raster into Georeferencer by going to File | Open raster or using the Open raster toolbar button, we are asked to specify the CRS of the ground control points that we are planning to add. Next, we can start adding ground control points by going to Edit | Add point. We can use the pan and zoom tools to navigate, and we can place GCPs by clicking on the map. We are then prompted to insert the coordinates of the new point or pick them from the reference map in the main QGIS window. The placed GCPs are displayed as red circles in both Georeferencer and the QGIS window, as you can see in the following screenshot:

Georeferencing raster maps

Georeferencer shows a screenshot of the OCM Landscape map © Thunderforest, Data © OpenStreetMap contributors (http://www.opencyclemap.org/?zoom=4&lat=62.50806&lon=-145.01953&layers=0B000)

After placing the GCPs, we can define the transformation algorithm by going to Settings | Transformation Settings. Which algorithm you choose depends on your input data and the level of geometric distortion you want to allow. The most commonly used algorithms are polynomial 1 to 3. A first-order polynomial transformation allows scaling, translation, and rotation only.

A second-order polynomial transformation can handle some curvature, and a third-order polynomial transformation consequently allows for even higher degrees of distortion. The thin-plate spline algorithm can handle local deformations in the map and is therefore very useful while working with very low-quality map scans. Projective transformation offers rotation and translation of coordinates. The linear option, on the other hand, is only used to create world files, and as mentioned earlier, this does not actually transform the raster.

The resampling method depends on your input data and the result you want to achieve. Cubic resampling creates smooth results, but if you don't want to change the raster values, choose the nearest neighbor method.

Before we can start the georeferencing process, we have to specify the output filename and target CRS. Make sure that the Load in QGIS when done option is active and activate the Use 0 for transparency when needed option to avoid black borders around the output image. Then, we can close the Transformation Settings dialog and go to File | Start Georeferencing. The georeferenced raster will automatically be loaded into the main map window of QGIS. In the following screenshot, you can see the result of applying projective transformation using the five specified GCPs:

Georeferencing raster maps

Georeferencing raster maps

Some raster data sources, such as simple scanned maps, lack proper spatial referencing, and we have to georeference them before we can use them in a GIS. In QGIS, we can georeference rasters using the Georeferencer GDAL plugin, which can be accessed by going to Raster | Georeferencer. (Enable it by going to Plugins | Manage and Install Plugins if you cannot find it in the Raster menu).

The Georeferencer plugin covers the following use cases:

  • We can create a world file for a raster file without altering the original raster.
  • If we have a map image that contains points with known coordinates, we can set ground control points (GCPs) and enter the known coordinates.
  • Finally, if we don't know the coordinates of any points on the map, we still have the chance to place GCPs manually using a second, and already georeferenced, map of the same area. We can use objects that are visible in both maps to pick points on the map that we want to georeference and work out their coordinates from the reference map.

After loading a raster into Georeferencer by going to File | Open raster or using the Open raster toolbar button, we are asked to specify the CRS of the ground control points that we are planning to add. Next, we can start adding ground control points by going to Edit | Add point. We can use the pan and zoom tools to navigate, and we can place GCPs by clicking on the map. We are then prompted to insert the coordinates of the new point or pick them from the reference map in the main QGIS window. The placed GCPs are displayed as red circles in both Georeferencer and the QGIS window, as you can see in the following screenshot:

Georeferencing raster maps

Georeferencer shows a screenshot of the OCM Landscape map © Thunderforest, Data © OpenStreetMap contributors (http://www.opencyclemap.org/?zoom=4&lat=62.50806&lon=-145.01953&layers=0B000)

After placing the GCPs, we can define the transformation algorithm by going to Settings | Transformation Settings. Which algorithm you choose depends on your input data and the level of geometric distortion you want to allow. The most commonly used algorithms are polynomial 1 to 3. A first-order polynomial transformation allows scaling, translation, and rotation only.

A second-order polynomial transformation can handle some curvature, and a third-order polynomial transformation consequently allows for even higher degrees of distortion. The thin-plate spline algorithm can handle local deformations in the map and is therefore very useful while working with very low-quality map scans. Projective transformation offers rotation and translation of coordinates. The linear option, on the other hand, is only used to create world files, and as mentioned earlier, this does not actually transform the raster.

The resampling method depends on your input data and the result you want to achieve. Cubic resampling creates smooth results, but if you don't want to change the raster values, choose the nearest neighbor method.

Before we can start the georeferencing process, we have to specify the output filename and target CRS. Make sure that the Load in QGIS when done option is active and activate the Use 0 for transparency when needed option to avoid black borders around the output image. Then, we can close the Transformation Settings dialog and go to File | Start Georeferencing. The georeferenced raster will automatically be loaded into the main map window of QGIS. In the following screenshot, you can see the result of applying projective transformation using the five specified GCPs:

Georeferencing raster maps

Loading data from databases

QGIS supports PostGIS, SpatiaLite, MSSQL, and Oracle Spatial databases. We will cover two open source options: SpatiaLite and PostGIS. Both are available cross-platform, just like QGIS.

SpatiaLite is the spatial extension for SQLite databases. SQLite is a self-contained, server-less, zero-configuration, and transactional SQL database engine (www.sqlite.org). This basically means that a SQLite database, and therefore also a SpatiaLite database, doesn't need a server installation and can be copied and exchanged just like any ordinary file.

You can download an example database from www.gaia-gis.it/spatialite-2.3.1/test-2.3.zip (4 MB). Unzip the file; you will be able to connect to it by going to Layer | Add Layer | Add SpatiaLite Layer, using the Add SpatiaLite Layer toolbar button, or by pressing Ctrl + Shift + L. Click on New to select the test-2.3.sqlite database file. QGIS will save all the connections and add them to the drop-down list at the top. After clicking on Connect, you will see a list of layers stored in the database, as shown in this screenshot:

Loading data from databases

As with files, you can select one or more tables from the list and click on Add to load them into the map. Additionally, you can use Set Filter to only load specific features.

Tip

Filters in QGIS use SQL-like syntax, for example,

"Name" = 'EMILIA-ROMAGNA' to select only the region called

EMILIA-ROMAGNA or "Name" LIKE 'ISOLA%' to select all regions whose names start with ISOLA. The filter queries are passed on to the underlying data provider (for example, SpatiaLite or OGR). The provider syntax for basic filter queries is consistent over different providers but can vary when using more exotic functions. You can read the details of OGR SQL at http://www.gdal.org/ogr_sql.html.

In Chapter 4, Spatial Analysis, we will use this database to explore how we can take advantage of the spatial analysis capabilities of SpatiaLite.

PostGIS is the spatial extension of the PostgreSQL database system. Installing and configuring the database is out of the scope of this book, but there are installers for Windows and packages for many Linux distributions as well as for Mac (for details, visit http://www.postgresql.org/download/). To load data from a PostGIS database, go to Layers | Add Layer | Add PostGIS Layer, use the Add PostGIS Layer toolbar button, or press Ctrl + Shift + D.

When using a database for the first time, click on New to establish a new database connection. This opens the dialog shown in the following screenshot, where you can create a new connection, for example, to a database called postgis:

Loading data from databases

The fields that have to be filled in are as follows:

  • Name: Insert a name for the new connection. You can use any name you like.
  • Host: The server's IP address is inserted in this field. You can use localhost if PostGIS is running locally.
  • Port: The PostGIS default port is 5432. If you have trouble reaching a database, it is recommended that you check the server's firewall settings for this port.
  • Database: This is the name of the PostGIS database that you want to connect to.
  • Username and Password: For convenience, you can tell QGIS to save these.

After the connection is established, you can load and filter tables, just as we discussed for SpatiaLite.

Loading data from OGC web services

More and more data providers offer access to their datasets via OGC-compliant web services such as Web Map Services (WMS), Web Coverage Services (WCS), or Web Feature Services (WFS). QGIS supports these services out of the box.

Note

If you want to learn more about the different OGC web services available, visit http://live.osgeo.org/en/standards/standards.html for an overview.

You can load WMS layers by going to Layer | Add WMS/WMTS Layer, clicking on the Add WMS/WMTS Layer button, or pressing Ctrl + Shift + W. If you know a WMS server, you can connect to it by clicking on New and filling in a name and the URL. All other fields are optional. Don't worry if you don't know of any WMS servers, because you can simply click on the Add default servers button to get access information about servers whose administrators collaborate with the QGIS project. One of these servers is called Lizardtech server. Select Lizardtech server or any of the other servers from the drop-down box, and click on Connect to see the list of layers available through the server, as shown here:

Loading data from OGC web services

From the layer list, you can now select one or more layers for download. It is worth noting that the order in which you select the layers matters, because the layers will be combined on the server side and QGIS will only receive the combined image as the resultant layer. If you want to be able to use the layers separately, you will have to download them one by one. The data download starts once you click on Add. The dialog will stay open so that you can add more layers from the server.

Many WMS servers offer their layers in multiple, different CRS. You can check out the list of available CRS by clicking on the Change button at the bottom of the dialog. This will open a CRS selector dialog, which is limited to the WMS server's CRS capabilities.

Loading data from WCS or WFS servers works in the same way, but public servers are quite rare. One of the few reliable public WFS servers is operated by the city of Vienna, Austria. The following screenshot shows how to configure the connection to the data.wien.gv.at WFS, as well as the list of available datasets that is loaded when we click on the Connect button:

Loading data from OGC web services

Note

The main advantage of using a WFS rather than a WMS is that the Web Feature Service returns vector features, including all their attributes, instead of only an image of a map. Of course, this also means that WFS layers usually take longer to download and cause more load on the server.

Styling raster layers

After this introduction to data sources, we can create our first map. We will build the map from the bottom up by first loading some background rasters (hillshade and land cover), which we will then overlay with point, line, and polygon layers.

Let's start by loading a land cover and a hillshade from landcover.img and SR_50M_alaska_nad.tif, and then opening the Style section in the layer properties (by going to Layer | Properties or double-clicking on the layer name). QGIS automatically tries to pick a reasonable default render type for both raster layers. Besides these defaults, the following style options are available for raster layers:

  • Multiband color: This style is used if the raster has several bands. This is usually the case with satellite images with multiple bands.
  • Paletted: This style is used if a single-band raster comes with an indexed palette.
  • Singleband gray: If a raster has neither multiple bands nor an indexed palette (this is the case with, for example, elevation model rasters or hillshade rasters), it will be rendered using this style.
  • Singleband pseudocolor: Instead of being limited to gray, this style allows us to render a raster band using a color map of our choice.

The SR_50M_alaska_nad.tif hillshade raster is loaded with Singleband gray Render type, as you can see in the following screenshot. If we want to render the hillshade raster in color instead of grayscale, we can change Render type to Singleband pseudocolor. In the pseudocolor mode, we can create color maps either manually or by selecting one of the premade color ramps. However, let's stick to Singleband gray for the hillshade for now.

Styling raster layers

The Singleband gray renderer offers a Black to white Color gradient as well as a White to black gradient. When we use the Black to white gradient, the minimum value (specified in Min) will be drawn black and the maximum value (specified in Max) will be drawn in white, with all the values in between in shades of gray. You can specify these minimum and maximum values manually or use the Load min/max values interface to let QGIS compute the values.

Tip

Note that QGIS offers different options for computing the values from either the complete raster (Full Extent) or only the currently visible part of the raster (Current Extent). A common source of confusion is the Estimate (faster) option, which can result in different values than those documented elsewhere, for example, in the raster's metadata. The obvious advantage of this option is that it is faster to compute, so use it carefully!

Below the color settings, we find a section with more advanced options that control the raster Resampling, Brightness, Contrast, Saturation, and Hue—options that you probably know from image processing software. By default, resampling is set to the fast Nearest neighbour option. To get nicer and smoother results, we can change to the Bilinear or Cubic method.

Click on OK or Apply to confirm. In both cases, the map will be redrawn using the new layer style. If you click on Apply, the Layer Properties dialog stays open, and you can continue to fine-tune the layer style. If you click on OK, the Layer Properties dialog is closed.

The landcover.img raster is a good example of a paletted raster. Each cell value is mapped to a specific color. To change a color, we can simply double-click on the Color preview and a color picker will open. The style section of a paletted raster looks like what is shown in the following screenshot:

Styling raster layers

If we want to combine hillshade and land cover into one aesthetically pleasing background, we can use a combination of Blending mode and layer Transparency. Blending modes are another feature commonly found in image processing software. The main advantage of blending modes over transparency is that we can avoid the usually dull, low-contrast look that results from combining rasters using transparency alone. If you haven't had any experience with blending, take some time to try the different effects. For this example, I used the Darken blending mode, as highlighted in the previous screenshot, together with a global layer transparency of 50 %, as shown in the following screenshot:

Styling raster layers

Styling vector layers

When we load vector layers, QGIS renders them using a default style and a random color. Of course, we want to customize these styles to better reflect our data. In the following exercises, we will style point, line, and polygon layers, and you will also get accustomed to the most common vector styling options.

Regardless of the layer's geometry type, we always find a drop-down list with the available style options in the top-left corner of the Style dialog. The following style options are available for vector layers:

  • Single Symbol: This is the simplest option. When we use a Single Symbol style, all points are displayed with the same symbol.
  • Categorized: This is the style of choice if a layer contains points of different categories, for example, a layer that contains locations of different animal sightings.
  • Graduated: This style is great if we want to visualize numerical values, for example, temperature measurements.
  • Rule-based: This is the most advanced option. Rule-based styles are very flexible because they allow us to write multiple rules for one layer.
  • Point displacement: This option is available only for point layers. These styles are useful if you need to visualize point layers with multiple points at the same coordinates, for example, students of a school living at the same address.
  • Inverted polygons: This option is available for polygon layers only. By using this option, the defined symbology will be applied to the area outside the polygon borders instead of filling the area inside the polygon.
  • Heatmap: This option is available only for point layers. It enables us to create a dynamic heatmap style.
  • 2.5D: This option is available only for polygon layers. It enables us to create extruded polygons in 2.5 dimensions.

Creating point styles – an example of an airport style

Let's get started with a point layer! Load airport.shp from your sample data. In the top-left corner of the Style dialog, below the drop-down list, we find the symbol preview. Below this, there is a list of symbol layers that shows us the different layers the symbol consists of. On the right-hand side, we find options for the symbol size and size units, color and transparency, as well as rotation. Finally, the bottom-right area contains a preview area with saved symbols.

Point layers are, by default, displayed using a simple circle symbol. We want to use a symbol of an airplane instead. To change the symbol, select the Simple marker entry in the symbol layers list on the left-hand side of the dialog. Notice how the right-hand side of the dialog changes. We can now see the options available for simple markers: Colors, Size, Rotation, Form, and so on. However, we are not looking for circles, stars, or square symbols—we want an airplane. That's why we need to change the Symbol layer type option from Simple marker to SVG marker. Many of the options are still similar, but at the bottom, we now find a selection of SVG images that we can choose from. Scroll through the list and pick the airplane symbol, as shown in the following screenshot:

Creating point styles – an example of an airport style

Before we move on to styling lines, let's take a look at the other symbol layer types for points, which include the following:

  • Simple marker: This includes geometric forms such as circles, stars, and squares
  • Font marker: This provides access to your symbol fonts
  • SVG marker: Each QGIS installation comes with a collection of default SVG symbols; add your own folders that contain SVG images by going to Settings | Options | System | SVG Paths
  • Ellipse marker: This includes customizable ellipses, rectangles, crosses, and triangles
  • Vector Field marker: This is a customizable vector-field visualization tool
  • Geometry Generator: This enables us to manipulate geometries and even create completely new geometries using the built-in expression engine

Simple marker layers can have different geometric forms, sizes, outlines, and angles (orientation), as shown in the following screenshot, where we create a red square without an outline (using the No Pen option):

Creating point styles – an example of an airport style

Font marker layers are useful for adding letters or other symbols from fonts that are installed on your computer. This screenshot, for example, shows how to add the yin-and-yang character from the Wingdings font:

Creating point styles – an example of an airport style

Ellipse marker layers make it possible to draw different ellipses, rectangles, crosses, and triangles, where both the width and height can be controlled separately. This symbol layer type is especially useful when combined with data-defined overrides, which we will discuss later. The following screenshot shows how to create an ellipse that is 5 millimeters long, 2 millimeters high, and rotated by 45 degrees:

Creating point styles – an example of an airport style

Creating line styles – an example of river or road styles

In this exercise, we create a river style for the majriver.shp file in our sample data. The goal is to create a line style with two colors: a fill color for the center of the line and an outline color. This technique is very useful because it can also be used to create road styles.

To create such a style, we combine two simple lines. The default symbol is one simple line. Click on the green + symbol located below the symbol layers list in the bottom-left corner to add another simple line. The lower line will be our outline and the upper one will be the fill. Select the upper simple line and change the color to blue and the width to 0.3 millimeters. Next, select the lower simple line and change its color to gray and width to 0.6 millimeters, slightly wider than the other line. Check the preview and click on Apply to test how the style looks when applied to the river layer.

You will notice that the style doesn't look perfect yet. This is because each line feature is drawn separately, one after the other, and this leads to a rather disconnected appearance. Luckily, this is easy to fix; we only need to enable the so-called symbol levels. To do this, select the Line entry in the symbol layers list and tick the checkbox in the Symbol Levels dialog of the Advanced section (the button in the bottom-right corner of the style dialog), as shown in the following screenshot. Click on Apply to test the results.

Creating line styles – an example of river or road styles

Before we move on to styling polygons, let's take a look at the other symbol layer types for lines, which include the following:

  • Simple line: This is a solid or dashed line
  • Marker line: This line is made up of point markers located at line vertices or at regular intervals
  • Geometry Generator: This enables us to manipulate geometries and even create completely new geometries using the built-in expression engine.

A common use case for Marker line symbol layers are train track symbols; they often feature repeating perpendicular lines, which are abstract representations of railway sleepers. The following screenshot shows how we can create a style like this by adding a marker line on top of two simple lines:

Creating line styles – an example of river or road styles

Another common use case for Marker line symbol layers is arrow symbols. The following screenshot shows how we can create a simple arrow by combining Simple line and Marker line. The key to creating an arrow symbol is to specify that Marker placement should be last vertex only. Then we only need to pick a suitable arrow head marker and the arrow symbol is ready.

Creating line styles – an example of river or road styles

Tip

Whenever we create a symbol that we might want to reuse in other maps, we can save it by clicking on the Save button under the symbol preview area. We can assign a name to the new symbol, and after we save it, it will be added to the saved symbols preview area on the right-hand side.

Creating polygon styles – an example of a landmass style

In this exercise, we will create a style for the alaska.shp file. The goal is to create a simple fill with a blue halo. As in the previous river style example, we will combine two symbol layers to create this style: a Simple fill layer that defines the main fill color (white) with a thin border (in gray), and an additional Simple line outline layer for the (light blue) halo. The halo should have nice rounded corners. To achieve these, change the Join style option of the Simple line symbol layer to Round. Similar to the previous example, we again enable symbol levels; to prevent this landmass style from blocking out the background map, we select the Multiply blending mode, as shown in the following screenshot:

Creating polygon styles – an example of a landmass style

Before we move on, let's take a look at the other symbol layer types for polygons, which include the following:

  • Simple fill: This defines the fill and outline colors as well as the basic fill styles
  • Centroid fill: This allows us to put point markers at the centers of polygons
  • Line/Point pattern fill: This supports user-defined line and point patterns with flexible spacing
  • SVG fill: This fills the polygon using SVGs
  • Gradient fill: This allows us to fill polygons with linear, radial, or conical gradients
  • Shapeburst fill: This creates a gradient that starts at the polygon border and flows towards the center
  • Outline: Simple line or Marker line: This makes it possible to outline areas using line styles
  • Geometry Generator: This enables us to manipulate geometries and even create completely new geometries using the built-in expression engine.

A common use case for Point pattern fill symbol layers is topographic symbols for different vegetation types, which typically consist of a Simple fill layer and Point pattern fill, as shown in this screenshot:

Creating polygon styles – an example of a landmass style

When we design point pattern fills, we are, of course, not restricted to simple markers. We can use any other marker type. For example, the following screenshot shows how to create a polygon fill style with a Font marker pattern that shows repeating alien faces from the Webdings font:

Creating polygon styles – an example of a landmass style

As an alternative to simple fills with only one color, we can create Gradient fill symbol layers. Gradients can be defined by Two colors, as shown in the following screenshot, or by a Color ramp that can consist of many different colors. Usually, gradients run from the top to the bottom, but we can change this to, for example, make the gradient run from right to left by setting Angle to 270 degrees, as shown here:

Creating polygon styles – an example of a landmass style

The Shapeburst fill symbol layer type, also known as a "buffered" gradient fill, is often used to style water areas with a smooth gradient that flows from the polygon border inwards. The following screenshot shows a fixed-distance shading using the Shade to a set distance option. If we select Shade whole shape instead, the gradient will be drawn all the way from the polygon border to the center.

Creating polygon styles – an example of a landmass style

Creating point styles – an example of an airport style

Let's get started with a point layer! Load airport.shp from your sample data. In the top-left corner of the Style dialog, below the drop-down list, we find the symbol preview. Below this, there is a list of symbol layers that shows us the different layers the symbol consists of. On the right-hand side, we find options for the symbol size and size units, color and transparency, as well as rotation. Finally, the bottom-right area contains a preview area with saved symbols.

Point layers are, by default, displayed using a simple circle symbol. We want to use a symbol of an airplane instead. To change the symbol, select the Simple marker entry in the symbol layers list on the left-hand side of the dialog. Notice how the right-hand side of the dialog changes. We can now see the options available for simple markers: Colors, Size, Rotation, Form, and so on. However, we are not looking for circles, stars, or square symbols—we want an airplane. That's why we need to change the Symbol layer type option from Simple marker to SVG marker. Many of the options are still similar, but at the bottom, we now find a selection of SVG images that we can choose from. Scroll through the list and pick the airplane symbol, as shown in the following screenshot:

Creating point styles – an example of an airport style

Before we move on to styling lines, let's take a look at the other symbol layer types for points, which include the following:

  • Simple marker: This includes geometric forms such as circles, stars, and squares
  • Font marker: This provides access to your symbol fonts
  • SVG marker: Each QGIS installation comes with a collection of default SVG symbols; add your own folders that contain SVG images by going to Settings | Options | System | SVG Paths
  • Ellipse marker: This includes customizable ellipses, rectangles, crosses, and triangles
  • Vector Field marker: This is a customizable vector-field visualization tool
  • Geometry Generator: This enables us to manipulate geometries and even create completely new geometries using the built-in expression engine

Simple marker layers can have different geometric forms, sizes, outlines, and angles (orientation), as shown in the following screenshot, where we create a red square without an outline (using the No Pen option):

Creating point styles – an example of an airport style

Font marker layers are useful for adding letters or other symbols from fonts that are installed on your computer. This screenshot, for example, shows how to add the yin-and-yang character from the Wingdings font:

Creating point styles – an example of an airport style

Ellipse marker layers make it possible to draw different ellipses, rectangles, crosses, and triangles, where both the width and height can be controlled separately. This symbol layer type is especially useful when combined with data-defined overrides, which we will discuss later. The following screenshot shows how to create an ellipse that is 5 millimeters long, 2 millimeters high, and rotated by 45 degrees:

Creating point styles – an example of an airport style

Creating line styles – an example of river or road styles

In this exercise, we create a river style for the majriver.shp file in our sample data. The goal is to create a line style with two colors: a fill color for the center of the line and an outline color. This technique is very useful because it can also be used to create road styles.

To create such a style, we combine two simple lines. The default symbol is one simple line. Click on the green + symbol located below the symbol layers list in the bottom-left corner to add another simple line. The lower line will be our outline and the upper one will be the fill. Select the upper simple line and change the color to blue and the width to 0.3 millimeters. Next, select the lower simple line and change its color to gray and width to 0.6 millimeters, slightly wider than the other line. Check the preview and click on Apply to test how the style looks when applied to the river layer.

You will notice that the style doesn't look perfect yet. This is because each line feature is drawn separately, one after the other, and this leads to a rather disconnected appearance. Luckily, this is easy to fix; we only need to enable the so-called symbol levels. To do this, select the Line entry in the symbol layers list and tick the checkbox in the Symbol Levels dialog of the Advanced section (the button in the bottom-right corner of the style dialog), as shown in the following screenshot. Click on Apply to test the results.

Creating line styles – an example of river or road styles

Before we move on to styling polygons, let's take a look at the other symbol layer types for lines, which include the following:

  • Simple line: This is a solid or dashed line
  • Marker line: This line is made up of point markers located at line vertices or at regular intervals
  • Geometry Generator: This enables us to manipulate geometries and even create completely new geometries using the built-in expression engine.

A common use case for Marker line symbol layers are train track symbols; they often feature repeating perpendicular lines, which are abstract representations of railway sleepers. The following screenshot shows how we can create a style like this by adding a marker line on top of two simple lines:

Creating line styles – an example of river or road styles

Another common use case for Marker line symbol layers is arrow symbols. The following screenshot shows how we can create a simple arrow by combining Simple line and Marker line. The key to creating an arrow symbol is to specify that Marker placement should be last vertex only. Then we only need to pick a suitable arrow head marker and the arrow symbol is ready.

Creating line styles – an example of river or road styles

Tip

Whenever we create a symbol that we might want to reuse in other maps, we can save it by clicking on the Save button under the symbol preview area. We can assign a name to the new symbol, and after we save it, it will be added to the saved symbols preview area on the right-hand side.

Creating polygon styles – an example of a landmass style

In this exercise, we will create a style for the alaska.shp file. The goal is to create a simple fill with a blue halo. As in the previous river style example, we will combine two symbol layers to create this style: a Simple fill layer that defines the main fill color (white) with a thin border (in gray), and an additional Simple line outline layer for the (light blue) halo. The halo should have nice rounded corners. To achieve these, change the Join style option of the Simple line symbol layer to Round. Similar to the previous example, we again enable symbol levels; to prevent this landmass style from blocking out the background map, we select the Multiply blending mode, as shown in the following screenshot:

Creating polygon styles – an example of a landmass style

Before we move on, let's take a look at the other symbol layer types for polygons, which include the following:

  • Simple fill: This defines the fill and outline colors as well as the basic fill styles
  • Centroid fill: This allows us to put point markers at the centers of polygons
  • Line/Point pattern fill: This supports user-defined line and point patterns with flexible spacing
  • SVG fill: This fills the polygon using SVGs
  • Gradient fill: This allows us to fill polygons with linear, radial, or conical gradients
  • Shapeburst fill: This creates a gradient that starts at the polygon border and flows towards the center
  • Outline: Simple line or Marker line: This makes it possible to outline areas using line styles
  • Geometry Generator: This enables us to manipulate geometries and even create completely new geometries using the built-in expression engine.

A common use case for Point pattern fill symbol layers is topographic symbols for different vegetation types, which typically consist of a Simple fill layer and Point pattern fill, as shown in this screenshot:

Creating polygon styles – an example of a landmass style

When we design point pattern fills, we are, of course, not restricted to simple markers. We can use any other marker type. For example, the following screenshot shows how to create a polygon fill style with a Font marker pattern that shows repeating alien faces from the Webdings font:

Creating polygon styles – an example of a landmass style

As an alternative to simple fills with only one color, we can create Gradient fill symbol layers. Gradients can be defined by Two colors, as shown in the following screenshot, or by a Color ramp that can consist of many different colors. Usually, gradients run from the top to the bottom, but we can change this to, for example, make the gradient run from right to left by setting Angle to 270 degrees, as shown here:

Creating polygon styles – an example of a landmass style

The Shapeburst fill symbol layer type, also known as a "buffered" gradient fill, is often used to style water areas with a smooth gradient that flows from the polygon border inwards. The following screenshot shows a fixed-distance shading using the Shade to a set distance option. If we select Shade whole shape instead, the gradient will be drawn all the way from the polygon border to the center.

Creating polygon styles – an example of a landmass style

Creating line styles – an example of river or road styles

In this exercise, we create a river style for the majriver.shp file in our sample data. The goal is to create a line style with two colors: a fill color for the center of the line and an outline color. This technique is very useful because it can also be used to create road styles.

To create such a style, we combine two simple lines. The default symbol is one simple line. Click on the green + symbol located below the symbol layers list in the bottom-left corner to add another simple line. The lower line will be our outline and the upper one will be the fill. Select the upper simple line and change the color to blue and the width to 0.3 millimeters. Next, select the lower simple line and change its color to gray and width to 0.6 millimeters, slightly wider than the other line. Check the preview and click on Apply to test how the style looks when applied to the river layer.

You will notice that the style doesn't look perfect yet. This is because each line feature is drawn separately, one after the other, and this leads to a rather disconnected appearance. Luckily, this is easy to fix; we only need to enable the so-called symbol levels. To do this, select the Line entry in the symbol layers list and tick the checkbox in the Symbol Levels dialog of the Advanced section (the button in the bottom-right corner of the style dialog), as shown in the following screenshot. Click on Apply to test the results.

Creating line styles – an example of river or road styles

Before we move on to styling polygons, let's take a look at the other symbol layer types for lines, which include the following:

  • Simple line: This is a solid or dashed line
  • Marker line: This line is made up of point markers located at line vertices or at regular intervals
  • Geometry Generator: This enables us to manipulate geometries and even create completely new geometries using the built-in expression engine.

A common use case for Marker line symbol layers are train track symbols; they often feature repeating perpendicular lines, which are abstract representations of railway sleepers. The following screenshot shows how we can create a style like this by adding a marker line on top of two simple lines:

Creating line styles – an example of river or road styles

Another common use case for Marker line symbol layers is arrow symbols. The following screenshot shows how we can create a simple arrow by combining Simple line and Marker line. The key to creating an arrow symbol is to specify that Marker placement should be last vertex only. Then we only need to pick a suitable arrow head marker and the arrow symbol is ready.

Creating line styles – an example of river or road styles

Tip

Whenever we create a symbol that we might want to reuse in other maps, we can save it by clicking on the Save button under the symbol preview area. We can assign a name to the new symbol, and after we save it, it will be added to the saved symbols preview area on the right-hand side.

Creating polygon styles – an example of a landmass style

In this exercise, we will create a style for the alaska.shp file. The goal is to create a simple fill with a blue halo. As in the previous river style example, we will combine two symbol layers to create this style: a Simple fill layer that defines the main fill color (white) with a thin border (in gray), and an additional Simple line outline layer for the (light blue) halo. The halo should have nice rounded corners. To achieve these, change the Join style option of the Simple line symbol layer to Round. Similar to the previous example, we again enable symbol levels; to prevent this landmass style from blocking out the background map, we select the Multiply blending mode, as shown in the following screenshot:

Creating polygon styles – an example of a landmass style

Before we move on, let's take a look at the other symbol layer types for polygons, which include the following:

  • Simple fill: This defines the fill and outline colors as well as the basic fill styles
  • Centroid fill: This allows us to put point markers at the centers of polygons
  • Line/Point pattern fill: This supports user-defined line and point patterns with flexible spacing
  • SVG fill: This fills the polygon using SVGs
  • Gradient fill: This allows us to fill polygons with linear, radial, or conical gradients
  • Shapeburst fill: This creates a gradient that starts at the polygon border and flows towards the center
  • Outline: Simple line or Marker line: This makes it possible to outline areas using line styles
  • Geometry Generator: This enables us to manipulate geometries and even create completely new geometries using the built-in expression engine.

A common use case for Point pattern fill symbol layers is topographic symbols for different vegetation types, which typically consist of a Simple fill layer and Point pattern fill, as shown in this screenshot:

Creating polygon styles – an example of a landmass style

When we design point pattern fills, we are, of course, not restricted to simple markers. We can use any other marker type. For example, the following screenshot shows how to create a polygon fill style with a Font marker pattern that shows repeating alien faces from the Webdings font:

Creating polygon styles – an example of a landmass style

As an alternative to simple fills with only one color, we can create Gradient fill symbol layers. Gradients can be defined by Two colors, as shown in the following screenshot, or by a Color ramp that can consist of many different colors. Usually, gradients run from the top to the bottom, but we can change this to, for example, make the gradient run from right to left by setting Angle to 270 degrees, as shown here:

Creating polygon styles – an example of a landmass style

The Shapeburst fill symbol layer type, also known as a "buffered" gradient fill, is often used to style water areas with a smooth gradient that flows from the polygon border inwards. The following screenshot shows a fixed-distance shading using the Shade to a set distance option. If we select Shade whole shape instead, the gradient will be drawn all the way from the polygon border to the center.

Creating polygon styles – an example of a landmass style

Creating polygon styles – an example of a landmass style

In this exercise, we will create a style for the alaska.shp file. The goal is to create a simple fill with a blue halo. As in the previous river style example, we will combine two symbol layers to create this style: a Simple fill layer that defines the main fill color (white) with a thin border (in gray), and an additional Simple line outline layer for the (light blue) halo. The halo should have nice rounded corners. To achieve these, change the Join style option of the Simple line symbol layer to Round. Similar to the previous example, we again enable symbol levels; to prevent this landmass style from blocking out the background map, we select the Multiply blending mode, as shown in the following screenshot:

Creating polygon styles – an example of a landmass style

Before we move on, let's take a look at the other symbol layer types for polygons, which include the following:

  • Simple fill: This defines the fill and outline colors as well as the basic fill styles
  • Centroid fill: This allows us to put point markers at the centers of polygons
  • Line/Point pattern fill: This supports user-defined line and point patterns with flexible spacing
  • SVG fill: This fills the polygon using SVGs
  • Gradient fill: This allows us to fill polygons with linear, radial, or conical gradients
  • Shapeburst fill: This creates a gradient that starts at the polygon border and flows towards the center
  • Outline: Simple line or Marker line: This makes it possible to outline areas using line styles
  • Geometry Generator: This enables us to manipulate geometries and even create completely new geometries using the built-in expression engine.

A common use case for Point pattern fill symbol layers is topographic symbols for different vegetation types, which typically consist of a Simple fill layer and Point pattern fill, as shown in this screenshot:

Creating polygon styles – an example of a landmass style

When we design point pattern fills, we are, of course, not restricted to simple markers. We can use any other marker type. For example, the following screenshot shows how to create a polygon fill style with a Font marker pattern that shows repeating alien faces from the Webdings font:

Creating polygon styles – an example of a landmass style

As an alternative to simple fills with only one color, we can create Gradient fill symbol layers. Gradients can be defined by Two colors, as shown in the following screenshot, or by a Color ramp that can consist of many different colors. Usually, gradients run from the top to the bottom, but we can change this to, for example, make the gradient run from right to left by setting Angle to 270 degrees, as shown here:

Creating polygon styles – an example of a landmass style

The Shapeburst fill symbol layer type, also known as a "buffered" gradient fill, is often used to style water areas with a smooth gradient that flows from the polygon border inwards. The following screenshot shows a fixed-distance shading using the Shade to a set distance option. If we select Shade whole shape instead, the gradient will be drawn all the way from the polygon border to the center.

Creating polygon styles – an example of a landmass style

Loading background maps

Background maps are very useful for quick checks and to provide orientation, especially if you don't have access to any other base layers. Adding background maps is easy with the help of the QuickMapServices plugin. It provides access to satellite, street, and hybrid maps by different providers.

To install the QuickMapServices plugin, go to Plugins | Manage and Install Plugins. Wait until the list of available plugins has finished loading. Use the filter to look for the QuickMapServices option, as shown in the following screenshot. Select it from the list and click on Install plugin. This is going to take a moment. Once it's done, you will see a short confirmation message. You can then close the installer, and the QuickMapServices plugin will be available through the Web menu.

Loading background maps

Note

Note that you have to be online to use these services.

Another fact worth mentioning is that all of these services provide their maps only in Pseudo Mercator (EPSG: 3857). You should change your project CRS to Pseudo Mercator when using background maps from QuickMapServices, particularly if the map contains labels that would otherwise show up distorted.

Note

Background maps added using the QuickMapServices plugin are not suitable for printing due to their low resolution.

If you load the OSM TF Landscape layer, your map will look like what is shown in this screenshot:

Loading background maps

Tip

An alternative to the QuickMapServices plugin is OpenLayers Plugin, which provides very similar functionality but offers fewer different background maps.

Dealing with project files

QGIS project files are human-readable XML files with the filename ending with .qgs. You can open them in any text editor (such as Notepad++ on Windows or gedit on Ubuntu) and read or even change the file contents.

When you save a project file, you will notice that QGIS creates a second file with the same name and a .qgs~ ending, as shown in the next screenshot. This is a simple backup copy of the project file with identical content. If your project file gets corrupted for any reason, you can simply copy the backup file, remove the ~ from the file ending, and continue working from there.

Dealing with project files

By default, QGIS stores the relative path to the datasets in the project file. If you move a project file (without its associated data files) to a different location, QGIS won't be able to locate the data files anymore and will therefore display the following Handle bad layers dialog:

Dealing with project files

Note

If you are working with data files that are stored on a network drive rather than locally on your machine, it can be useful to change from storing relative paths to storing absolute paths instead. You can change this setting by going to Project | Project Properties | General.

To fix the layers, you need to correct the path in the Datasource column. This can be done by double-clicking on the path text and typing in the correct path, or by pressing the Browse button at the bottom of the dialog and selecting the new file location in the file dialog that opens up.

Tip

A comfortable way to copy QGIS projects to other computers or share QGIS projects and associated files with other users is provided by the QConsolidate plugin. This plugin collects all the datasets used in the project and saves them in one directory, which you can then move around easily without breaking any paths.

Summary

In this chapter, you learned how to load spatial data from files, databases, and web services. We saw how QGIS handles coordinate reference systems and had an introduction to styling vector and raster layers, a topic that we will cover in more detail in Chapter 5, Creating Great Maps. We also installed our first Python plugin, the QuickMapServices plugin, and used it to load background maps into our project. Finally, we took a look at QGIS project files and how to work with them efficiently. In the following chapter, we will go into more detail and see how to create and edit raster and vector data.

You have been reading a chapter from
QGIS:Becoming a GIS Power User
Published in: Feb 2017
Publisher: Packt
ISBN-13: 9781788299725
Register for a free Packt account to unlock a world of extra content!
A free Packt account unlocks extra newsletters, articles, discounted offers, and much more. Start advancing your knowledge today.
Unlock this book and the full library FREE for 7 days
Get unlimited access to 7000+ expert-authored eBooks and videos courses covering every tech area you can think of
Renews at $19.99/month. Cancel anytime