How to mesh in TopoJSON while maintaining discrete polygons

59 views
Skip to first unread message

Chris Wilson

unread,
Apr 13, 2017, 1:20:07 PM4/13/17
to d3...@googlegroups.com
I recently had to deal with mapping the USDA's "commuting zones," which are clusters of counties around metropolitan areas. Since this isn't a Census designation, there's no convenient SHP file anywhere in TIGER of these zones--at least that I could locate--so I had to group the counties manually like so:


I know `topojson.mesh` is a faster solution for this sort of grouping, but I needed the zones to be individual polygons (as you can see above by mousing over a zone). 

Still, this solution feels a) hacky and b) wanders from the GeoJSON format by creating 709 individual GeoJSON objects instead of one GeometryCollection with 709 geometries.

Is there an elegant way to get to b)? Or any way? I don't like doing this grouping in the client and would much prefer to write a Node script to create a single topoJSON or geoJSON object with all 709 commuting zones as individual polygons. 

Mike Bostock

unread,
Apr 13, 2017, 1:30:06 PM4/13/17
to d3...@googlegroups.com
To do this in Node, use topojson.mergeArcs to create a TopoJSON geometry object for each commuter zone. Combine the array of objects into a GeometryCollection (wrap it in {type: "GeometryCollection", geometries: array}), and then add it to your topology.objects.

You can also use topomerge to do this without writing a custom Node script. (Meaning, writing a Bash script instead.) You can use ndjson-join to join the us-atlas topology with your commuter zone data, and then specify topomerge -k to return the commuter zone id. See my Command-Line Cartography series for examples.

Mike

--
You received this message because you are subscribed to the Google Groups "d3-js" group.
To unsubscribe from this group and stop receiving emails from it, send an email to d3-js+un...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Chris Wilson

unread,
Apr 13, 2017, 4:33:35 PM4/13/17
to d3-js, mi...@ocks.org
Thank you!
Reply all
Reply to author
Forward
0 new messages