One of the biggest pain points while making maps with D3 is obtaining the underlying data. Normally this involves outdated government websites and a long, obscure transformation process from Shapefiles to TopoJSON.
In a nutshell it’s a bash script that downloads and transforms the geometry of the country’s administrative boundaries: municipalities, provinces and autonomous regions. In the end you get a ready to use TopoJSON with the right IDs from the National Statistics Institute.
The boundaries are merged consistently, as I generate the provinces by joining the municipalities and the autonomous regions by joining the provinces. That means that you get the upper administrative divisions for free with the same filesize.
This also plays well with Roger Veciana’s Conic Conformal projection for Spain, which moves the Canary Islands closer to the mainland.
Get the TopoJSONs
After that long download the script will generate two files, one with all the municipalities and one with the provinces.
Remember that this is only a starting point. The script provides decent defaults but you should adapt the code if you have other needs. For example, you can generate less simplified geometries or change the polygon properties (city and region names).
Bonus: I am also maintaining two URLs with the files: