Question

I am rendering two maps in my web page and I'm using d3 to do it. One is a world map with all the countries' borders represented. The file I'm using is a version of this: https://raw.github.com/mbostock/topojson/master/examples/world-110m.json

The second map is of US states. All I need are state borders (not counties). I am using a modified version of this file: http://bl.ocks.org/mbostock/raw/4090846/us.json

I've modified both files to include the name and two letter state or country code) which I use for tooltips.

The world-110m.json file is about 100kb. the states.json file is well over 650kb. Can anyone explain why this is? And, more importantly, what can I remove from the states.json file to substantially reduce its size while still being valid?

Both files have arcs defined for each node as well as an "arc" node near the end of the file. The states' arc node is humongous. I have a feeling the states json file has all county borders which I don't need.

Was it helpful?

Solution

In addition to rysloan suggestions you can use Mapshaper and QGIS to extract the state boundaries. Both of these are also free. To get just the us-states follows these steps:

  • Upload the us.json file to Mapshaper;
  • Export it as a shape file;
  • Unpack the zip and you'll notice the Mapshaper has already split your topojson into 3 shape files one of which is us-states;
  • Upload the us-states.shp and us-states.shx to Mapshaper (you'll have to refresh Mapshaper to get rid of the orginal us.json file first); and
  • Save as topojson and you'll have a file 58kb in size.

OTHER TIPS

if your states json file still contains:

objects:{"counties..." 

then you still have county borders in your file. you will need to do some pre-processing on your file before using it. you might be able to just remove the 'counties' property using javascript (underscore is a good library for object manipulation, see _.omit). other options involve using some gis to dissolve the county polygons. PostGIS and R would be two ways to do this for free(see ST_UNION in postgis or unionSpatialPolygons in R's maptools library).

as far as making the world borders map smaller, I am not too sure. looks like its pretty bare bones as is.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top