Skip to content

Instantly share code, notes, and snippets.

@alpha-beta-soup
Last active May 21, 2017 06:41
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save alpha-beta-soup/faa02be104b53949257e70c2debf7a7f to your computer and use it in GitHub Desktop.
Save alpha-beta-soup/faa02be104b53949257e70c2debf7a7f to your computer and use it in GitHub Desktop.
d3 map experiment with NZTM
<!DOCTYPE html>
<meta charset="utf-8">
<style>
.land {
fill: #ddd;
}
.boundary {
fill: none;
stroke: #999;
}
</style>
<svg width="960" height="800"></svg>
<script src="https://d3js.org/d3.v4.min.js"></script>
<script src="https://d3js.org/topojson.v2.min.js"></script>
<script>
var svg = d3.select("svg"),
width = +svg.attr("width"),
height = +svg.attr("height");
// function scale (scaleFactor, width, height) {
// return d3.geoTransform({
// point: function(x, y) {
// this.stream.point( (x - width/2) * scaleFactor + width/2 , (y - height/2) * scaleFactor + height/2);
// }
// });
// }
var path = d3.geoPath().projection(null);//scale(1, width, height))
d3.json("build/wards-simple-topo.json", function(error, nz) {
if (error) throw error;
// console.log(nz)
// nz.transform.scale = [0,0];//undefined;
// nz.transform.translate = [0,0];
svg.append("path")
.datum(topojson.feature(nz, nz.objects.wards))
.attr("class", "land")
.attr("d", path);
// svg.append("path")
// .datum(topojson.mesh(nz, nz.objects.wards, function(a, b) { return a !== b; }))
// .attr("class", "boundary")
// .attr("d", path);
});
</script>
build/ESRI_Census_Based_2013_NZTM.zip:
mkdir -p $(dir $@)
curl -o $@ http://www3.stats.govt.nz/digitalboundaries/census/$(notdir $@)
build/ESRI_Census_Based_2013_NZTM.shp: build/ESRI_Census_Based_2013_NZTM.zip
unzip -od $(dir $@) $<
touch $@
build/wards.geojson: build/ESRI\ shapefile\ Output/2013\ Digital\ Boundaries\ Generalised\ Clipped/WARD2013_GV_Clipped.shp
ogr2ogr -f GeoJSON build/wards.geojson build/ESRI\ shapefile\ Output/2013\ Digital\ Boundaries\ Generalised\ Clipped/WARD2013_GV_Clipped.shp -s_srs EPSG:2193 -t_srs EPSG:2193
build/wards.json: build/wards.geojson
node_modules/topojson/node_modules/topojson-server/bin/geo2topo \
-o $@ \
wards=$<
build/wards-simple-topo.json: build/wards.json
node_modules/topojson/node_modules/topojson-client/bin/topoquantize 1e4 \
< $< \
> build/wards-simple-topo.json
{
"name": "d3-bubble-map",
"version": "1.0.0",
"description": "",
"main": "index.js",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1"
},
"author": "",
"license": "ISC",
"devDependencies": {
"gistup": "^0.1.3",
"http-server": "^0.10.0"
},
"dependencies": {
"topojson": "^3.0.0"
}
}
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.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment