I’ve wanted to write a QGIS tutorial for a while now, and recently I learned something new, so I thought it would be a good opportunity to get started. I hope to write more than one of these but I wont make any promises right now.
A while ago I put out a request for maps, asking people to let me know if they wanted a map made of some area that means something to them. I got a few responses (which I am still getting to…), and the idea was mainly to get more experience creating maps that look good. This idea of aesthetically pleasing maps doesn’t have to go against the idea of a technically strong map that tells you some great insight, but often times it does. Last night at the Location Analytics meetup event in Vancouver, this idea was briefly touched on.
One of the requests was for a map of Italy, when I finally got started on it I had the idea to colour in each of the 20 regions of Italy with the unique flag of that region. Step one was to get the shape of Italy and each of the 20 regions into my computer. To get this data, I went to the Diva-GIS website and downloaded the administrative areas file for Italy. Diva-GIS is a great site for getting free SHP files of the whole world, offering free downloads of administrative boundaries, roads, railroads, altitude, land cover and even population density for most if not all the countries in the world.
Anyway, I got the regions loaded into QGIS and my map was looking like this:
In the image above I had set the polygon fill type to no brush as opposed to the default fill type of simple fill. Simply put, a simple fill will simply fill each polygon with whatever colour you want (it is random by default). These fill options for a polygon are found in the properties menu (style tab) for your layer, accessed by double clicking on the layer, or by right clicking on it and selecting properties.
My goal was to fill each polygon (region of Italy) with the flag of that region. So the next step was a trip to Wikipedia where I found this very helpful page with all the flags. I made a new folder on my computer for the flag images and when I started downloading them, I immediately noticed that the file extension was called SVG. It stands for Scalable Vector Graphics, and the key word there is scalable. If you’re unsure of what the word Vector means, you might not intuitively understand what the advantage of SVG images are. Raster and Vector are both very important concepts to understand when dealing with spatial data, so what are they?
A raster is a collection of pixels that are fixed in location. It’s a static image, meaning the pixels don’t change no matter how much you zoom into it – they get bigger, but the relationship between pixels stays the same. The quickest way to get a general understanding of a raster is by zooming in on any jpeg image. When you zoom in to an image so much that you start to see the pixels, you’re looking at a raster and one thing you notice is that the quality goes downhill fast.
On the other side of the coin is a vector image. A vector image is a dynamic image, the pixels that make up a vector aren’t the same ones that are there when you zoom in. The pixels change and the image retains it’s sharpness as you change the scale of the image. If a raster is a fixed set of pixels, a vector is a fixed set of shapes. Wikipedia has a great example of this:
You can see the obvious difference in the image above when the ‘S’ is zoomed into. There are a ton of different things you could get into talking about raster and vector, but for this example we will stop here.
Back to my SVG-flags folder:
Immediately this was a little confusing, I thought I downloaded a picture, yet the type is listed as document, and by default it opens with internet explorer (I don’t even use IE). Fortunately, I’ve seen the phrase SVG in QGIS before, so it wasn’t totally foreign to me and I was sure that with a little research I would be able to utilize the images I had downloaded.
Because I have 20 unique categories (each region of Italy), I also knew I would need a categorized style rather than single symbol style, since a single symbol style (which is the default option when you add new layers) apples only one style to all the shapes in your layer. So I select categorized rather than single symbol:
Now I have to decide which column from the attribute list holds the different categories that I’m interested in displaying. In this case I know that the region names are stored in the column called NAME_1. The next step is two-part:
1 – Find NAME_1 from the drop-down list
2- Press Classify to show the contents of the NAME_1 column
Now my screen looks like this:
If you were to click Apply and then OK at this point, all those colours would fill in the corresponding polygons, it would look something like this:
Doesn’t look so bad, but what I really want is to change those colours to the individual flags of each region. In order to do that with our special SVG files, we need to very specifically tell QGIS which folder our files are in.
You can do this more than one way, but the way I like is to click on the settings menu and select Options… :
From there you have to add the folder (path) containing your SVG files. You can add more than one of these if you have multiple folders containing SVG’s, but for our purpose we only have one folder. Locate that folder on your computer by using the add button and then press OK.
Now QGIS knows where to look to find SVG’s, so we can go back into the properties menu for our layer, and start changing those boring simple fill‘s into exciting Scalable Vector Graphics.
Click on each of the little squares from the categorized list in the properties menu, this will open up the options of how to fill in that specific polygon.
From these menu options you’ll need to change the symbol layer type from simple fill to SVG fill:
From there you just pick the right image for the region you’ve selected:
After a few minutes of work… Voilà!
And now we have our map showcasing the flags of the regions of Italy, next is to make it look even better, I’ll probably do a Google search for “Italian-style fonts” or something to use for my title, get a fancy north arrow, and who knows what else.
Thanks for reading, let me know if you have questions/corrections.