Skip to content

Instantly share code, notes, and snippets.

@JuanBarros2
Last active February 17, 2018 13:25
Show Gist options
  • Save JuanBarros2/3fdd1e6f52ff81b08b080c026305cec9 to your computer and use it in GitHub Desktop.
Save JuanBarros2/3fdd1e6f52ff81b08b080c026305cec9 to your computer and use it in GitHub Desktop.
#sudo npm install -g shapefile
#sudo npm install -g d3-geo-projection
#sudo npm install -g ndjson-cli
#sudo npm install -g d3-dsv
#sudo npm install -g topojson
#sudo npm install -g d3
#sudo npm install -g d3-scale-chromatic
echo 'Processando' $1
shp2json $1 |
geoproject 'd3.geoOrthographic().rotate([54,14,-2]).fitSize([1000,600], d)' |
ndjson-split 'd.features' > shapemap.ndjson
echo 'Extraindo informações de' $2
dsv2json --input-encoding latin1 -r ';' -n < $2 > dados.ndjson
echo 'Casando dados com mapa...'
ndjson-map 'd.Cod_setor = d.properties.CD_GEOCODI, d' < shapemap.ndjson > shapechange.ndjson
ndjson-join 'd.Cod_setor' shapechange.ndjson dados.ndjson > merge.ndjson
#Especifico desse mapa
echo 'Criando mapa...'
ndjson-map 'd[0].properties = {renda: Number(d[1].V005.replace(",", "."))}, d[0]' < merge.ndjson > result.ndjson
geo2topo -n tracts=result.ndjson > pb-tracts-topo.json
toposimplify -p 1 -f < pb-tracts-topo.json | topoquantize 1e5 > pb-quantized-topo.json
topo2geo tracts=- < pb-quantized-topo.json | ndjson-map -r d3 'z = d3.scaleSequential(d3.interpolateViridis).domain([0, 1e3]), d.features.forEach(f => f.properties.fill = z(f.properties.renda)), d' | ndjson-split 'd.features' | geo2svg -n --stroke none -w 1000 -h 600 > map.svg
echo 'Removendo lixos...'
rm merge.ndjson
rm result.ndjson
rm pb-tracts-topo.json
rm pb-quantized-topo.json
rm shapechange.ndjson
rm shapemap.ndjson
rm dados.ndjson
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment