Wednesday 19 August 2015

Supermarket Voronoi

During the course of the MSc I came across this excellent open source dataset from Geolytix containing the locations of supermarkets within England, Scotland, Wales and Northern Ireland. I've used a previous version of this dataset to create Voronoi diagrams, and it seemed natural to use it to test a QGIS plugin I've been writing as part of the dissertation.

The plugin converts shapefiles to topojson and creates all the necessary boilerplate code required for a d3 map on a html page. Although d3 comes armed with its own Voronoi functions, I want the plugin to take the carefully crafted styling within QGIS and output it to d3, taking advantage of the SVG functionality in modern web browsers.

For those that don't know Voronoi polygons are the area closest to each point in Euclidean (straight line) space for a given set of points.

So, once the data is downloaded and imported into QGIS as a delimited text layer, the data can be processed using the "Voronoi polygons" function in QGIS's Geometry toolset.

The new layer returned by the function has polygons for each supermarket location, the outline of the country and major cities clearly visible with the concentration of polygons in urban areas, and polygons at the coastline extending into infinity at the edge of the map.

Using a data set of United Kingdom regions, those of England, Scotland and Wales were dissolved to form a single outline of the United Kingdom mainland with which to clip the Voronoi layer, resulting in polygons restricted to the coastline.

Categorising the Voronoi diagram according to retailer, and using a combination of color brewer colour schemes (due to the number of retailers in the data set) a reasonable map can be created in a short space of time. Some colour changes to the original voronoi diagram makes for a nice background to the categorised map.

Creating a d3 map of this data using the plugin, whilst specifying a legend and popup information, can be accomplished within minutes. All that remains is to tidy up the tooltip template html so that the attribute names are replaced with more understandable words.

Over twenty thousand voronoi polygons are rendered in the browser (there's two layers including the background). An experiment to add the QGIS point layer from the original data import caused a substantial delay on rendering, zooming and panning around the map on an Android device. Unsurprising given the volume of data.

Must remember to get around to comparing this to d3’s built in d3.geom.voronoi client-side rendering, once the dissertation is out the way.

Pan and zoom around the map, click on a polygon to view the details of the supermarket.