How do I create a Hexbin map?

Normally, polygons are used to plot geographical areas that correspond to an area of importance in your data model. For example, your customers will have a zip code in their address that can be used to group customer locations by zip code. The difficulty is that in the example, zip codes are used to associate your customers to a territory, not associate your customer in proximity to other customers.

Hexbinning can creatively solve this problem by grouping points in to custom sized hexagons.

Hexbinning is a technique that involves data preparation outside of QlikMaps. This guide uses the free tool QGIS, but most other spatial systems can do something similar.

A video of How To of this technique can be found at the following link:

https://vimeo.com/158645971

 

NOTE:

This document explains how to produce a compressed format hexagon during the data preparation stage using an outside tool. This will allow for an optimized load and use of a memory optimized format.

There is also a technique where square bins can be created in the load script of a QlikView or Qlik Sense application. The square bins are produced in an unoptimized WKT format. Creation in the script will simplify the development of Bins at the expense of a memory optimized format. The WKT Bin Script can be found on the download site.

Install MMQGIS

MMQGIS is a plugin for QGIS with many different spacial functions. To download MMQGIS

  • Click on Plugins
  • Select Manage and Install Plugins
  • Search for MMQGIS
  • Select and install MMQGIS

Install Encoded Polyline Exporter

The Encoded Polyline Exporter is a plugin for QGIS that exports layers to a QlikMaps Optimized format. To download the Encoded Polyline Exporter

  • Click on Plugins
  • Select Manage and Install Plugins
  • Search for Encoded Polyline Exporter
  • Select and install Encoded Polyline Exporter

Load Points in to QGIS

Open QGIS and add a points based layer.

  • Select Layer
  • Add Layer
  • Select the file format of the points based layer to be added.

Create Hexagons

For this step we will use the MMQGIS plugin.

  • Select MMQGIS
  • Select Create
  • Select Create Grid Line Layers
  • Browse to a location to place the new .shp file
  • Select Hexagon (Polygon) from the drop down.
  • Select OK

NOTE: Hexagons can be increased or decreased by changing the H Spacing or V Spacing. Selecting one will adjust the other. Smaller numbers create smaller hexagons.

 

Assign ID to Hexagons

When Hexagons are created, only the 6 lat/long points are created. To identify the hexagons with a value, we must create an ID for the Hexagon.

  • Right click on the hexagon layer
  • Select Properties
  • Select Fields
  • Select Field Calculator
  • Type the name of a field in the Output Field Name
  • Type @row_number in the expression box
  • Select OK
  • Select Apply

Associate Data Points with Hexagons

The hexagons created are not associated with the original points imported. To do this we need to do a spatial join.

  • Select Vector
  • Select Data Management Tools
  • Select Join Attributes by Location
  • Select the points layer as your Target Vector Layer
  • Select the hexagon layer as your Join Vector Layer
  • Select OK

 

Save New Layer

This new layer will contain the information from your original points layer with an added a column representing the hexagon. This can be checked by right clicking on the new layer and viewing the attribute table.

Save the layer to a csv file to be used in your QlikView or Qlik Sense application.

  • Right click on the layer
  • Select Save As
  • Select Comma separate Value from the Format dropdown
  • Click Browse to select a location for the CSV
  • Select OK

 

Export the hexagon

The hexagon layer must be exported to a format optimized for QlikMaps.

  • Select the Encoded Polyline Exporter
  • Select the hexagon layer for the Source Layer
  • Select a location for the exported CSV file
  • Click OK