Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Building a uniform topojson with two quantized/transformed topojsons? #322

Open
Nemsae opened this issue May 31, 2018 · 0 comments
Open

Comments

@Nemsae
Copy link

Nemsae commented May 31, 2018

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.

screen shot 2018-05-31 at 4 37 19 pm

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.

screen shot 2018-05-31 at 5 18 13 pm

Did I fail to remove the quantization of the coordinates for both jsons during the round trip to geoJSON?

Possibly (ir)relevant Question:

  1. The Nielsen DMA map does not include geometries for Alaska and Hawaii. Could this discrepancy between the two jsons lead to this issue?
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant