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.geo.path gives wrong values for bounds #2051

Closed
theevann opened this issue Oct 7, 2014 · 2 comments
Closed

d3.geo.path gives wrong values for bounds #2051

theevann opened this issue Oct 7, 2014 · 2 comments

Comments

@theevann
Copy link

theevann commented Oct 7, 2014

I wonder if this issue may be linked with the bug #2025.

I'm plotting a map using geojson data and d3.geo. It appears that for some of the objects, the function bounds() returns wrong bounds.

Here is an example:

    var proj = d3.geo.mercator()
        .center([-0.14, 51.5])
        .scale(20000);

    var path = d3.geo.path().projection(proj);

    var obj = {
        geometry : {
            coordinates : [[[0.6673, 51.4574], [0.6759, 51.4583], [0.6815, 51.4578], [0.6815, 51.4578], [0.6873, 51.4595], [0.6673, 51.4574]]],
            type : "Polygon"
        },
        type : "Feature",
        id : "236404706",
        clipped : true,
        properties : {
            area: 118107,
            kind: "water",
            source: "openstreetmap.org"
        }
    };

    path.bounds(obj);

The bounds given are: [-62302.98385274002, -62581.853071795864] and [63311.853071795864, 63081.853071808815]
which are not correct.

With, for example, the coordinates : [[[0.6673, 51.4574], [0.6759, 51.4583], [0.6815, 51.4578], [0.6873, 51.4595], [0.6673, 51.4574]]], the bug doesn't appear.

@theevann
Copy link
Author

theevann commented Oct 8, 2014

Update :
Then, I wondered if that may be linked to the polygon being taken in the wrong way (problem probably linked with clockwise / antoclokwise way). So I reversed the coordinates and I got the right answer :

    obj.geometry.coordinates[0].reverse()
    path.bounds(obj);

which gives me the right answer...

@jasondavies
Copy link
Contributor

d3.geo requires polygons to wind clockwise around their interior (right-hand/right-foot winding rule). Your polygon looked like it might be degenerate (self-intersecting) at first glance (I removed the coincident point for clarity):

screen shot 2014-10-09 at 14 29 14

If you zoom in, you realise there is no degeneracy, therefore the problem was simply the incorrect winding order. The numbers from 0 to 3 indicate the order, and you can see that the winding order is counterclockwise relative to the small interior.

screen shot 2014-10-09 at 14 33 10

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

2 participants