Background
I'm building a map that displays a map of the US. On this map I am plotting heat circles that correspond to a Nielsen DMA topography.
The first topojson that I'm using, is this Nielsen DMA topojson (from simzhou's repo here) to visually plot these heat circles across the US map.
Below you can see the map, with the DMA heat circles, and also the DMA border lines built completely from the Nielsen DMA topojson.
Problem:
The issue I'm having is trying to draw state border lines, instead of these DMA border lines. I've brought in the "https://unpkg.com/us-atlas@1/us/10m.json" that @mbostock has provided for us. When drawing the state borders via topojson.feature(us, us.objects.states).features
(i've tried topojson.mesh
too), that's when things go awry. I am 99% sure that this is because the two json files are using different transform
values, and therefore the positions/coordinates are transformed on different scales.
Here are the two jsons: Nielsen DMA here and the US here
You can see how the transform object differs below:
Transform object from US Atlas
"transform": {
"scale": [0.009995801851947097,0.005844667153098606],
"translate":[-56.77775821661018,12.469025989284091]
}
Transform object from DMA topojson
"transform": {
"scale": [0.00577894299429943, 0.002484260626062607],
"translate": [-124.732975, 24.544237]
},
Here's what I've done so far.
Approach:
1. Round trip through GeoJSON
As detailed by Bostock here I've tried making a new topoJSON "via a round trip through GeoJSON."
Quantized → non-quantized, to remove quantization. This is often done temporarily to process data (for example, topojson.presimplify). I suppose you might want this so that you could combine topologies with different quantized transforms, but you could always do this by making a round trip through GeoJSON.
For each of the jsons
1. I converted them from topoJSON to geoJSON.
topo2geo nielsen_dma=us-dma-geo.json < us-dma-topo.json
Now for each json we have a feature collection with absolute coordinates.
2. With the new geoJSON, I then converted them back to topoJSON via CLI.
geo2topo nielsen_dma=us-dma-geo.json > us-dma-topo.json
Both JSONs no longer have the transform
property, but they do have bbox
.
3. Now I have both jsons make a round trip from topojson -> geojson -> topojson.
4. I stripped bbox
properties from both jsons, as they are optional.
5. I then simply added over the geometry collection of one to the other. statesJSON.objects.nielsen_dma = dmaJSON.objects.nielsen_dma
I now have a topojson with the nielsen_dma
and states
geometries. However this still doesn't work, and drawing the state lines brings chaos.
Did I fail to remove the quantization of the coordinates for both jsons during the round trip to geoJSON?
Possibly (ir)relevant Question:
- The Nielsen DMA map does not include geometries for Alaska and Hawaii. Could this discrepancy between the two jsons lead to this issue?