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

Error in difference between two polygons #12

Closed
DGuidi opened this issue Oct 20, 2014 · 4 comments
Closed

Error in difference between two polygons #12

DGuidi opened this issue Oct 20, 2014 · 4 comments
Assignees

Comments

@DGuidi
Copy link
Contributor

DGuidi commented Oct 20, 2014

copied from GoogleCode Issue 193
What steps will reproduce the problem?

var precisionModel = new GeometryFactory(new PrecisionModel(100));
var reader = new WKTReader(precisionModel);
var p1 = reader.Read(@"POLYGON ((504927.9 6228865.64, 504969.88 6228833.89, 504980.82 6228861.76, 504927.9 6228865.64))");
var p2 = reader.Read(@"POLYGON ((504927.9 6228865.64, 504951.14 6228848.06, 504957.42 6228863.47, 504927.9 6228865.64))");
var test = p1.Difference(p2);

What is the expected output? What do you see instead?
The two polygons share a vertex (504927.9 6228865.64) at the left tip of the triangle, and when creating the difference this point does not get removed, leaving a strange "tail" on the resulting polygon. Expected to get only the blue(ish) colored polygon as a result
See the image atached.

What version of the product are you using? On what operating system?
It seems to be the same problem with verison 13.1 and 13.2
Its tested on Windows 7 x64 and .NET framework 4.5.1

@FObermaier
Copy link
Member

What is JTS' result? I suspect it is a precision problem.

@DGuidi DGuidi self-assigned this Oct 20, 2014
@DGuidi
Copy link
Contributor Author

DGuidi commented Oct 20, 2014

@FObermaier same suspect. I wanna check jts results first.

@DGuidi
Copy link
Contributor Author

DGuidi commented Oct 21, 2014

checked: jts'trunk returns same results

DGuidi added a commit that referenced this issue Oct 21, 2014
@DGuidi DGuidi closed this as completed Oct 21, 2014
@svalentinh
Copy link

We also checked JTS with the same result. After some investigation it turns out its due to our implementation. We did calculate an intersection and then in a second step tried to remove the intersection from the geometry.
The problem is that one point is exactly on the line between two vertices and then the pricision model when rounding the coordinates moves the line between the two vertices slightly, and then if the intersection point is inside the geometry it creates a tail.

So strictly speeking the algorithm is correct and you just have to be carefull when using calculated geometries and instead of calculating an overlap and then removing that overlap, then just remove it by using the difference between the two original geometries

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

3 participants