I'm following Mike Bostock's tutorial, let's make a map, but for a map of Mexico. I want to display state boundaries.

I was able to get the map of Mexico from Natural Earth Data's world maps. My source for the state boundaries is here:


NOTE: this should be the same file as here, but INEGI's server seems to be down for days. I was able to convert it from ogr2ogr into geojson. When you convert from geojson into topojson, this notice comes up:

duopixel$ topojson -s 5 -o estados_simp.json -- estados.json
quantization: maximum error 78.607km (0.707°)
simplification: retained 1130 / 454450 points (0%)

It still seems to generate the file and it looks like it's correct. This is the file it generates. This is my javascript code:

d3.json("estados.json", function(error, mex) {

  var estados = mex.objects.estados.geometries

    .attr("class", "estado")
    .attr("d", path)

However, I get an error when running this code...

Uncaught TypeError: Cannot read property 'length' of undefined 

Now, since I'm not even sure what I'm doing, I have no idea where the failure point is. I'm stuck at this point and any help is appreciated.

| improve this question | | | | |
  • 1
    Careful with the -s argument; it takes an area threshold in steradians. A value of 5 steradians is about 40% of the surface of the sphere, which is why it only retained 0% (1130 / 454450) of the input points. For a map of Mexico, you probably want something closer to 1e-8. Alternatively, use --simplify-proportion and specify a value between 0 and 1. See the command line reference for details. – mbostock Mar 10 '13 at 15:49

It was a mistake on my javascript code, I wasn't unpacking the data with the clientside topojson...

d3.json("estados.json", function(error, mex) {
  var estados = topojson.object(mex, mex.objects.estados);

    .attr("class", "estado")
    .attr("d", path);
| improve this answer | | | | |

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.