Skip to content

Instantly share code, notes, and snippets.

Forked from mbostock/.block
Last active Aug 29, 2015
What would you like to do?
Quantised States

Using topojson.merge to merge states & provinces into a single feature from the Natural Earth 1:10,000,000 Admin 1 dataset.

Turning off pre-quantisation entirely avoids artefacts, and post-quantisation doesn’t affect the merge algorithm.

<!DOCTYPE html>
<meta charset="utf-8">
.graticule {
fill: none;
stroke: #777;
stroke-opacity: .5;
stroke-width: .5px;
pointer-events: none;
.land {
fill: #222;
stroke: orange;
.border {
fill: none;
stroke: blue;
stroke-width: 1px;
<script src=""></script>
<script src=""></script>
var width = 960,
height = 960;
var projection = d3.geo.mercator()
.scale(width / 2 / Math.PI)
.translate([width / 2, height / 2])
var path = d3.geo.path()
var graticule = d3.geo.graticule();
var svg ="body").append("svg")
.attr("width", width)
.attr("height", height);
.attr("class", "graticule")
.attr("d", path);
d3.json("world.json", function(error, world) {
svg.insert("path", ".graticule")
.datum(topojson.merge(world, world.objects.states.geometries))
.attr("class", "land")
.attr("d", path);
svg.insert("path", ".graticule")
.datum(topojson.mesh(world, world.objects.states, function(a, b) { return a !== b; }))
.attr("class", "border")
.attr("d", path);
});"height", height + "px");
rm -rf -- $(GENERATED_FILES)
.PHONY: all clean
mkdir -p $(dir $@)
curl -o $@ "$*.zip"
build/ne_%_admin_1_states_provinces.shp: build/
mkdir -p $(dir $@)
unzip -od $(dir $@) $<
for file in $(dir $@)/ne_$*_admin_1_states_provinces_shp.*; do mv $$file $(dir $@)/ne_$*_admin_1_states_provinces"$${file#*_shp}"; done
touch $@
world.json: build/ne_10m_admin_1_states_provinces.shp
node_modules/.bin/topojson \
-o $@ \
--q0 0 \
--q1 1e2 \
--simplify-proportion .1 \
-- states=$<
"name": "anonymous",
"version": "0.0.1",
"private": true,
"dependencies": {
"topojson": "1"
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