QGIS Mapping 101: Making your first categorial map with shapefiles
By: Kayla Duarte Brady
Tags: Qgis, Geology, Mapping

QGIS Mapping 101: Making your first categorial map with shapefiles

When investigating a new set of GIS or environmental data, and before diving into any machine learning, it is often useful to map out your features and get a sense of any potential underlying relationships. QGIS has quickly become my mapping software of choice due to its similarity to ArcMap and, best of all, it’s free! Through my endeavor learning this new tool, I thought it might be helpful to some of you out there who are just getting started with it as well. If you’ve used QGIS before, honestly, this blog probably isn’t for you as it is more focused on very basic, entry-level skills. But, if this is your first map I think you’ll find this extremely useful!

If you haven’t downloaded QGIS go ahead and do that now, here. During my college years I used ArcMap pretty extensively for undergraduate research. Now that I’m on my own and don’t have that luxury, I was looking for something cheap, or better yet free, to get my mapping skills up to snuff. That’s when I stumbled upon QGIS. It is surprisingly similar to ArcMap and I was pleased to see all the features it offers. The user interface is also very nicely laid out, and I couldn’t be happier with this open source software. With that, there is a slight learning curve, as there is with everything, but once you get the gist, things are a lot easier. Today, I’m hopefully going to help mitigate some of that learning curve for you by making a simple geologic map of North Carolina using data from an assortment of resources. With that, let’s begin!

To start following along, I suggest you download the needed data from my GitHub, here. You’ll find a zip file containing the shapefiles, a CSV file of some coordinates of cities in North Carolina, and also a QGIS file of the end result map. The data is from the the North Carolina DoT and the USDA Geospatial Data Gateway, both very useful data resources with an assortment of GIS data!

Let’s get to the good stuff. First, open QGIS and create a new project. You should be met with a plain white screen. Let’s add our first bit of data, the map shapefile. QGIS is awesome because it handles and assortment of datatypes, one of the most useful being shapefiles. On the top toolbar select Layer → Add Layer → Add Vector Layer. From there you will see a popup. Under Source Type, keep file selected, and let the encoding be automatic. Under Source, click the button with the three dots, navigate to the folder labeled “NC_County_Boundaries”, and select the shapefile from the list of files. Shapefiles are delimited with .shp at the end of their name. Press “Add” and you will be asked to designate the particular transformation. There are multiple associated with this shapefile, but 2/3 are for military purposes only. Seeing as though this is a blog, we will use the one it already has selected, the one intended for civilians. Click apply and now you should see a beautiful county boundary map of North Carolina. Great job!

Our first base map! | (Image by author)

So now that you have your map, and know how to import layers, let’s add in a geologic map to the mix. It’s the same idea: Layer → Add Layer → Add Vector Layer. This time, navigate to the “NC_geology” folder and select your shapefile. Once it’s added it should look like the image below.

NC Geologic Map | (Image by author)

Taking a look, all that orange isn’t really useful, and we can’t see the county boundaries anymore. What’s happened is QGIS has imported the new shapefile, but put it overtop the county boundary map, and it thinks we just want to see the lines separating the different geologic types. But, wouldn’t it be cool if we could color-code the map so that each color represents a different rock type? Or, we could even change the colors to represent when the geology was formed! Let’s go with the first idea, and see what information we can get out of our map.

To the left of your map, you should see a popup frame. Within that frame, there should be a section that says “Layers”. Here, you can toggle the order of the layers, and if they are even showing on the map! Right now, though, we need to get into the layer properties of the geologic map so we can make necessary adjustments. Find the “NC_geology” layer, right click, and select “Properties”. A new window should pop up with the symbology tab open. At the top of the page, there should be a drop-down menu with “Single symbol” selected. Click that and change it to “Categorized”. This will fix our one color issue and allow us to color-code based on whatever attribute we want! Like I said above, I’ll be categorizing on rock type, but you can choose whatever you please. For Value I’m choosing “ROCKTYPE_1", leaving Symbol be, and selecting “Spectral” for the color ramp. You can choose any of the colors for the color ramp, but I thought Spectral would be nice since I’m interested in how different the rock types are, and don’t want the colors to imply there is some sort of continuum or relationship between them (i.e. choosing a blue gradient). Near the bottom of the pop-up we can choose to classify on either all of the rock types listed, or just a few. Again, I’m interested in the entire map, so all I have to do is press classify and QGIS will automatically assign colors to each label for that attribute. Press Apply → OK and now you should have a wonderfully colorful map to explore!

Geologic map of North Carolina | (Image by author)

This map is awesome, but it would be super neat to see where the major cities lie on the map, and if they might correlate to a specific geologic type. Thankfully, this is extremely simple to do by simply importing in a .csv file with the latitudes, longitudes, and city names. I’ve provided it on my GitHub, here.

To import a .csv, go to Layer → Add Layer → Add Delimited Text Layer . Navigate to your file as usual, give it a useful name so you know what it is, and for our purposes today that’s all you have to do! Go ahead and press Add, then you should be met with some extremely small and hard to see dots where the cities are. Let’s change these so they’re easier to spot, and give them labels so we know what cities they are. Right click your cities layer, and go to Properties. I’m going to make the markers white and change their size to 5. Then, on the left hand side of the pop-up select “Labels”. Press the drop-down menu and select “Single Labels”. QGIS should automatically select the “Name” attribute from the .csv as the values. I’m going to first change the style to bold, and change the font size to 13. Press Apply but stay in the pop-up window.

If you take a peak at your map, the names aren’t in an ideal place around the markers. They need to be moved up to look cleaner. By changing the distance, you can move your labels up. Within that same window, press the “Placement” tab. I set mine to 2mm and am happy with the placement, but it’s up to you!

Our labeled geologic map | (Image by author)

The text is still a little hard to see with all the colors in the background. Go back to your geologic layer properties, select Symbology, and press the little arrow next to “Layer Rendering”. Here we can change the opacity of the layer. I set mine to ~68% so I can still see the colors well, but also read the text. You might notice the base map we used, the county boundary map, may or may not bother you with all the extra lines. Feel free to toggle this layer on and off by checking and unchecking the white box next to the layer name. I find it useful to keep these layers around in case I want to examine other possible relationships, but some people prefer to make a whole new map for that. To each their own, and it’s something you will figure out over time!

Our labeled geologic map with the county boundary map turned off | (Image by author)

Now that we have a basic map outlined, you can take this time to do some exploring! Some useful tools are the Identify tool (found in the upper toolbar, with a blue circle and an “i” in it), the Pan Map tool (upper toolbar, white hand), and the magnifying functions (upper toolbar, magnifying glasses). The Identify tool is extremely useful for quickly looking up the attributes of a particular area, just make sure you have the layer of interest selected or you’ll be left there clicking on an area with nothing showing up.

Taking a look around the map, and using the trusty Identify tool, there doesn’t seem to be any obvious indication that people chose to settle and create these cities based on their rock types and geology. Darn, who would’ve guessed it!

Let’s say maybe we want to find out how many distinct rock types there are, or how many different sections are mapped. Using the handy Statistics tools we can easily, and quickly find that out! Navigate to the upper toolbar and click the button with the summation symbol on it. Now, check the left hand side of the screen and there should be a new statistics window. Simply select the layer and attribute you want to know more about, and boom, simple statistic analytics appear! You can also get specific attribute statistics by pressing the summation symbol next to the attribute selection and creating a simple query.

This was a simple example of how to load and manipulate a map, but the possibilities are endless! There are so many tools you can use, so go wild and play around with it. Doing this sort of initial analysis can be extremely beneficial, and save you a lot of time if you’re planning on creating a machine learning model centered around the data. Let me know in the comments if you come across anything interesting and stick around for more QGIS blogs soon!