I am trying to build a map of Canada showing FSA boundaries using d3js. I got shape data from Statistics Canada [http://www12.statcan.gc.ca/census-recensement/2011/geo/bound-limit/bound-limit-2011-eng.cfm].

To convert the SHP file to topojson, I am following the process from Mike Bostock's Tutorial 'Lets Build a Map' [http://bost.ocks.org/mike/map/].

First convert the map to GeoJSON using ogr2ogr, then using topojson in Node.js, convert the GeoJSON file to a TopoJSON file.

I am executing the commands:

> ogr2ogr -f "GeoJSON" -s_srs EPSG:21781 -t_srs EPSG:4326 output.geojson input.shp

Followed by the command:

 > topojson --id-property CFSAUID -p name=PRNAME -p name -o output.topojson output.geojson

The resulting map that is generated renders some provinces properly, however, the following provinces show up as jumbled lines.

  • Ontario
  • Newfoundland
  • Quebec
  • Manitoba
  • Saskatchewan
  • Alberta
  • British Columbia

Here is a basic version of my d3 call.

var g = svg.append("g").attr("id", "fsa");
d3.json("can/output.json", function (error, json) {
    var counter = 0;
    var subunits = topojson.object(json, data);
    .attr("d", path)        
  • If -s_crs means source crs, I think the 21781 code is wrong. That's a projected crs for Switzerland. The census data I downloaded has a prj file that lists NAD 1983, EPSG:4269, a geographic CRS. – mkennedy Apr 23 '13 at 16:01
  • As @mbostock says in his answer, the problem is with the projection. By specifying the mercator projection canada renders properly. – Isioma Nnodum Apr 24 '13 at 16:33

The default projection in D3 is the U.S.-centric d3.geo.albersUsa projection. This is a composite projection design to display the 48 contiguous United States, Hawaii, Alaska and Puerto Rico. If you want to make a map of Canada, you’ll have to specify the appropriate projection rather than relying on the default.

  • Thanks so much, it seems to be working now. Apologies for the duplicate post. I did not know it is against the rules, now I do. :) – Isioma Nnodum Apr 24 '13 at 16:30

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.