Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

topojson.object in topojson V1

I am having a lot of fun playing with topojson, but it looks like topojson.object is undefined in V1 of topojson, where it was supported in V0. Can someone explain how I might work around this issue? I am trying to draw distinct path elements for each polygon in an input file formatted as topojson. the code is:

d3.json("maTopo.json", function(error, ma) {
    svg.selectAll(".subunit")
      .data(topojson.object(ma, ma.objects.ma).geometries)
    .enter().append("path")
      .attr("class", function(d) { return "subunit " + d.id; })
      .attr("d", path);
});
like image 402
Mark Roper Avatar asked May 24 '13 16:05

Mark Roper


People also ask

What does TopoJSON feature do?

TopoJSON is an extension of GeoJSON that encodes topology. Rather than representing geometries discretely, geometries in TopoJSON files are stitched together from shared line segments called arcs. This technique is similar to Matt Bloch's MapShaper and the Arc/Info Export format, .


1 Answers

You can use topojson.feature instead.

d3.json("maTopo.json", function(error, ma) {
  svg.selectAll(".subunit")
      .data(topojson.feature(ma, ma.objects.ma).features)
    .enter().append("path")
      .attr("class", function(d) { return "subunit " + d.id; })
      .attr("d", path);
});

A detailed example can be found here: http://bost.ocks.org/mike/map/

like image 170
Pablo Navarro Avatar answered Sep 20 '22 08:09

Pablo Navarro