Martín González

Visual journalist, designer, map maker.

Madrid and Barcelona TopoJSON

Following es-atlas, it made sense to create some scripts to convert the vector data from Madrid and Barcelona.

These two projects provide all the basic administrative divisions of Madrid and Barcelona in just one TopoJSON, ready to use with D3 and your data. Census tracts, neighborhoods, districts, no problem!


The source shapefiles are already projected, so I ended up using d3.geoProject and d3.geoIdentity to maintain the same projection and apply some transformations in the geometry.

In the end this means that you shouldn’t specify a projection while making the map. The calculations are already done and the rendering is faster.

Getting started

Download the zip or clone the Madrid or the Barcelona repo, go to the folder with your terminal and run npm install. The script will start downloading the files and converting them. In the end you’ll find the output in the madrid or barcelona folder, respectively.

I am also maintaining two URLs with the files:


¿Open data? Not in Barcelona

The Barcelona City Council has a platform that hosts all the geographic data of the city, CartoBCN. This shouldn’t be a problem if they provided public URLs, of at least the basic administrative divisions. Instead, they only let you download the datasets after registering in a marketplace-like interface.

This is hostile and disallows automatic retrieval of the data. In places like Madrid, Spain, or the US, the administration serves this information in the open.

To circumvent this, I had to create a public mirror of the data.

I already contacted them, but I haven’t gotten any response yet.


Thanks to Luis Sevillano for helping with the Madrid script.