How to calculate travel distance between places and each point of the European population grid

You've got some coordinates and the European population grid: how to calculate the travel distances? A step-by-step presentation of a possible strategy based on OpenStreetMap.

Published On: November 27th, 2019

Almost one million Romanian citizens cast their ballot for the second turn of the Romanian presidential elections in November 2019 from abroad, largely thanks to the fact that more than 800 polling stations around the world remained opened from Friday through Sunday over the election week-end. In some parts of Europe, polling stations were available not only in capital cities or major urban centers, but also in relatively remote locations.

Indeed, it took me about 25 minutes on a rainy Sunday to drive my wife to a polling station from the small village in the Italian Alps where I live.

A polling station in Trentino, Italy

Looking at the density of polling stations in Italy on a map, I had the feeling that I was not exceptionally lucky, and that indeed many Romanian voters in Italy had a polling station within relatively easy reach. Or… was I? How far was the average Italian resident from a Romanian polling station on 24 November 2019? I decided to find out.

How far is the average Italian resident from a polling station for Romania’s presidential elections? To answer this question, first we need to know where polling stations are located, second we need to know where Italian residents actually live, and then, well, calculate the distance.

  1. The Romanian Ministry of Foreign Affairs has published a map with all polling stations for the latest elections on its own website. I am not sure they published the coordinates of each location as open data, but, consciously or not, they let all addresses and coordinates in a nicely formatted json if you just look at the source code of that page (e.g. by doing ctrl+U with Firefox).
  2. Eurostat published back in 2011 a population grid of all of the EU. What is the population grid? Basically, it divides the surface of a country in squares of the size of 1km, and tells how many people live in each of these squares. Why do we need the population grid? Because we need to know that there are more residents in a urban center than on top of a mountain if we want to calculate meaningfully how long it would take for the average Italian to drive to a Romanian polling station.

Here is our data on a map, Romanian polling stations on top of Italy’s population grid:

Now that we have the data, the answer to my question is “simple”: let’s measure the distance between each population grid cell and each polling station in Italy to find out which is the closest. Then it will be possible to calculate the mean (or median) distance, weighting for the number of residents living in each square kilometer that composes the grid.

There are 172,216 one-km cells in the Italian population grid, and, making no other assumption, we’ll check which is the closest polling station to each of them.

This a computing-intensive process (it took approximately 6 hours on my laptop), but hey, this is what computer were made for. So a few hours later, here is our long-coveted answer: on average, an Italian resident lives less than 18 km from a Romanian polling station.[note 1] Fifty per cent of Italians live less than 13km from a Romanian polling station.[2]

To summarise again how we reached this number: Eurostat publishes a population grid that tells how many people live in each square km of the continent. After having calculated the distance between the centre of each of these squares and the location of a Romanian polling station in Italy, we calculated a weighted mean value, “weighted” according to the number of people living in each square km, so that places with many residents in cities “weigh” more than places with few residents in the countryside.

Yes, dear reader, you are right. I just calculated the distance “as the crow flies”. Mind you, I believe this information is very telling and impressive, as residents of most countries would likely need to drive hundreds of kilometers to reach a polling station if they are abroad on election day. But as you will surely remember from the beginning of this story, this author lives in the Alps, where mountains can, and indeed do, stand in the way between an Italian resident and their preferred Romanian polling station. Even worse, the wise Alpine resident knows from experience that what looks closest on a map does not necessarily mean easiest to reach.