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

Difference problem #718

Open
grizoood opened this issue Oct 9, 2023 · 0 comments
Open

Difference problem #718

grizoood opened this issue Oct 9, 2023 · 0 comments

Comments

@grizoood
Copy link

grizoood commented Oct 9, 2023

Hello, I am having a problem using the Difference function. Here is a code snippet to show the different results:

var precisionModel = new PrecisionModel(PrecisionModels.Floating);
var ntsGeometryServices = new NtsGeometryServices(
                   CoordinateArraySequenceFactory.Instance,
                   precisionModel,
                   NtsGeometryServices.Instance.DefaultSRID,
                   GeometryOverlay.NG,
                   new CoordinateEqualityComparer());
var factory = ntsGeometryServices.CreateGeometryFactory();

var seg1 = new LineSegment(new Coordinate(56.505308802306047, -9.7735522481500272), new Coordinate(61.658255026265437, -2.4143823696501023));
var seg2 = new LineSegment(new Coordinate(56.505308802306047, -9.773552248150029), new Coordinate(57.678138451727747, -8.0985779221024536));

var line1 = seg1.ToGeometry(factory);
// LINESTRING (56.505308802306047 -9.7735522481500272, 61.658255026265437 -2.4143823696501023)
var line2 = seg2.ToGeometry(factory);
// LINESTRING (56.505308802306047 -9.773552248150029, 57.678138451727747 -8.0985779221024536)

var pmReduce = new PrecisionModel(1.0e2);
line1 = GeometryPrecisionReducer.Reduce(line1, pmReduce) as LineString;
// LINESTRING (56.51 -9.77, 61.66 -2.41)
line2 = GeometryPrecisionReducer.Reduce(line2, pmReduce) as LineString;
// LINESTRING (56.51 -9.77, 57.68 -8.1)

var diff = line1.Difference(line2);
// LINESTRING (56.51 -9.77, 61.66 -2.41)

var oNG = new OverlayNG(line1, line2, pmReduce, NetTopologySuite.Operation.Overlay.SpatialFunction.Difference);
var diff2 = oNG.GetResult();
// LINESTRING (57.68 -8.1, 61.66 -2.41)

The geometry diff and diff2 do not match, I expect the result of diff to be equal to the result of diff2. It looks like
Geometry diff = line1.Difference(line2); keeps the precision entered during the first creation.

Should I use new OverlayNG(…) to perform this processing

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

1 participant