Converting GeoJSON to PNG

Christopher Lanoue
1 min readFeb 1, 2020

--

Within the United Kingdom there are approximately 650 constituencies, which makes for a highly detailed map. A detailed map means a larger file size and therefore more heavy processing on the client side, so when building the UK Political Atlas we needed a solution that wouldn’t slow down client-side rendering when exploring different constituencies.

Detailed view of the Amber Valley constituency

We decided on an offline approach of rendering each constituency with d3-node (which allows for static rendering with the power of d3) and then converting the rendered SVG into a PNG with sharp. Within one minute, we had 650 static PNG files of ~7kb each; compared to the 6mb GeoJSON file with which we started. Now when a user loaded a constituency detail page the browser only had to retrieve a single small file and the page would load fast even on mobile or older browsers.

SVG to PNG converter
PNG of Amber Valley within the East Midlands region using D3 and Sharp

--

--