2

I'm trying to display the Italian cartographic shapefiles, for example this one, using D3.js

I can load the Zip file on MapShaper, look at the map, simplify it and export to TopoJSON. I can load back the TopoJSON in MapShaper and it still looks ok.

But when I try to display it using D3.js, I get a bunch of spaghetti:

enter image description here

Beauty, isn't it?

The code is taken straight from the examples. The projection center, rotation, and parallels are supposed to be the canonical ones for Italy, but it doesn't really matter: the map remains spaghetti-like with any choice of projection.

width = 600
height = 1200

projection = d3.geo.albers()
    .center [0, 41]
    .rotate [347, 0]
    .parallels [35, 45]
    .scale 2000
    .translate [width / 2, height / 2]

path = d3.geo.path()
    .projection projection

svg = d3.select "body"
    .append "svg"
    .attr "width", width
    .attr "height", height

d3.json "Reg2011_ED50.json", (json) ->
    svg.append "path"
        .datum topojson.feature json, json.objects.Reg2011_ED50
        .attr "d", path

What am I doing wrong?

Tobia
  • 17,856
  • 6
  • 74
  • 93
  • Getting a bunch of spaghetti when rendering a map of Italy isn't that far of, huh? Made my day ;-) Anyway, could you provide a live demo including the exported TopoJSON to fiddle around with? – altocumulus Oct 19 '15 at 14:41
  • @altocumulus Thank you, but I found the solution, even though I don't understand it. – Tobia Oct 19 '15 at 15:41
  • It's because you didn't specify the projection. This is pretty normal. – kwoxer Oct 28 '15 at 10:33
  • @kwoxer I did create a projection object and set the path object to it. What else should I have done? – Tobia Oct 28 '15 at 10:47

1 Answers1

4

I found an old mailing list post detailing how to import those exact files.

Basically I needed to convert the projection to a standard one with this command:

ogr2ogr -t_srs EPSG:4326 converted.shp original.shp

I don't understand why it's needed: I thought the .prj file took care of projection differences. Apparently not.

Tobia
  • 17,856
  • 6
  • 74
  • 93