Skip to content

Instantly share code, notes, and snippets.

@bricedev
Last active August 29, 2015 14:26
Show Gist options
  • Save bricedev/32830794d6b1488eb256 to your computer and use it in GitHub Desktop.
Save bricedev/32830794d6b1488eb256 to your computer and use it in GitHub Desktop.
Urban Population
<!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>

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

Display the source blob
Display the rendered blob
Raw
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment