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

d3.geoStitch should ignore unpaired points on the antimeridian. #104

Open
mbostock opened this issue Apr 8, 2017 · 0 comments
Open

d3.geoStitch should ignore unpaired points on the antimeridian. #104

mbostock opened this issue Apr 8, 2017 · 0 comments
Assignees

Comments

@mbostock
Copy link
Member

mbostock commented Apr 8, 2017

Consider the stitching of a single polygon where a single edge (DE…GH) lies on the antimeridian:

C-----D
|     |
|     E
|    /
|   F
|    \
|     G
|     |
I-----H

During stitching, two fragments are considered:

C-----D
|      
|     E
|    /
|   F
|    \
|     G
|      
I-----H

After stitching, this produces two rings:

C-----D
|     |
|     |
|     |
|     |
|     |
|     |
|     |
I-----H

  E
 /|
F |
 \|
  G

This is because the points that lie on the antimeridian (D, E, G and H) do not have a matching fragment on the other side of the antimeridian to join to. So the fragments DCIH and EFG are each treated as “standalone rings”, resulting in separate polygons.

I employed this workaround to stitch contours:

var shared = {};

// Record the y-intersections with the antimeridian.
p.coordinates.forEach(function(ring) {
  ring.forEach(function(p) {
    if (p[0] === -180 || p[0] === 180) {
      shared[p[1]] |= p[0] === -180 ? 1 : 2;
    }
  });
});

// Offset any unshared antimeridian points to prevent their stitching.
p.coordinates.forEach(function(ring) {
  ring.forEach(function(p) {
    if ((p[0] === -180 || p[0] === 180) && shared[p[1]] !== 3) {
      p[0] = p[0] === -180 ? -179.9995 : 179.9995;
    }
  });
});

But it seems to me that d3.geoStitch could do this by default, and then simple cases like this wouldn’t get broken by d3.geoStitch:

{
  "type": "Polygon",
  "coordinates": [
    [[180, 10], [170, 11], [170, 19], [180, 20], [180, 19], [179, 15], [180, 11], [180, 10]]
  ]
}
@mbostock mbostock self-assigned this Apr 8, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

No branches or pull requests

1 participant