top of page
Search
Writer's pictureTamara

Let's Have Some Fun Mm?

Blog #6 – Let’s Have Some Fun Mm?


I’ll be honest, I hit a little bit of a wall thinking about where to go next on this QGIS journey. A lot has been happening lately and starting a whole new “plotline”/data searching jaunt was a bit daunting. Especially considering… I have some good news and some bad news: the good news is that I just started a new job (in a pandemic?? I know… feeling very blessed), the bad news is that since I’m going to be dedicating most of my energy to a whole new set of projects, I won’t have as much energy to dedicate here. For the next little while, the posts are going to be shorter, and more lighthearted, which is actually kind of a nice thing for both of us I’d say.


My original inspiration for this blog was the Terrible Maps page, where they highlighted more-or-less useless maps, and I found it endlessly entertaining. Here is my favourite:

I want to make some maps that convey little to no useful information… and learn QGIS while I do it. So here we go!


I had it stuck in my head that there are a lot of US states that start with the letter M… Mississippi, Minnesota, Michigan… and I wanted to know what that looked like visually. Where are the M states? And what about the states with little m’s? No one really needs this information… But I want to know.


First, I needed to decide what the categories would be, is it just going to be states that start with M and ones that don’t? What about states that have a capital M that is not right at the beginning? And of course I want a category for states that have a lower case m somewhere in their name.


I decided on three categories: Does the state have a capital M, does the state have a lower-case m, and does the state not have an m. In order to achieve this, I added a new field using the ‘New field’ button in the attribute table (red circle), and then going into the ‘Open field calculator’ button (blue square). This opens a window where you can input some code to return the value you are interested in. This part I was a little iffy about because of my lack of familiarity with the syntax in QGIS, but I took a shot at it using my baseline knowledge of code logic, combined with this helpful site with some basic syntax. You can skip the next couple of paragraphs if you don’t feel like reading about code 😊.



The first iteration of this looked like this:

Walking you through it, it’s a pretty ugly if/else statement with stacked ifs, Excel style. Basically, if the first letter is a capital M, then the returned value is ‘M’, if that’s not true, but there is an m anywhere in the name, then the returned value is ‘m inside’, if neither of those things are true, the returned value is ‘No m’. The issues I had with this iteration were that the left function didn’t account for capital M’s that aren’t at the beginning of the name, and I assumed that the strpos function would return a ‘null’ value if the conditions weren’t met. The left function returns the left-most character in the string (i.e. the first letter in the state’s name), and the strpos function returns the location number value for the character you are looking for (i.e. string position for, in this case, a lower case m). If the character(s) do(es) not exist in the string/name, then a 0 value is returned, which I figured out

after some testing. I made some changes, namely, I used strpos instead of left for the capital M and I set both functions to test if the returned value is greater than 0. I also fixed up the label names for the legend, and let it run! Make sure to select update existing field and choose the field to update and let it fly.


Now that the attribute table is updated to have a new column that specifies the characteristics of the states’ names, we can use this in the symbology.

Whabam, we have a map! Sure enough, there are 8 states that start with ‘M’ and 2 states that have a capital ‘M’ inside (non-contiguous states not pictured), not a majority, but also not insignificant. The runner-up is states that start with ‘N’, mostly because of all the ‘New’s and ‘North’s. The Ms and Ns have it you guys, they make up a substantial portion of the US state names, who knew?

18 views0 comments

Recent Posts

See All

Comentarios


bottom of page