Skip to content

Instantly share code, notes, and snippets.

@mbostock
Last active October 27, 2016 18:07
  • Star 1 You must be signed in to star a gist
  • Fork 2 You must be signed in to fork a gist
Star You must be signed in to star a gist
Save mbostock/6216797 to your computer and use it in GitHub Desktop.
Custom Cartesian Projection
license: gpl-3.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.
<!DOCTYPE html>
<meta charset="utf-8">
<style>
.lot {
fill: lightgray;
stroke: black;
}
</style>
<svg width="960" height="500"></svg>
<script src="https://d3js.org/d3.v4.min.js"></script>
<script>
var svg = d3.select("svg"),
width = +svg.attr("width"),
height = +svg.attr("height");
var x = d3.scaleLinear()
.range([0, width]);
var y = d3.scaleLinear()
.range([0, height]);
var projection = d3.geoTransform({
point: function(px, py) {
this.stream.point(x(px), y(py));
}
});
var path = d3.geoPath()
.projection(projection);
d3.json("geo.json", function(error, geo) {
if (error) throw error;
x.domain(d3.extent(geo.features, function(d) { return d.properties.Easting; }));
y.domain(d3.extent(geo.features, function(d) { return d.properties.Northing; }));
svg.append("path")
.datum(geo)
.attr("class", "lot")
.attr("d", path);
});
</script>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment