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

Problems when one segment of the LineString fully intersects the polygon #2

Open
mileswwatkins opened this issue Jun 20, 2016 · 1 comment

Comments

@mileswwatkins
Copy link

When one consecutive pair of nodes in a LineString passes all the way through a Polygon, it is still only clipped once, instead of twice.

var line = turfLinestring([[-1,-1], [5,5]]);
var poly = turfPolygon([[[0,0], [0,2], [1,2], [1,0], [0,0]]]);
var result = turfLineSliceAtIntersection(line, poly);
console.log(JSON.stringify(result));
// '{"type":"FeatureCollection","features":[{"type":"Feature","geometry":{"type":"LineString","coordinates":[[-1,-1],[1,1]]},"properties":{}},{"type":"Feature","geometry":{"type":"LineString","coordinates":[[1,1],[5,5]]},"properties":{}}]}'

A similar error occurs in cases with concave polygons, where a single line segment passes through the polygon multiple times. Interestingly, in this case the correct number of segments are output, but many of them overlap.

var line = turfLinestring([[0,-0.5], [3.5,3]]);
var poly = turfPolygon([[[0,0], [0,2], [1,2], [2,2], [2,1], [1,1], [1,0], [0,0]]]);
var result = turfLineSliceAtIntersection(line, poly);
console.log(JSON.stringify(result));
// {"type":"FeatureCollection","features":[{"type":"Feature","geometry":{"type":"LineString","coordinates":[[0,-0.5],[2,1.5]]},"properties":{}},{"type":"Feature","geometry":{"type":"LineString","coordinates":[[2,1.5],[1.5,1]]},"properties":{}},{"type":"Feature","geometry":{"type":"LineString","coordinates":[[1.5,1],[1,0.5]]},"properties":{}},{"type":"Feature","geometry":{"type":"LineString","coordinates":[[1,0.5],[0.5,0]]},"properties":{}},{"type":"Feature","geometry":{"type":"LineString","coordinates":[[0.5,0],[3.5,3]]},"properties":{}}]}
@mezgaAladar
Copy link

Hello,

I had the same error like your second problem. In my observation it is works in given cases, depends on the direction of lines and the "clockwiseness" of the polygon. I rewrote the testLineAndRing function within the turf module, and it is works for the wrong lines, but now it is not works with the lines which were good before. You can find my solution in the 3. issue thread.

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

2 participants