Archive for July, 2018

QGIS 3 Beginner’s Basics Tutorial

Unicorn Map

New to QGIS? Want to learn a few basic techniques? Follow along in the making of this Lisa Frank-esque map to see how it’s done.

Download QGIS if you don’t have it already. Right now we’re on version 3.2, which is what I recommend to download. If you see anything different between that and what I’m showing here let me know, I’ve got 3.3 running for this (via the osgeo network installer, where you can get the very latest development version). If you have an older version of QGIS already running you can probably use it but never fear, you can install multiple versions on the same machine and they’ll run just fine.

Use Natural Earth data for this project. I’ll provide the links to the appropriate datasets as we go. Unfamiliar with Natural Earth? This is the dataset to use when designing maps from world-scale to admin 1 (state)-scale. Note that depending on where you reside and your world-view country and state boundaries could be argued differently. It doesn’t matter what dataset you use, always scrutinize it for accuracy and usefulness for your purpose.

Add the GRAY_LR_SR_OB raster dataset from Natural Earth to an empty QGIS project. Look for the one titled “Gray Earth with shaded relief, hypsography, and ocean bottom, medium-sized.” When you download the data file you’ll see it is made up of several files. Just drag and drop the large TIF file onto the QGIS project to add it.

 

Drag and drop this TIF file

After adding it you see it’s a basic gray hillshade, which is pretty nice as-is. Change the projection to something more suitable for the continental U.S. such as EPSG: 102003. Find the button to do this at the bottom right corner of the QGIS window. Click it and the CRS tab from Project Properties appears, where you can type the code into the filter, select the projection, and click OK.

 

Change the Projection

 

Now the map will look like this:

 

Unmodified hillshade

 

But for this project we want it to be purple with some other modifications. Open the Layer Styling Panel by right-clicking in the toolbar area at the top of the QGIS project and selecting Layer Styling Panel. It will appear on the right side of the project window. This is where you do most of the styling for each layer you add to the project. It auto-updates as you go and keeps a history of edits so that you can return to a previous design state if you desire. In this panel, make the following changes to the hillshade layer:

 

Styling settings

 

The purple color used here is #e19aeb, which you put in the HTML Notation box after clicking on the color drop-down and clicking Choose Color. This kind of color code is also called HEX. You also need to change the opacity of this hillshade so it is even lighter. We don’t want it to overwhelm the unicorns, after all. :) Use the Transparency tab in the Layer Styling Panel for that, like this:

 

gray_transparency

 

The map should now look like this:

 

Modified hillshade

 

Now add ne_10m_admin_0_countries_lakes to the project.

(If you’d prefer adding in this vector layer and the next 3 as a single geopackage that contains all the Natural Earth data, which is recommended if you’ll be doing some experimenting as this way you’ll have more data, use the Natural Earth Starter Kit geopackage, which you also drag-drop onto the QGIS project window and select data from the dialog that pops up.)

This countries layer will mask the U.S. so the unicorns will show up better. Use the Query Builder to filter the data by right-clicking the countries layer, going to the Source tab, and clicking the Query Builder button, entering in the filter “NAME” = ‘United States of America’, which will then appear as shown:

 

U.S. Query

 

Using the Layer Styling panel with the countries layer active in the Layers list, change the fill color to white and the opacity to 70%. The map will now look like this:

 

Countries Mask

 

Now we do much the same thing with the ne_10m_ocean layer, except that we use a dark gray border line and only a 60% opacity, with no filter. The project will then look like this:

 

Ocean Styling Settings

 

Next, add the ne_10m_admin_1_states_provinces_lakes file to the project and change the Fill style to No Brush and set the Stroke color to #6f4486. Now we’ve got:

 

States Styling

 

We can’t forget to put in some color for the Great Lakes. To do this, add the ne_10m_lakes layer and style it with a blue fill color so that it looks something like this:

 

Lakes Styling

 

Duplicate the ne_10m_admin_1_states_provinces_lakes file via right-click as shown:

 

Right Click Options

 

Rename the new duplicated layer to something like “states” (right-click, Rename Layer) and move it to the top of the layer list (drag). Right-click this layer again and choose Open Attribute Table. Click the Toggle editing mode button, which looks like a pencil, then click the New Field button and add a new integer field called rainbow. These buttons and the new field settings are shown here:

 

Add a New Field

 

Click OK and now you have a new field added to the data table. In this section, using tables, you can buy generic drugs online as well as cialis, which will help you if you suffer from erectile dysfunction. We’ll use this field in a bit. Click the edit button again to save the changes.

The unicorn icon is from The Noun Project, where I paid a couple of bucks for a royalty-free version. When you get an SVG icon for use in QGIS from somewhere other than QGIS’s built-in set of icons, you’ll notice that you can’t change their color. But for this map we definitely want to have unicorns of different colors. So we have to modify the SVG file. If you want to skip this step, simply choose an icon from the set that comes with QGIS. Otherwise, download an icon that you want and then open up the SVG file in a text editor and add the following bit of code at the beginning of the path tag (note that if there are multiple paths in the file you need this code in every path tag).

fill=”param(fill) #FFF” stroke=”param(outline) #000″

The file will look something like this:

Parameter Snippet

This is just a snippet, of course, the file is much longer.

Now that the SVG file has parameters for the fill and stroke in it, save it. To add it to the project, first what we’ll do is simply add it in the same style for all the states by using a centroid fill, SVG marker in the styling settings. Make sure the drop-down in Layer Styling is set to Single symbol, click on the Simple fill box (yours will have a different color as it just chooses a color at random):

simple fill

Once you’ve clicked Simple fill you’ll see that there is a drop-down next to Symbol layer type. You can change this drop-down to Centroid fill. Notice the map now has a centroid dot for every state. We want to use our icon instead of these dots so now click where it says Simple marker and change the new drop-down that says Symbol layer type to SVG marker. The dot turns into a question mark. It’ll look like this:

SVG Marker not set

Load your icon by using the ellipsis button at the bottom of the Layer Styling panel and browsing for it.

Browse for SVG File

Right now the map has a whole lot of symbols.

Unicorns

Select the Centroid fill part of the symbol and un-check the box next to Draw point on every part of multi-part features. That should de-clutter the map.

Turn off Multi-part

 

Zoom in to the western continental U.S. and use the selection tool to select some of the western state icons.

 

The Select Tool

 

Right-click to open the attribute table for this layer again and, again, click the edit pencil button to toggle editing to on. In the drop-down field menu that appears, select the new field called rainbow and put a “1” in the box. Then click Update Selected. This assigns a “1” in the rainbow field for the points that we just selected. Go ahead and check the data to see that it happened.

 

Updating Selected Records

 

Go back to the map, select some more icons, and update the rainbow field to “2.” Continue like this until you have some icons set to 1, 2, 3, 4, and 5. Each of these numbers represents a different color.  Toggle the editing button again to save the edits.

When that’s done, go back to the Layer Styling panel for the layer and change the renderer from Simple fill to Rule-based. It should have one rule already:

 

Double click this rule

 

… if you double-click it you’ll see that the rule has a Centroid fill and SVG marker setting with the custom icon.

 

Rule settings

 

Put “1” for the Label, put “rainbow” = 1 for the Filter, and change the color to red. Then use the back arrow to go back to where the rules are listed (we only have this one at the moment).

 

The First Rule

 

Now we simply copy and paste this rule until there are five rules. On windows just use ctrl-c and ctrl-v or right-click the rule. Change their colors, labels, and filters so that it looks like this:

 

All the Rules

 

Here’s how the project looks now that this is done:

 

Completed Icon Styling

 

Et voilà!

This map was just for fun. Please note that the finished map at the top of the page was further modified in Inkscape, where I created an ellipse and used it as a clipping object, then created a new ellipse of the same size as an outline object set with a drop-shadow filter.

While this was a fairly meaningless map in the sense that it has no real-world thematic meaning, I hope it served the purpose of adding some fun to a beginning learning experience.

If you’d like to learn more advanced map techniques with real-world examples, please keep an eye out for QGIS 3 Map Design, written by Anita Graser and myself, due on bookshelves in November 2018. In the meantime, you can explore more QGIS “recipes” in the 1st edition of the book, QGIS Map Design. (Below is an affiliate link that helps support me. Feel free to look at other bookstores like Barnes and Noble, or, as always, ask your local library if they have it or will get it for you.)

————

 

 

 

No Comments