Skip to content

Instantly share code, notes, and snippets.

@Fil
Last active May 21, 2017 09:12
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
Star You must be signed in to star a gist
Save Fil/865611a125f335aa57d30520bc80a0d6 to your computer and use it in GitHub Desktop.
d3 map experiment with NZTM [UNLISTED]
license: mit
<!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 p = d3.geoIdentity().reflectY(true),
path = d3.geoPath().projection(p);//scale(1, width, height))
d3.json("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];
var wards = topojson.feature(nz, nz.objects.wards);
p.fitExtent([[0,0],[960,500]], wards)
svg.append("path")
.datum(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