Monday is upon us again and so is #MapInfoMonday.
Today, I'll give you some hints on how to create a density map. By this, I mean a map showing where you have more events or occurrences. In my example, I use address points but it can be anything that has a spatial component to it: crimes, traffic incidents, mobility data or you name it.
The trick to better understanding this is to not focus on the individual point or occurrence but to aggregate these up into larger areas. You can use any type of boundary to aggregate your data. You can use administrative boundaries or postal boundaries but I'd suggest using boundaries of the same size. That could be hexagons or square vector grids. In this example, I'm using square vector grids.
Creating the Boundaries
You first need to create the boundaries - the squared vector grids. In MapInfo Pro, you can do this via the
Grid Maker tool. The Grid Maker tool comes with MapInfo Pro and can be found on the
Registered tab in the
Tools window.
To load the tool double-click on the tool on the
Registered tab. This will run the tool and you can now find it on the
Running tab.
Make sure you have a map covering the area for which you want to create the square vector grids. Now go to the
Running tab in the
Tools window and double-click the
Grid Maker tool. This will start the Grid Maker process to create vector grids.
The
Grid Maker dialog will not appear.
You now set up the tool to create vector grids for a specific area in this way.
Select
Closed Regions under
Object Types at the top of the dialog. You can also choose your preferred style for the polygons.
Leave the coordinates but make sure to check the
Select Area from Map option. This will allow you to draw a rectangle on your map for which you want to create vector grids.
Set the size of the vector grids and also set the distance units for these using
Spacing between lines. I have set mine to 500 meters.
Use
Browse... to select where to create the new table and finally use the
Projection button to set the coordinate system for the grid. I have chosen a local Danish coordinate system instead of Longitude/Latitude WGS84 which typically is the standard.
Once done, hit the
OK button to draw the area you want to have covered with the grids.
The Grid Maker tool automatically activates the tool you need to use to mark the area. Move the cursor to the upper left corner of the area and push and hold down the left mouse button. Now move the cursor to the lower right corner and release the mouse button again.
The
Grid Maker dialog reappears now showing the coordinates of the rectangle you drew. You can manually modify the coordinates of the extent and you can also use the
Round Extents to round the coordinates using the size of the vector grids.
Make sure
Select Area from Map has been unchecked before clicking the
OK button. If you check it, you will have to draw a coverage rectangle again. If you uncheck it, the tool will not create the grid cells. It will show you how many grid cells you are about to create. On my laptop, it took a few seconds to create 7,500 cells, and just around 200 seconds to create around 750,000 cells.
The resulting map with 7,500 grid cells looks like this. Remember to save the changes to the grid table before continuing.
Creating the Density Map
The next step is to create the actual density map where we count the number of occurrences inside each cell and visualize this using a thematic map.
I will update a temporary column with the number of addresses using
Update Column. You can also add a new static column and update this instead, or you can create a spatial join between the two tables and in this way count the number of addresses in each cell.
Select
Update Column from the
SQL dropdown on either the
Table, the
Map, or the
Spatial tab.
Select the grid table as the
Table to Update and select the table holding the occurrences from
Get Value From Table. Now you can also select the option to
Add new temporary column in the list
Column to Update.
In the list
Calculate make sure to select
Count which will return the number of occurrences for each cell. If your data has a column that holds a count, you can also select
Sum from the
Calculate list and then select the column to summarize.
Finally, you also need to check the join condition. Click on the
Join... button to specify this condition. In many cases, MapInfo Pro is able to predict the correct join condition but I always recommend validating this. Make sure it is set to
where object from table <occurrences> is within object from table <density grid>.
When Ready click
OK to update the temporary column. If you have unchecked
Browse Result you will not see any change. If you checked this option you will see a browser window showing the density grid table with the new temporary column added.
We have now assigned the count of occurrences to the individual grid cells and we can create a thematic map highlighting the dense areas. I have WindowHelper running and choose to use the
Quick Ranged Theme option that this tool provides me access to from the context menu of the layer. You can also create a thematic map using
Add Theme from the
Map tab.
In the dialog
Quick Ranged Theme, I select the temporary column holding the count of addresses (occurrences) and from the
Select Color Range list, I select
ColorBrewer Reds (6 colors) and click
OK.
And below you can see the final density map. Notice that I have turned off the bin holding the address counts of 0 - 1 which actually are all the grid cells that don't hold any addresses at all. I have also made that thematic layer 25% transparent via the
Style tab.
I hope this gives you some ideas on how to visualize your data using the density map. In an upcoming #MapInfoMonday article I will also show you have you can do the same using raster. Stay tuned!
------------------------------
Peter Horsbøll Møller
Principal Presales Consultant | Distinguished Engineer
Precisely | Trust in Data
------------------------------