Skip to content

Instantly share code, notes, and snippets.

@eidmanna
Last active December 17, 2015 23:48
Show Gist options
  • Save eidmanna/5691513 to your computer and use it in GitHub Desktop.
Save eidmanna/5691513 to your computer and use it in GitHub Desktop.
Austria D3 TopoJSON

D3 & TopoJSON sample for Austria.

Idea and tutorial: Let's Make a Map by Mike Bostock

Makefile for build of TopoJSON 'aut.json': Why Use Make by Mike Bostock

Display the source blob
Display the rendered blob
Raw
{"type":"Topology","transform":{"scale":[0.0007627945819581924,0.00026313945274527455],"translate":[9.521154825000167,46.37864308700006]},"objects":{"subunits":{"type":"GeometryCollection","geometries":[{"type":"Polygon","arcs":[[0]],"id":"AUT","properties":{"name":"Austria"}}]},"places":{"type":"GeometryCollection","geometries":[{"type":"Point","coordinates":[322,4325],"properties":{"name":"Bregenz"}},{"type":"Point","coordinates":[9193,5528],"properties":{"name":"Eisenstadt"}},{"type":"Point","coordinates":[8821,5462],"properties":{"name":"Wiener Neustadt"}},{"type":"Point","coordinates":[7720,2657],"properties":{"name":"Graz"}},{"type":"Point","coordinates":[6278,919],"properties":{"name":"Klagenfurt"}},{"type":"Point","coordinates":[6250,7375],"properties":{"name":"Linz"}},{"type":"Point","coordinates":[5172,8317],"properties":{"name":"Passau"}},{"type":"Point","coordinates":[4613,5441],"properties":{"name":"Salzburg"}},{"type":"Point","coordinates":[2476,3427],"properties":{"name":"Innsbruck"}},{"type":"Point","coordinates":[8972,6929],"properties":{"name":"Vienna"}}]}},"arcs":[[[7395,9723],[100,52],[6,8],[19,42],[4,20],[3,51],[5,15],[11,0],[6,-15],[6,-19],[6,-9],[61,-1],[30,-16],[63,-61],[58,-38],[28,-31],[65,-107],[30,-22],[78,-58],[102,-110],[29,-13],[30,0],[23,13],[46,47],[12,5],[40,1],[7,-11],[5,-47],[7,-20],[9,-7],[25,-3],[14,-20],[10,-9],[11,2],[-13,-34],[16,7],[15,-1],[10,-17],[1,-40],[22,11],[7,-17],[0,-26],[2,-19],[132,-184],[69,-57],[122,14],[183,-52],[1,2],[28,8],[17,-27],[7,-5],[21,12],[14,26],[67,218],[23,29],[37,-10],[14,1],[24,19],[12,3],[12,-8],[22,-27],[78,-44],[25,-5],[25,-20],[10,-46],[5,-54],[9,-45],[18,-23],[20,-7],[50,4],[20,-14],[48,-60],[24,-17],[25,6],[51,34],[21,-3],[31,-84],[18,-251],[45,-101],[13,-178],[-7,-48],[-3,-19],[-22,-44],[-21,-34],[-10,-36],[-7,-50],[-34,-95],[-14,-52],[-5,-54],[-12,-203],[-3,-24],[-3,-11],[-3,-17],[0,-42],[4,-23],[10,-12],[26,-5],[8,-9],[14,-22],[13,-29],[6,-30],[-3,-17],[-5,-22],[-3,-19],[6,-8],[4,-8],[4,-19],[4,-22],[2,-17],[4,-22],[10,-13],[12,-10],[15,-26],[8,-5],[5,-13],[1,-17],[-2,-43],[1,-19],[20,-136],[6,-69],[1,-82],[9,-59],[33,-71],[18,-21],[21,-6],[14,-18],[19,-69],[7,-22],[17,-35],[-14,-33],[-6,-38],[-8,-71],[5,-6],[16,-25],[-7,-63],[30,-32],[42,-29],[31,-54],[-82,-134],[14,-31],[-1,-24],[-6,-23],[-4,-33],[-3,-6],[-12,-17],[-3,-10],[1,-17],[7,-8],[6,-4],[3,-7],[-5,-68],[-8,-50],[-13,-38],[-21,-33],[-46,-20],[-16,-17],[0,-41],[9,-18],[27,-24],[10,-15],[13,-71],[8,-25],[-19,-42],[2,-66],[8,-77],[3,-124],[6,-38],[11,-29],[15,-18],[-27,-25],[-95,-25],[-104,-51],[-50,18],[-19,100],[-17,-29],[-26,-80],[-14,-28],[-12,-6],[-74,23],[-14,17],[-15,30],[-10,39],[-4,40],[-8,34],[-16,23],[-105,80],[-55,13],[-48,-42],[-8,-37],[2,-50],[-7,-33],[-11,-21],[-52,-54],[-16,-27],[-9,-11],[-6,3],[-6,12],[-8,18],[-9,-19],[-20,-63],[-12,-28],[24,-27],[73,-58],[37,15],[86,-69],[43,15],[29,-26],[23,-60],[11,-77],[-8,-74],[23,-24],[18,-36],[10,-48],[-1,-59],[-14,-48],[-39,-32],[-15,-31],[6,-153],[-18,-28],[-50,-76],[-141,-127],[-15,50],[-18,24],[-16,-8],[-14,-49],[4,-145],[-3,-11],[-7,-7],[-5,-10],[-1,-23],[4,-14],[5,-7],[6,-4],[4,-8],[40,-164],[5,-63],[-9,-51],[-18,-33],[-41,-44],[4,-66],[-20,-84],[5,-62],[8,-14],[10,2],[11,-2],[9,-25],[0,-33],[-11,-65],[0,-21],[18,-23],[44,42],[22,-4],[16,-46],[-7,-44],[-30,-79],[-27,-34],[-9,-55],[10,-50],[26,-18],[16,-15],[4,-20],[-5,-21],[-15,-19],[-58,-47],[-17,-29],[38,-9],[19,-13],[18,-34],[6,-41],[-25,-12],[-34,-1],[-22,-8],[-5,-11],[-7,-3],[-6,4],[-7,10],[-23,34],[-28,7],[-53,-13],[-49,20],[-18,-5],[-13,-42],[-5,-58],[-11,-17],[-13,-6],[-13,-23],[-3,-23],[1,-21],[-1,-23],[-9,-28],[-9,-14],[-27,-23],[-34,-48],[-15,-32],[-47,-129],[-17,-32],[-21,-19],[-54,-64],[-27,-32],[-5,-2],[-54,-27],[-7,-9],[-13,-26],[1,-9],[6,-8],[1,-27],[-9,-118],[0,-12],[-2,-55],[1,-66],[15,-93],[28,-36],[15,-59],[2,-87],[-24,62],[-15,20],[-53,18],[-89,90],[-36,14],[-37,-6],[-50,-40],[-38,-31],[-35,-4],[-101,29],[-21,26],[-4,-57],[0,-49],[-7,-33],[-7,-11],[-7,-10],[-17,-9],[-20,11],[-28,-1],[-28,-15],[-20,-30],[-13,-54],[0,-7],[-4,-36],[-5,-22],[-3,-16],[-25,-38],[-39,-14],[-30,37],[-6,11],[-23,40],[-39,29],[-72,-7],[-168,-18],[-42,9],[-88,19],[-26,6],[-31,7],[-76,-49],[-48,-139],[-26,72],[-18,8],[-19,-24],[-28,-36],[-5,-1],[-23,-6],[-18,5],[-17,-14],[-21,-64],[-15,-64],[-11,-62],[-9,-58],[-14,-63],[-11,-49],[-7,-12],[-29,-27],[-33,-11],[-12,16],[-22,-19],[-8,-18],[-6,-26],[-16,-37],[-9,-47],[-10,3],[-7,3],[-6,-3],[-27,-55],[-13,-18],[-14,-7],[-28,-6],[-13,-10],[-19,-56],[-11,-73],[-6,-33],[-6,-30],[-23,-20],[-17,36],[-15,66],[-18,49],[-45,-22],[-22,7],[-18,17],[-23,21],[-7,17],[-4,22],[-6,18],[-14,6],[-45,-20],[-157,9],[-121,7],[-2,2],[-14,7],[-74,128],[-19,19],[-22,13],[-23,1],[-23,-8],[-21,-8],[-22,5],[-119,114],[-40,13],[-85,-28],[-18,0],[-87,42],[-19,3],[-21,-8],[-20,4],[-158,103],[-56,5],[-10,14],[-19,42],[-9,7],[-80,-12],[-57,20],[-134,-57],[-52,5],[-28,23],[-83,102],[-108,50],[-307,44],[-74,97],[-33,22],[-11,8],[-11,-3],[-21,-17],[-12,0],[-12,10],[-24,36],[-10,10],[-2,2],[-65,13],[-77,-20],[-19,4],[-21,20],[-41,55],[-40,14],[-31,11],[-53,44],[-46,80],[-25,122],[-11,83],[-22,28],[-27,7],[-27,21],[-13,18],[-8,15],[-3,26],[1,49],[3,44],[5,26],[4,27],[-1,47],[-12,83],[-21,29],[-55,3],[-18,14],[-8,18],[-7,24],[-15,30],[-14,15],[-31,11],[-14,11],[19,38],[0,35],[-9,36],[-8,42],[-8,88],[-6,43],[-9,38],[14,66],[80,88],[28,75],[0,52],[0,48],[-31,21],[-62,-24],[-22,-9],[-133,-137],[-93,-9],[-58,-39],[-56,-60],[-45,-71],[-59,-19],[-15,-19],[-26,-41],[-15,-7],[-24,18],[-43,63],[-25,5],[-10,-3],[-10,2],[-1,1],[-1,0],[-67,27],[-31,-6],[-39,-22],[-12,-13],[-13,-5],[-12,4],[-11,14],[-7,18],[-7,14],[-9,10],[-23,11],[-13,-6],[-12,-17],[-10,-30],[-44,-86],[-40,4],[-41,40],[-47,20],[-92,-31],[-91,-58],[-23,-28],[-85,-167],[-11,-47],[-13,-134],[-25,-117],[-1,-15],[1,-39],[-2,-19],[-6,-12],[-14,-13],[-6,-11],[-29,-100],[-18,-38],[-19,-5],[-22,15],[-46,8],[-22,-6],[-44,-29],[-13,-2],[-14,11],[-22,38],[-12,12],[-13,1],[-25,-15],[-13,1],[-38,43],[-15,10],[-27,-17],[-14,1],[-8,33],[6,19],[29,47],[6,26],[-12,39],[-101,119],[-20,11],[-23,-6],[-133,-73],[-55,12],[-42,69],[-3,81],[16,129],[-7,64],[-12,28],[-44,70],[-28,88],[-13,29],[-1,0],[-6,9],[-8,3],[-7,-3],[-38,-43],[-33,-75],[-23,-87],[-1,-71],[-32,-4],[-26,14],[-21,-8],[-20,-67],[-6,-48],[-1,-32],[-4,-29],[-13,-39],[-57,-58],[-34,-19],[-9,1],[-18,1],[-57,36],[-30,34],[-50,96],[-140,90],[-33,50],[-17,46],[-2,36],[4,41],[4,89],[5,37],[0,22],[-5,12],[-8,-2],[-6,10],[3,43],[-248,155],[-22,6],[-69,-16],[-24,12],[36,91],[9,99],[-13,97],[-31,86],[-39,46],[-1,33],[13,57],[2,27],[-12,53],[-12,33],[-6,33],[9,53],[-22,40],[-12,35],[42,141],[45,106],[5,26],[7,67],[6,34],[51,127],[12,57],[1,161],[-37,65],[-49,44],[-39,115],[-2,23],[-7,67],[3,-4],[5,-3],[77,-41],[84,2],[36,34],[19,58],[16,69],[29,65],[18,20],[20,4],[19,-13],[15,-33],[4,-44],[-2,-47],[5,-40],[26,-27],[11,2],[16,20],[7,4],[39,-29],[39,-6],[20,7],[16,25],[4,-62],[13,-36],[17,-32],[12,-51],[0,-12],[0,-11],[2,-23],[14,-17],[12,10],[12,20],[14,14],[65,-186],[11,-44],[-6,-40],[-29,-46],[14,-33],[3,-40],[2,-40],[7,-37],[12,-24],[9,1],[10,14],[17,17],[7,-2],[13,-16],[7,0],[6,8],[15,34],[58,20],[24,-25],[-1,-69],[-24,-140],[3,-25],[1,-23],[-3,-25],[-7,-13],[-17,-10],[-5,-7],[-12,-43],[-5,-24],[5,-6],[20,4],[85,21],[28,22],[59,71],[25,46],[24,62],[29,116],[8,24],[14,17],[27,19],[11,15],[22,57],[19,77],[12,86],[0,81],[-5,47],[-7,34],[-12,24],[-18,20],[13,152],[2,35],[-9,42],[-11,42],[-2,33],[19,15],[22,8],[10,8],[5,-7],[6,-36],[-2,-15],[-6,-18],[-5,-24],[2,-33],[7,-17],[11,-15],[20,-19],[56,-16],[16,5],[16,26],[27,73],[18,25],[32,-1],[173,-128],[5,-12],[4,-20],[7,-18],[11,-7],[39,10],[53,47],[18,10],[18,-2],[14,-16],[30,-44],[-11,-26],[-42,-57],[9,-30],[68,-61],[65,-139],[4,-17],[0,-26],[-3,-26],[-4,-18],[-3,0],[14,-51],[18,-22],[137,-3],[25,15],[86,117],[33,17],[28,-22],[-3,-103],[31,-8],[29,26],[19,40],[17,46],[25,46],[25,15],[57,3],[21,18],[11,38],[-5,28],[-14,18],[-16,9],[62,140],[29,13],[33,-8],[29,-19],[62,20],[28,22],[24,53],[7,35],[10,88],[9,40],[37,62],[4,11],[24,-1],[58,-23],[106,-1],[74,-29],[14,8],[13,65],[15,17],[110,44],[301,-25],[10,4],[38,94],[4,24],[2,36],[-2,101],[-4,21],[-7,9],[-10,21],[-10,25],[-4,21],[-3,31],[21,16],[32,52],[11,14],[19,16],[3,1],[-4,-17],[-3,-41],[-5,-30],[-8,-23],[-5,-26],[8,-42],[13,-23],[14,5],[29,29],[29,9],[75,-32],[23,7],[51,39],[22,-9],[6,-21],[13,-81],[8,-32],[10,-24],[39,-62],[19,-18],[27,-1],[27,11],[21,17],[12,22],[46,80],[25,25],[47,22],[47,0],[73,-37],[23,6],[-14,-67],[21,-49],[34,-44],[26,-50],[-36,-34],[-16,-88],[7,-94],[32,-51],[20,-7],[13,-9],[11,-17],[60,-130],[64,-95],[14,-12],[11,8],[11,11],[14,1],[13,-13],[7,-15],[8,-10],[14,1],[9,16],[38,87],[-1,32],[-3,23],[-4,19],[-3,21],[-1,24],[0,66],[3,10],[12,61],[2,6],[-3,-2],[-1,86],[3,-3],[21,55],[1,10],[16,75],[3,9],[3,46],[1,46],[-4,48],[-10,56],[-26,85],[-16,39],[-16,24],[-21,6],[-33,-29],[-19,-6],[-74,26],[-21,43],[24,74],[1,0],[8,27],[2,25],[1,25],[2,24],[8,30],[84,265],[-6,12],[-28,82],[-45,201],[-22,42],[-10,11],[-27,54],[-31,36],[-11,30],[-7,40],[0,6],[-4,41],[-19,84],[-93,188],[-12,38],[-12,45],[-6,50],[2,52],[8,27],[9,6],[8,-1],[8,7],[19,57],[5,12],[52,71],[18,38],[24,74],[11,25],[20,20],[73,28],[-2,9],[20,32],[43,45],[48,91],[22,29],[136,105],[180,61],[44,47],[128,217],[19,59],[7,81],[3,19],[6,20],[5,26],[3,39],[-2,108],[2,35],[6,35],[18,72],[4,37],[-3,33],[-12,37],[-6,69],[-4,17],[0,13],[7,27],[12,21],[42,31],[44,11],[136,-73],[23,-24],[21,-30],[20,-59],[54,-47],[3,-6],[12,102],[11,43],[4,-2],[27,8],[11,9],[11,21],[6,18],[22,93],[9,50],[4,55],[1,64],[-7,123],[3,45],[18,32],[-17,15],[-6,12],[-14,53],[-7,-5],[3,36],[39,158],[53,-27],[25,-26],[24,-36],[28,-45],[88,-94],[12,-24],[22,-64],[8,-31],[7,-12],[9,-7],[8,-11],[3,-23],[-2,-24],[-6,-3],[-7,2],[-4,-5],[-8,-36],[-8,-5],[-2,-11],[6,-52],[6,-21],[22,-54],[11,-19],[45,-36],[185,-40],[131,-88],[12,3],[10,7],[27,41],[68,57],[21,41],[29,150],[19,25],[32,-71],[52,-53],[15,-7],[20,8],[39,37],[21,3],[8,-14],[2,-25],[0,-25],[4,-16],[10,-2],[20,13],[9,-3],[14,-36],[8,-36],[10,-25],[21,-3],[21,40],[6,11],[6,99],[0,116],[4,103],[25,77],[69,116],[7,73],[13,44],[5,46],[8,37],[20,14],[68,-18],[68,-53],[26,4],[15,67],[-2,7],[-6,24],[-6,31],[-3,23],[3,27],[9,48],[28,238],[0,105],[-5,116],[0,108],[18,81],[-1,20],[0,18],[2,13],[4,6],[29,7],[73,-48],[102,-16],[9,-53],[6,-52],[-1,-52],[-8,-54],[26,-1]]]}
<!DOCTYPE html>
<meta charset="utf-8">
<style>
.subunit.AUT { fill: #dcd; }
.place,
.place-label {
fill: #444;
}
text {
font-family: "Helvetica Neue", Helvetica, Arial, sans-serif;
font-size: 10px;
pointer-events: none;
}
.subunit-boundary {
fill: none;
stroke: #777;
stroke-dasharray: 2,2;
stroke-linejoin: round;
}
.subunit-label {
fill: #777;
fill-opacity: .5;
font-size: 20px;
font-weight: 300;
text-anchor: middle;
}
</style>
<body>
<script src="http://d3js.org/d3.v3.min.js"></script>
<script src="http://d3js.org/topojson.v1.min.js"></script>
<script>
var width = 960,
height = 1160;
var projection = d3.geo.albers()
.center([0, 45.5])
.rotate([-13.8, 0])
.parallels([40, 50])
.scale(9000)
.translate([width / 2, height / 2]);
var path = d3.geo.path()
.projection(projection)
.pointRadius(2);
var svg = d3.select("body").append("svg")
.attr("width", width)
.attr("height", height);
d3.json("aut.json", function(error, aut) {
console.log(aut);
svg.selectAll(".subunit")
.data(topojson.feature(aut, aut.objects.subunits).features)
.enter().append("path")
.attr("class", function(d) {
return "subunit " + d.id;
})
.attr("d", path);
svg.append("path")
.datum(topojson.feature(aut, aut.objects.places))
.attr("d", path)
.attr("class", "place");
svg.selectAll(".place-label")
.data(topojson.feature(aut, aut.objects.places).features)
.enter().append("text")
.attr("class", "place-label")
.attr("transform", function(d) { return "translate(" + projection(d.geometry.coordinates) + ")"; })
.attr("dy", ".35em")
.text(function(d) { return d.properties.name; });
svg.selectAll(".place-label")
.attr("x", function(d) { return d.geometry.coordinates[0] > 16.3 ? 6 : -6; })
.style("text-anchor", function(d) { return d.geometry.coordinates[0] > 16.3 ? "start" : "end"; });
svg.selectAll(".subunit-label")
.data(topojson.feature(aut, aut.objects.subunits).features)
.enter().append("text")
.attr("class", function(d) { return "subunit-label " + d.id; })
.attr("transform", function(d) { return "translate(" + path.centroid(d) + ")"; })
.attr("dy", ".35em")
.text(function(d) { return d.properties.name; });
});
</script>
</body>
aut.json: subunits.json places.json
topojson --id-property su_a3 -p name=NAME -p name -o aut.json subunits.json places.json
subunits.json: ne_10m_admin_0_map_subunits.shp
ogr2ogr -f GeoJSON -where "adm0_a3 IN ('AUT')" subunits.json ne_10m_admin_0_map_subunits.shp
places.json: ne_10m_populated_places.shp
ogr2ogr -f GeoJSON -where "iso_a2 = 'AT' AND SCALERANK < 20" places.json ne_10m_populated_places.shp
ne_10m_admin_0_map_subunits.shp: subunits.zip
unzip subunits.zip
touch ne_10m_admin_0_map_subunits.shp
ne_10m_populated_places.shp: places.zip
unzip places.zip
touch ne_10m_populated_places.shp
subunits.zip:
curl -o subunits.zip 'http://www.nacis.org/naturalearth/10m/cultural/ne_10m_admin_0_map_subunits.zip'
places.zip:
curl -o places.zip 'http://www.nacis.org/naturalearth/10m/cultural/ne_10m_populated_places.zip'
clean:
rm `ls | grep -v 'zip' | grep -v 'Makefile' `
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment