Skip to content

Instantly share code, notes, and snippets.

@RandomEtc
Last active July 11, 2018 04:42
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save RandomEtc/13fa3e31fed7834eee10 to your computer and use it in GitHub Desktop.
Save RandomEtc/13fa3e31fed7834eee10 to your computer and use it in GitHub Desktop.
D3 Australia Conformal Conic
australian-states.json
ne_10m_admin_1_states_provinces_lakes.geojson
ne_10m_admin_1_states_provinces_lakes.geojson.gz
Display the source blob
Display the rendered blob
Raw
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
<!DOCTYPE html>
<html>
<meta charset="utf-8">
<style>
.states {
fill: #222;
}
.states :hover {
fill: orange;
}
</style>
<head>
<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>
</head>
<body>
<script>
var width = 960,
height = 628;
var projection = d3.geo.conicConformal()
.rotate([-132, 0])
.center([0, -27])
.parallels([-18, -36])
.scale(Math.min(height * 1.2, width * 0.8))
.translate([width / 2, height / 2])
.precision(0.1);
var path = d3.geo.path()
.projection(projection);
var svg = d3.select("body").append("svg")
.attr("width", width)
.attr("height", height);
d3.json("australia.json", function(error, australia) {
if (error) throw error;
svg.append("g")
.attr("class", "states")
.selectAll("path")
.data(topojson.feature(australia, australia.objects.states).features)
.enter().append("path")
.attr("d", path)
});
d3.select(self.frameElement).style("height", height + "px");
</script>
</body>
</html>
# brew install wget gdal
# npm install -g topojson
australia.json: australian-states.json
topojson -o australia.json -- states=australian-states.json
australian-states.json: ne_10m_admin_1_states_provinces_lakes.geojson
ogr2ogr -where "admin='Australia'" -f GeoJSON australian-states.json ne_10m_admin_1_states_provinces_lakes.geojson
ne_10m_admin_1_states_provinces_lakes.geojson: ne_10m_admin_1_states_provinces_lakes.geojson.gz
gunzip -k -f ne_10m_admin_1_states_provinces_lakes.geojson.gz
ne_10m_admin_1_states_provinces_lakes.geojson.gz:
wget https://github.com/nvkelso/natural-earth-vector/raw/master/geojson/ne_10m_admin_1_states_provinces_lakes.geojson.gz
touch ne_10m_admin_1_states_provinces_lakes.geojson.gz
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment