We thought this tutorial was showing it’s age, so we updated it. Check out the new version. It’s a lot more in depth, and uses the latest version on QGIS.
In this tutorial I’m going to show you how you can take a list of locations and turn them into a heat map showing colleges per county.
For this example were going to be using two datasets. The first is US colleges (point data) which contains the locations of all US schools, and the second dataset is US counties (polygon data). The objective is to create a heat map that lets us see which counties have the highest number of colleges.Download the Sample Data
The data is in Shapefile format which is the de facto standard for sharing map data. Despite its singular name, it is in fact a collection of files – with a minimum of four key files: (.shp, .shx, .dbf, .prj).
If you have your own location data in a spreadsheet you can follow this tutorial that explains how to convert a spreadsheet into a Shapefile.
You can easily find Shapefiles for different administrative boundaries for free online. For example the administrative boundaries for the U.S can be downloaded from the Census Bureau.
We will be preparing the data using a popular open source GIS (geographic information system) program called QGIS. For this tutorial we’re assuming you have QGIS already installed, if you don’t you can download the installer here. We’re using QGIS 2.0, but it should also work on earlier or later versions.
Let’s get started
Importing the Data Into QGIS
For the purpose of this tutorial you don’t need to be familiar with QGIS, but if you would like to learn more then here is a great place to get started.
First unzip the sample data and save it in a local directory. You will see the two Shapefiles (made up of four files each).
Now we need to open QGIS and complete the following steps:
- From the top menu bar press “Layer → Add Vector Layer”
- Press the browse button and choose the
counties.shpfile and press open.
- Repeat steps 1 & 3 to open the
Now we can see the two datasets displayed on the map as layers. A Shapefile is made up of two main parts, the first is the geometry which you can now see on the map, the second is the attribute data which contains data about each feature.
To see the attribute data for one of the features on the map follow these steps:
- Activate the identify tool
- Click on a feature on the map
Counting the Points (colleges) Inside Each Polygon (Counties)
Obviously counting all of the points manually would be very hard work, luckily QGIS can do the hard work for us. We’re now going to use QGIS to count how many colleges are in each county and add that number as an extra column called “PNTCNT” in the attribute data of each country.
Follow these steps:
- In the main menu press “Vector → Analysis Tools → Points in polygon”.
- Press browse to choose where the new county Shapefile that contains the school count will be stored and call it “Colleges Per County” and press “OK”.
- When prompted “Would you like to add the new layer to the TOC?” press yes.
The new Shapefile will be opened on the map. In the left hand to bar your can now right click on the “USCountiesColleges” and select “Open Attribute Table”, here in the “PNTCNT” column we can see the number of schools in each county.
Data Clean Up
You will notice that the “schools” column shows a floating point number, when in reality it should be whole numbers. To fix this we need to complete the steps below:
- Right click “USCountiesColleges” and choose “Open attribute table”.
- Press the edit button from the top menu bar.
- Now press the “Open field calculator” button from the top menu (Or press CTRL+i).
- Change “Output field name” to schools.
- Make sure “Output field type” is “Integer (whole number)”.
- In the function list choose “Fields & Values” and double click on “PNTCNT”.
- Press OK.
You will now see the schools column correctly formatted in the table. We can now delete the PNTCNT column by pressing the “Delete columns” button in the top menu bar or pressing CTRL+l and selecting PNTCNT.
We should finish up by pressing the save button in the top bar.
Creating Our Heat Map In Mango
Now that you have your Shapefile let’s upload it to Mango and take a look. If you don’t yet have an account your can sign up for free here.
Once you have logged into your account just complete the following steps:
- Press “Create Map”
- Press “Add Layer → Upload Data” Select the four files of the Shapefile we made.
- Once the upload finishes choose “Quantity” in the layer style panel.
- In the Class Breaks row, select Column: “schools”, Number: 5
- Click the Custom Legend button at the bottom of the panel and change the Range column in the table to 0, 1, 5, 10, 20
- Press Save
You will now be able to see your heat map. Please take some time to experiment with different values in the Custom Legend/Class Breaks panel to see what happens to the map.