Source: Census data and shapefile Ine, municipios polygons datos.gob.
I used a bash
script I to filter from government's files and get the shapefiles I would use:
Isolate Comunidad Valenciana census polygons
ogr2ogr \
-where "CCA = '10'" \
cv/shapes/CV.shp \
cartografia_censo2011_nacional/SECC_CPV_E_20111101_01_R_INE.shp
Shame for municipios
ogr2ogr \
-where "CODNUT2 = 'ES52'" \
cv/shapes/munis.shp \
recintos_municipales_inspire_peninbal_etrs89/recintos_municipales_inspire_peninbal_etrs89.shp
reproject each shapefile and export to GeoJSON
ogr2ogr \
-f "GeoJSON" \
-t_srs "EPSG:32630" \
cv/shapes/census.json \
cv/shapes/CV.shp
ogr2ogr \
-f "GeoJSON" \
-t_srs "EPSG:32630" \
cv/shapes/munis.json \
cv/shapes/munis.shp
Then I use QGIS to create an unique ID from several fields for each polygon to could join with the csv.
Join the data, preserve some properties, simplify, and merge both shapefiles in one json
.
"The resulting TopoJSON file has the 2011 estimated population of each census tract as the population property, and the land area in square meters as the area property. We will divide one by the other and converting to square miles".
topojson \
-e data.csv \
--id-property CUSEC,cod \
-p population=+t1_1,area=+Shape_area \
-s 1 \
--width 750 \
--margin 10 \
-o cv.json \
-- cv/shapes/census.json cv/shapes/munis.json
This recipe is in the bash script in this gist repo.
Mostly everything comes from Mike's block.