block by bricedev 32830794d6b1488eb256

Urban Population

Full Screen

USA Urban population. Data from census.gov.

index.html

<!DOCTYPE html>
<meta charset="utf-8">

<body>
<script src="https://cdnjs.cloudflare.com/ajax/libs/d3/3.5.5/d3.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/topojson/1.6.19/topojson.min.js"></script>
<script>

var width = 960,
    height = 600;

var projection = d3.geo.albersUsa()
    .scale(1100)
    .translate([width / 2, height / 2]);

var path = d3.geo.path()
    .projection(projection);

var svg = d3.select("body").append("svg")
    .attr("width", width)
    .attr("height", height);

d3.json("us.json", function(error, us) {
  if (error) throw error;

  svg.append("g")
    .selectAll("path")
      .data(topojson.feature(us, us.objects.usa).features)
    .enter().append("path")
      .attr("d", path)
      .style("stroke","#000");

  svg.append("g")
    .selectAll("path")
      .data(topojson.feature(us, us.objects.urban).features)
    .enter().append("path")
      .attr("d", path)
      .style("fill","#fff");
});

d3.select(self.frameElement).style("height", height + "px");

</script>

makefile.md

ogr2ogr \
  -f GeoJSON \
  usa.json \
  cb_2014_us_nation_5m.shp

ogr2ogr \
  -f GeoJSON \
  urban.json \
  cb_2014_us_ua10_500k.shp

topojson \
  -o us.json \
  -- \
  usa.json \
  urban.json