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

Unquantize Points during presimplify #22

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

Sigill
Copy link

@Sigill Sigill commented Jan 20, 2023

Simplifying a topology requires the removal of the transform (if any).
This is done it the presimplify() function.

presimplify() only does that on arcs, not points.
If the topology is quantized again later, points will be quantized twice, yielding invalid values.

With this commit, presimplify() also remove the transform of Point & MultiPoint objects.

The code for this fix is heavily inspired by https://github.com/topojson/topojson-client/blob/71e5bd6428fd8b7a40fa980d2ef7862140851f03/src/quantize.js.

For example, here is a topology corresponding to Washington DC, which has been quantized with q=1e4:

{
  "type": "Topology",
  "objects": {
    "subunits": {
      "type": "GeometryCollection",
      "geometries": [
        {
          "type": "Polygon",
          "arcs": [[0]],
          "properties": {
            "name": "District of Columbia"
          }
        }
      ]
    },
    "places": {
      "type": "GeometryCollection",
      "geometries": [
        {
          "type": "Point",
          "coordinates": [5151, 5105],
          "properties": {
            "name": "Washington, D.C."
          }
        }
      ]
    }
  },
  "arcs": [
    [
      [4601, 0],
      [-211, 886],
      [279, 870],
      [174, 437],
      [91, 471],
      [-173, 361],
      [-302, 586],
      [-482, 374],
      [-644, 438],
      [-497, 557],
      [-392, 148],
      [-759, 76],
      [-614, 248],
      [-1071, 1337],
      [1933, 1678],
      [1765, 1532],
      [2918, -2470],
      [3383, -2864],
      [-2801, -2421],
      [-2597, -2244]
    ]
  ],
  "bbox": [
    -77.11978099719528,
    38.80276753027573,
    -76.90931454193253,
    38.99613558029279
  ],
  "transform": {
    "scale": [
      0.00002104875040131482,
      0.00001933873887559323
    ],
    "translate": [
      -77.11978099719528,
      38.80276753027573
    ]
  }
}

The location for the label is quantized:

"coordinates": [5151, 5105]

Running toposimplify -P 0.5 dc.json was causing the coordinates of the label to be quantized twice:

"coordinates": [248381480, 261971438]

Simplifying a topology requires the removal of the transform (if any).
This is done it the presimplify() function.

presimplify() only does that on arcs, not points.
If the topology is quantized again later, points will be quantized
twice, yielding invalid values.

With this commit, presimplify() also remove the transform of Point &
MultiPoint objects.
@Sigill
Copy link
Author

Sigill commented Jan 20, 2023

I believe this might fix #14.

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

Successfully merging this pull request may close these issues.

1 participant